Zabbix服务器:192.168.1.36;
被控端:192.168.1.37
#在被控端:192.168.1.37安装agent
yum install zabbix40-agent -y
#修改zabbix-agent配置文件:
[root@localhost ~]# vim /etc/zabbix_agent.confPidFile=/run/zabbix/zabbix_agentd.pidLogFile=/var/log/zabbix/zabbix_agentd.logLogFileSize=0Server=192.168.1.36Hostname=192.168.1.36UserParameter=nginx.status[*],bash /data/sh/nginx_status.sh $1# 指定监控项及获取值的方式
#创建脚本
vim /data/sh/nginx_status.sh#!/bin/bash#######################function active {curl 192.168.1.37/status 2>/dev/null |awk 'NR==1{print $NF}'}function accepts {curl 192.168.1.37/status 2>/dev/null | awk 'NR==3{print $1}'}function handled {curl 192.168.1.37/status 2>/dev/null | awk 'NR==3{print $2}'}function requests {curl 192.168.1.37/status 2>/dev/null | awk 'NR==3{print $3}'} function reading {curl 192.168.1.37/status 2>/dev/null | awk 'NR==4{print $2}'} function writing {curl 192.168.1.37/status 2>/dev/null | awk 'NR==4{print $4}'}function waiting {curl 192.168.1.37/status 2>/dev/null | awk 'NR==4{print $NF}'}$1
#启动agent服务
systemctl start zabbix-agent
#在web界面添加agent主机
#添加监控项
创建触发器:
在192.168.1.37关闭nginx服务,zabbix就会报问题了
自动邮件报警:
#添加接收报警的邮箱:
#设置发送报警邮件的邮箱:
#添加动作:(发送邮件和自动重启 nginx服务)
测试:在agent192.168.1.37关闭ngnix:
systemctl stop nginx
可以看到监听端口变成0了,问题中也出现信息了。
邮件也收到了。
Zabbix自动发送了邮件,并重启了服务。在被控端查看,nginx服务已经启动:
[root@localhost sh]# netstat -tnlpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 00 0.0.0.0:80 0.0.0.0:*LISTEN16419/nginx: master tcp 00 0.0.0.0:22 0.0.0.0:*LISTEN900/sshd tcp 00 127.0.0.1:25 0.0.0.0:*LISTEN988/mastertcp 00 0.0.0.0:10050 0.0.0.0:*LISTEN10120/zabbix_agentd tcp6 00 :::80 :::*LISTEN16419/nginx: master tcp6 00 :::22 :::*LISTEN900/sshd tcp6 00 ::1:25 :::*LISTEN988/mastertcp6 00 :::10050:::*LISTEN10120/zabbix_agentd