以下记录是笔者两年前实际操作的完整记录,包含Zabbix平台的安装及配置,微信通知告警等实际操作,还包含不少在zabbix手册中不会提到但与实际应用密切相关的Linux相关操作,用这个记录文档一两天内做一个完整的Zabbix系统毫无问题,我已验证过。
#本文档目的是安装Zabbix 4.0LTS平台,依次Zabbix安装CentOS 7.4 / Zabbix平台及依赖包
#Dell R510带远程控制卡,可以WWW远程管理。在192.168.3.250上,zabbix@root
#安装好后从Zabbix_Server的log查询,结果如下:
# SNMP monitoring: YES
# IPMI monitoring: YES
# Web monitoring: YES
# VMware monitoring: YES
# SMTP authentication: YES
# Jabber notifications: NO
# Ez Texting notifications: YES
# ODBC: NO
# SSH2 support: NO
# IPv6 support: YES
# TLS support: NO
#Zabbix平台采用编译安装模式,支持SNMP及IPMI;CentOS建议安装最小服务器模式或带GUI的服务器模式
#Zabbix平台包括Zabbix_Server,Zabbix_agent
#首先安装好CentsOS
#最小化安装的系统缺乏一些组件,以下命令将它们安装
yum install lrzsz tree net-tools nmap vim bash-completion lsof dos2unix nc telnet ntp wget rng-tools psmisc screen -y
#配置时间同步
#查看时间同步情况
timedatectl
#安装NTP软件包并启动
yum install ntp -y
systemctl restart ntpd
systemctl enable ntpd
#最小安装包没有安装网络工具包,先安装下
yum -y install net-tools
#关闭防火墙及Selinux安全服务
#后期为了安全可以打开这两项服务,但需要重新配置
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/=enforcing/=disabled/g' /etc/selinux/config
setenforce 0
#查看防火墙状态
firewall-cmd --state
#安装依赖软件包
yum install httpd mariadb mariadb-server php php-mysql php-devel php-xml php-bcmath php-mbstring php-gd wget expect net-snmp gcc mysql-devel libxml2-devel net-snmp-devel libevent-devel curl-devel -y
#下载Zabbix源文件(如先下载了,可以跳过,建议先下载,wget命令下载很慢)
wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.12/zabbix-4.0.12.tar.gz
#启动httpd及sql服务,并增加自启动
systemctl start httpd
systemctl enable httpd
systemctl enable mariadb
systemctl start mariadb
#数据库设置(根据要求答y或/n,应答参考initmysqlpassword.sh)
mysql_secure_installation
#解压缩下载或拷贝进来的zabbix源文件
tar -zxvf zabbix-4.0.12.tar.gz
#增加zabbix系统用户
cd zabbix-4.0.12
groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
#MySQL数据库设置Zabbix用户及中文支持(这里实际使用的是CentOS自带的MySQL的开源分支MariaDB)
cd database/mysql/
mysql -uroot -p123456 -e "create database zabbix character set utf8 collate utf8_bin;"
mysql -uroot -p123456 -e "grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';"
mysql -uroot -p123456 -e "flush privileges;"
mysql -uzabbix -pzabbix -e "use zabbix;source schema.sql;source images.sql;source data.sql;"
cd ../..
#openipmi安装
yum install OpenIPMI
yum install ncurses-devel
yum install OpenIPMI-devel
#Zabbix编译安装
./configure --enable-server --enable-agent --with-mysql --with-openssl --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi
make install
#匹配Zabbix与数据库及httpd
#Zabbix配置文件位于/usr/local/etc;Log文件位于LogFile=/tmp
sed -i s/'# DBPassword='/'DBPassword=zabbix'/g /usr/local/etc/zabbix_server.conf
cp -r frontends/php/ /var/www/html/zabbix
sed -i s/'^max_execution_time.*'/'max_execution_time = 300'/g /etc/php.ini
sed -i s/'^max_input_time.*'/'max_input_time = 300'/g /etc/php.ini
sed -i s/'^post_max_size.*'/'post_max_size = 16M'/g /etc/php.ini
sed -i s/'^;date.timezone.*'/'date.timezone = Asia\/Shanghai'/g /etc/php.ini
#重启数据库及网页服务
systemctl restart httpd
systemctl enable httpd
systemctl restart mariadb
systemctl enable mariadb
#日志中发现Fping未装,补上,先在fping.org上下载源文件,在root目录下
tar zxf fping-4.2.tar.gz
cd fping-4.2
./configure && make && make install
#本例中Zabbix_Server.conf中fping路径指向 /usr/sbin/fping
#实际上fping在l/usr/local/sbin/fping
#fping缺省用户权限是root,zabbix建立了zabbix组的zabbix用户
ln -s /usr/local/sbin/fping /usr/sbin/fping
chown root:root /usr/sbin/fping
chmod u+s /usr/sbin/fping
#安装SNMP工具包
yum -y install net-snmp-utils
#Snmpwalk的一些简单用法
snmpwalk -v 2c -c public 127.0.0.1 system
snmpwalk -v 2c -c public 127.0.0.1 ifdescr
#启动Zabbix服务器及代理
#zabbix_server默认日志文件位于/tmp/zabbix_server.log,有问题可以查看这个日志文件
zabbix_server
#确认Zabbix的server及agent是否启动
netstat -anpt | grep zabbix
#Zabbix_agentd.conf中配置的Hostname需与Web管理端hosts中主机名完全一致
#进入http页面配置Zabbix_Server
#记住设置的Server Name,在Agent配置中的HostName与此要严格一致,含其它机器上的agent
#这里配置的是Zabbix.Dell
#此项配置中 PHP LDAP有报警,未安装
zabbix_agentd
#Zabbix相关进程的管理方法,systemctl关停进程好像不行
#CentOS精简版不含killall工具,killall在psmisc工具包中
yum install psmisc
#显示在运行的zabbix字头的进程
ps -ef|grep zabbix
killall zabbix_server
#软件的删除
#有些软件会有 make uninstall 之类的功能,但大多都没有,所以只有手动删除
#或者在configure的时候加个preifx参数,比如 --preifx=/opt/squid
#这样当你不用的时候直接rm -rf /opt/squid 就可以了。
#查看RPM方式安装的软件包,zabbix为指定名字
rpm -qa | grep zabbix
#企业微信已创建运维部,运维报警信息如下:
#zabbix中创建用户里对应的账户是微信账号而不是微信号
#AgentId=1000002
#Secret=xxxxxxxxxxxxxxxxxxx
#corpid=wxxxxxxxxxxx71d3244
#--user={ALERT.SENDTO}
#
#--msg={ALERT.MESSAGE}
#微信接口脚本文件位置/usr/lib/zabbix/alertscripts
chown zabbix.zabbix /usr/lib/zabbix/alertscripts/weixin
chmod 755 /usr/lib/zabbix/alertscripts/weixin
#wechat脚本不可用,wexin可用(oneSaas的)
./weixin --corpid=ww4a5f9280471d3244 --corpsecret=xxxxxxxxxxxxxxxxx="云平台版测试告警" --toparty=2 --agentid=1000002
./weixin.one --corpid=ww4a5f9280471d3244 --corpsecret=2wPqlt6VjygojMzq7-NQcRAZCb4YgXfHLhkct_fWo8o --msg="这里是XXX告警测试" --user=xxxxxxx --agentid=1000002
./wexin.py --corpid=ww4a5f9280471d3244 --corpsecret=2wPqlt6VjygojMzq7-NQcRAZCb4YgXfHLhkct_fWo8o --msg="吃完饭了吗打麻将去" --user=xxxxxxx --agentid=1000002
#解决zabbix中文显示乱码:
#(1)从Windows系列系统复制宋体 常规(simsun.ttc):
#文件路径 C:\Windows\Fonts
#(2)复制该字体文件到zabbix的web端的fonts目录下:
#默认rpm安装位置为:/var/www/html/zabbix/assets/fonts
#注:字体文件的文件后缀名需要是:.ttf,因此改成:simsun.ttf
#(3)修改php配置文件:
cd /var/www/html/zabbix/include/defines.inc.php
vim include/defines.inc.php
#原内容如下:
#define(‘ZBX_GRAPH_FONT_NAME’, ‘graphfont’);
#define(‘ZBX_FONT_NAME’, ‘graphfont’);
#修改成以下内容:
#define(‘ZBX_GRAPH_FONT_NAME’, ‘simsun’);
#define(‘ZBX_FONT_NAME’, ‘simsun’);
#SNMP Trapper也要单独安装?
#还需要安装NMAP,zabbix脚本用到
本文暂时没有评论,来添加一个吧(●'◡'●)