自定义监控的环境
安装agent
[root@localhost ~]# tar xf zabbix-5.2.6.tar.gz
[root@localhost ~]# cd zabbix-5.2.6/
[root@localhost zabbix-5.2.6]# useradd -r -M -s /sbin/nologin zabbix
[root@localhost zabbix-5.2.6]# dnf -y install gcc gcc-c++ make pcre-devel
编译安装
[root@localhost zabbix-5.2.6]# ls
aclocal.m4 ChangeLog config.sub database install-sh man README
AUTHORS compile configure depcomp m4 misc sass
bin conf configure.ac include Makefile.am missing src
build config.guess COPYING INSTALL Makefile.in NEWS ui
[root@localhost zabbix-5.2.6]# ./configure --enable-agent
[root@localhost zabbix-5.2.6]# make install
安装完成之后,修改三条配置文件
[root@localhost etc]# vim zabbix_agentd.conf
Server=192.168.100.33
ServerActive=192.168.100.33
Hostname=node3
启动客户端
[root@localhost ~]# zabbix_agentd
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
关闭防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
添加主机
安装一个httpd,让它有进程
[root@localhost ~]# dnf -y install httpd
启动apache
[root@localhost ~]# apachectl start
查看进程
[root@localhost ~]# ps -ef |grep httpd
root 112678 1 0 06:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 112679 112678 0 06:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 112680 112678 0 06:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 112681 112678 0 06:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 112682 112678 0 06:44 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 116215 3365 0 06:45 pts/1 00:00:00 grep --color=auto httpd
再关闭httpd
[root@localhost ~]# systemctl stop httpd
[root@localhost ~]# ps -ef |grep httpd
root 120102 3365 0 06:47 pts/1 00:00:00 grep --color=auto httpd
监控进程,就是监控它有没有进程,去过滤,如果没有过滤出来,就说明有问题
添加自定义监控需要把zabbix配置文件的自定义取消掉
UnsafeUserParameters=1
创建一个存放脚本的目录
[root@localhost ~]# mkdir /scripts
[root@localhost ~]# cd /scripts/
[root@localhost scripts]# vim check_process.sh
[root@localhost scripts]# cat check_process.sh
#!/bin/bash
process_status=$(ps -ef |grep -v grep |grep -c httpd)
echo $process_status
[root@localhost scripts]# chmod +x check_process.sh
[root@localhost scripts]# ./check_process.sh
0
把httpd 的值取出来
[root@localhost ~]# ps -ef |grep -v grep |grep -c httpd
0
启动服务
[root@localhost ~]# apachectl start
[root@localhost ~]# ps -ef |grep -v grep |grep -c httpd
5
[root@localhost ~]# /scripts/check_process.sh
5
更新最后的脚本
[root@localhost scripts]# cat 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
临时让zabbix用户可以登录
[root@localhost ~]# su - zabbix -s /bin/bash
[zabbix@localhost root]$ /scripts/check_process.sh httpd
0
把httpd服务停掉
[root@localhost ~]# systemctl stop httpd
[zabbix@localhost root]$ /scripts/check_process.sh httpd
1
[root@localhost etc]# vim zabbix_agentd.conf
Server=192.168.100.33
ServerActive=192.168.100