1.创建脚本存放目录,写脚本,给执行权限
改脚本存放目录的属主属组为zabbix
[root@cwt-client ~]# cd /opt/scripts/
[root@cwt-client scripts]# cat check_process.sh
#!/bin/bash
process=$(ps -ef | grep -Ev "grep|$0" |grep -c $1)
if [ $process -gt 0 ];then
echo '0'
else
echo '1'
fi
[root@cwt-client scripts]# chmod +x check_process.sh
[root@cwt-client scripts]# chown -R zabbix.zabbix /opt/scripts
[root@cwt-client scripts]# bash check_process.sh mysql
0
2.改客户端配置文件agentd.conf
UnsafeUserParameters=1
UserParameter=<key_name>,<shell command>
[root@cwt-client ~]# vim /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1 #在配置文件里搜索UnsafeuserParameters
UserParameter=check_process[*],/bin/bash /opt/scripts/check_process.sh $1 #在文件最后面添加
3.重启zabbix_agent
[root@cwt-client ~]# pkill zabbix
[root@cwt-client ~]# zabbix_agentd
4.在服务端手动测试
zabbix_get -s 客户端IP -k key_name
[root@zabbix ~]# zabbix_get -s 192.168.40.140 -k check_process[mysql]
5.配置网页界面,添加监控项以及触发器
#先创建监控项


#其他配置保持不变

#创建触发器




6.验证
#停止mysql服务
[root@cwt-client ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
[root@cwt-client ~]# service mysqld stop
Shutting down MySQL.. SUCCESS!

本文详细介绍如何使用Zabbix监控自定义脚本的过程,包括创建脚本、修改配置、重启服务、手动测试、界面配置及验证步骤。适用于系统管理员和运维工程师。
4972

被折叠的 条评论
为什么被折叠?



