自定义监控添加步骤:
1.创建脚本存放目录,写脚本,给执行权限,改脚本存放目录的属主属组为zabbix
在客户端上进入根目录
[root@lwq-client ~]# cd /
[root@lwq-client /]# cd scripts/
[root@lwq-client scripts]# vim zabbix.sh
#!/bin/bash
process=$(ps -ef | grep -Ev "grep|$0" | grep -c $1)
if [ $process -gt 1 ];then
echo "0"
else
echo "1"
fi
[root@lwq-client scripts]# chown -R zabbix.zabbix zabbix.sh
[root@lwq-client scripts]# ll
总用量 4
-rwxr-xr-x. 1 zabbix zabbix 126 8月 24 16:26 zabbix.sh
process=$(ps -ef | grep -Ev "grep|$0" | grep -c $1)
查看进程号 过滤 取反 进程本身和脚本本身 再过滤进程号
2.更改客户端配置文件agentd.conf
UnsafeUserParameters=1
UserParameter=<key_name>, /bin/bash
[root@lwq-client ~]# vim /usr/local/etc/zabbix_agentd.conf
//搜索UnsafeUserParameters 去掉前面注释符,将后面值改为1
UnsafeUserParameters=1
//添加此行
UserParameter=zabbix[*],/bin/bash /scripts/zabbix.sh $1
3.重启zabbix_agent
[root@lwq-client ~]# zabbix_agentd
4.在服务端手动测试
zabbix_get -s 客户端IP -k key_name
//客户端安装httpd服务并启动
[root@lwq-client ~]# yum -y install httpd
[root@lwq-client ~]# systemctl start httpd.service
[root@lwq-client ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
//手动测试
[root@lwq-server ~]# zabbix_get -s 192.168.176.112 -k zabbix[httpd] 此处ip为客户端ip
0
//如果出现这样的报错情况
[root@lwq-server ~]#zabbix_get -s 192.168.176.112 -k zabbix[httpd]
zabbix_get [2717]: Check access restrictions in Zabbix agent configuration
//解决:
//在服务器和客户端上杀死zabbix进程,在开启服务
[root@lwq-server ~]# pkill zabbix
[root@lwq-server ~]# zabbix_server
[root@lwq-server ~]# zabbix_agentd
[root@lwq-server ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
LISTEN 0 80 :::3306 :::*
[root@lwq-client ~]# zabbix_agentd
[root@lwq-client ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
[root@lwq-server ~]# zabbix_get -s 192.168.176.112 -k zabbix[httpd]
0
5.配置网页界面,添加监控项以及触发器
配置——>主机——>监控项——>创建监控项
配置——>主机——>触发器——>创建触发器
6.验证
监测——>仪表板——>Global view
查看仪表板
//关闭httpd服务
[root@lwq-client ~]# systemctl stop httpd.service
[root@lwq-client ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
提示警告
//开启httpd服务
[root@lwq-client ~]# systemctl start httpd.service
[root@lwq-client ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 ::1:6010 :::*
仪表板恢复正常