环境 | ip | hostname | 要安装的应用 |
服务器 | 192.168.59.131 | server | lamp架构 zabbix server zabbix agent |
客户端 | 192.168.59.133 | 139 | zabbix agent |
监控进程
客户端: 打开自定义监控的功能
[root@139 ~]# cd /usr/local/etc [root@139 etc]# ls zabbix_agentd.conf zabbix_agentd.conf.d [root@139 etc]# vim zabbix_agentd.conf UnsafeUserParameters=1
UserParameter=check_process[*],/bin/bash /scripts/check_process.sh $1
#重启服务
[root@139 etc]# pkill zabbix
[root@139 etc]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@139 etc]# zabbix_agentd
[root@139 etc]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
创建目录编写脚本
[root@139 etc]# mkdir /scripts [root@139 etc]# ls / bin/ dev/ home/ lib64/ mnt/ proc/ run/ scripts/ sys/ usr/ boot/ etc/ lib/ media/ opt/ root/ sbin/ srv/ tmp/ var/ [root@139 etc]# cd /scripts/ [root@139 scripts]# vim check_process.sh #!/bin/bash process_status=$(ps -ef|grep -Ev "grep|$0"|grep -c $1) if[$process_status -eq 0 ];then echo ‘1‘ else echo ‘0‘ fi #添加执行权限 [root@139 scripts]# chmod +x check_process.sh
监控端验证
[root@139 etc]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@server ~]# zabbix_get -s 192.168.59.133 -k check_process[‘httpd‘] 0
网页配置监控项
验证
停止http服务后
监控log日志文件
验证脚本
[root@139 script./log.py /var/log/httpd/error_log_log 0 [root@139 scripts]# echo ‘Error‘ >> /var/log/httpd/error_log [root@139 scripts]# echo ‘qwe‘ >> /var/log/httpd/error_log [root@139 scripts]# echo ‘qwe‘ >> /var/log/httpd/error_log [root@139 scripts]# echo ‘qwe‘ >> /var/log/httpd/error_log [root@139 scripts]# echo ‘qwe‘ >> /var/log/httpd/error_log [root@139 scripts]# ./log.py /var/log/httpd/error_log 1
添加配置文件
[root@139 scripts]# vim /usr/local/etc/zabbix_agentd.conf UserParameter=check_log[*],/scripts/log.py $1 $2 $3 #重启服务 [root@139 scripts]# pkill zabbix [root@139 scripts]# zabbix_agentd
#添加权限
[root@139 ~]# setfacl -m u:zabbix:rx /var/log/httpd/
到服务器监控
[root@server ~]# zabbix_get -s 192.168.59.133 -k check_log[‘/var/log/httpd/error_log‘] 1
网页端配置
验证
[root@139 scripts]# echo ‘Error‘ >> /var/log/httpd/error_log
原文:https://www.cnblogs.com/Mariko/p/14801411.html