自行编译安装或者直接yum安装
2、编译安装zabbix5.2yum install epel-release -yyum install net-snmp-devel mysql-devel libevent-devel libxml2-devel libcurl-devel -ytar -zxvf zabbix-5.2.0.tar.gzgroupadd --system zabbixuseradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix./configure --prefix=/data/soft/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2make -j 2make installmysql -uroot -pxxx> create database zabbix character set utf8 collate utf8_bin;> create user 'zabbix'@'localhost' identified by 'zabbix88889999';> grant all privileges on zabbix.* to 'zabbix'@'localhost';cd database/mysqlmysql -uzabbix -pzabbix88889999 zabbix < schema.sql# stop here if you are creating database for Zabbix proxymysql -uzabbix -pzabbix88889999 zabbix < images.sqlmysql -uzabbix -pzabbix88889999 zabbix < data.sqlrm /etc/my.cnf
3、配置zabbix服务端配置zabbix连接mysql
vim /data/soft/zabbix/etc/zabbix_server.confDBPassword=password
配置nginx+php,拷贝php程序
mkdir /data/www/jk.fk94.com -pcp -a /tmp/zabbix-5.2.4/ui/* /data/www/jk.fk94.com/ll /data/www/jk.fk94.com/chown www.www /data/www/jk.fk94.com/ -R
修改php.ini,保证zabbix可以正常运行
vim php.inipost_max_size = 16Mmax_execution_time = 300max_input_time = 300
安装php扩展sockets/LDAP
PHP sockets PHP(世界最好的语言) LDAP cd /tmp/wget https://wiki.fafdy.com/source/php/php-7.2.12.tar.gztar xf php-7.2.12.tar.gz cd php-7.2.12cd ext/sockets//data/soft/php7/bin/phpize ./configure --with-php-config=/data/soft/php7/bin/php-config --enable-socketsmake -j2 && make installcd ../ldap//data/soft/php7/bin/phpize yum install openldap-devel -ycp /usr/lib64/libldap* /usr/lib/ -a./configure --with-php-config=/data/soft/php7/bin/php-config --with-ldapmake -j2 && make install
拷贝启动服务
cp -r /tmp/zabbix-5.2.4/misc/init.d/fedora/core/zabbix_server /etc/init.d/cp -r /tmp/zabbix-5.2.4/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/chkconfig --add zabbix_serverchkconfig --add zabbix_agentdchkconfig zabbix_agentd onchkconfig zabbix_server onsed -i s#BASEDIR=/usr/local#BASEDIR=/data/soft/zabbix#g /etc/init.d/zabbix_serversed -i s#BASEDIR=/usr/local#BASEDIR=/data/soft/zabbix#g /etc/init.d/zabbix_agentdchmod +x /etc/init.d/zabbix_serverchmod +x /etc/init.d/zabbix_agentd
启动zabbix
/etc/init.d/zabbix_server start /etc/init.d/zabbix_agentd start
登陆web端
浏览器输入http://jk.fk94.comAdminzabbix
4、修改zabbbix_server默认端口为15151vi /data/www/jk.fk94.com/conf/zabbix.conf.php10051改为15151vi /data/soft/zabbix/etc/zabbix_server.confListenPort=15151/etc/init.d/zabbix_server restart/etc/init.d/php-fpm restart
5、客户端单独安装tar -zxvf zabbix-5.2.0.tar.gzgroupadd --system zabbixuseradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix./configure --prefix=/usr/local/zabbix-agent --enable-agentmake -j 2make installcp -r /tmp/zabbix-5.2.4/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentdchmod +x /etc/init.d/zabbix_agentdsed -i s#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix-agent#g /etc/init.d/zabbix_agentdchkconfig --add zabbix_agentdchkconfig zabbix_agentd on/etc/init.d/zabbix_agentd start
zabbix_agent的模式是相对的。
对于客户端,默认是被动模式,则服务端是主动模式。
服务端需要主动向客户端请求数据,如果服务器太多的话,服务器端的压力会非常大。
配置客户端为主动模式
修改配置文件
cat > /usr/local/zabbix-agent/etc/zabbix_agentd.conf << EOF#Server=192.168.137.100 注释被动模式StartAgents=0#0表示关闭被动模式ServerActive=jk.fk94.com:15151Hostname=xxx-vm-centos7-zabbix-0001HostMetadataItem=system.unameTimeout=20LogFile=/tmp/zabbix_agentd.logLogFileSize=0DebugLevel=3EOF
自定义必要脚本
1、tcp连接数监听
mkdir -p /usr/local/zabbix-agent/share/zabbix/alertscriptscat > /usr/local/zabbix-agent/share/zabbix/alertscripts/tcp_connection.sh << EOF#!/bin/bashfunction ESTAB { ss -ant|awk '{s[\$1]++}END{for(k in s) print k,s[k]}'|awk '/ESTAB/{print \$2}'} function TIMEWAIT { ss -ant|awk '{s[\$1]++}END{for(k in s) print k,s[k]}'|awk '/TIMEWAIT/{print \$2}'} function LISTEN { ss -ant|awk '{s[\$1]++}END{for(k in s) print k,s[k]}'|awk '/LISTEN/{print \$2}'} \$1EOFchmod +x /usr/local/zabbix-agent/share/zabbix/alertscripts/tcp_connection.shvi /usr/local/zabbix-agent/etc/zabbix_agentd.conf添加 UserParameter=tcp[*],/usr/local/zabbix-agent/share/zabbix/alertscripts/tcp_connection.sh $1
2、监控用户的最大进程数和最大文件打开数
cat > /usr/local/zabbix-agent/share/zabbix/alertscripts/ulimit.sh << EOFfunction files { cat /etc/security/limits.conf|grep -v "#"|grep "nofile"|awk '{print \$NF}'|tail -n1} function processes { cat /etc/security/limits.conf|grep -v "#"|grep "nproc"|awk '{print \$NF}'|tail -n1} \$1EOFchmod +x /usr/local/zabbix-agent/share/zabbix/alertscripts/ulimit.shvi /usr/local/zabbix-agent/etc/zabbix_agentd.conf添加 UserParameter=ulimit[*],/usr/local/zabbix-agent/share/zabbix/alertscripts/ulimit.sh $1重启zabbix_agent
6、web界面上配置主机组和告警模板- linux基础监控模板
看附件,三种模式,随便找到一种导入即可 - 在web界面配置客户端主动模式-自动注册
有些告警线是自动发现的,监控项原型,请参考这篇博客
不用zabbix自带的,会失灵,直接用mailx发邮件
yum -y install mailx dos2unixcat > /etc/mail.rc << EOFset from=jkfeko94@163.com #设置发件人邮箱set smtp=smtp.163.com #设置smtpset smtp-auth-user=jkfeko94@163.com #设置登录的用户名set smtp-auth-password=xxxxxx #注意,这个不是密码,是SMTP授权码set smtp-auth=login # 认证方式,默认是login,也可以改成CRAM-MD5或PLAIN方式EOFcd /data/soft/zabbix/share/zabbix/alertscriptscat > mailx.sh << EOF#!/bin/bash#echo "\$3" | mail -s "\$2" "\$1"FILE=/tmp/mailtmp\${RANDOM}.txttouch \$FILEecho "\$3" >\$FILEdos2unix -k \$FILEmailx -v -s "\$2" "\$1" < \$FILErm -f \$FILEEOF
web端配置
名称mailx类型脚本脚本名称mailx.sh脚本参数{�ܷ�����,�ܷ���ǿALERT.SENDTO}{ALERT.SUBJECT}{ALERT.MESSAGE}
- 创建接收邮件群组,添加用户(用户要配置告警媒介邮箱)
故障[{HOSTNAME1}]:{TRIGGER.NAME}
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
已恢复[{HOSTNAME1}]:{TRIGGER.NAME}
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
[zabbix5.2官方自定义监控项](https://www.zabbix.com/documentation/current/manual/config/items/itemtypes/zabbix_agent "zabbix5.2官方自定义监控项")未分类信息警告 P3一般严重 P2严重 P1灾难 P0
9、解决监控图的乱码
下载地址:[点击下载](https://wiki.fafdy.com/binary/zabbix/v5.2/微软vista雅黑ttf.zip)cd /data/www/jk.feko94.com/assets/fonts/rz -Ecd /data/www/jk.feko94.com/egrep "ZBX_GRAPH_FONT_NAME|ZBX_FONT_NAME" include/defines.inc.php cp include/defines.inc.php include/defines.inc.php.baksed -i 's#DejaVuSans#stzhongs#g' include/defines.inc.php
客户端- zabbix-agent已经打包,下载解压即可使用
groupadd --system zabbixuseradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbixcd /usr/local/wget https://wiki.fafdy.com/binary/zabbix/v5.2/zabbix-agent.tar.gztar xf zabbix-agent.tar.gz cd zabbix-agentmv zabbix_agentd /etc/init.d/chkconfig --add zabbix_agentd/etc/init.d/zabbix_agentd startchkconfig zabbix_agentd on