zabbix自定义监控
- 进程监控
- 日志文件监控
- mysql主从状态监控
- mysql主从延迟监控
环境
server端:192.168.147.44
agent端:192.168.147.10
在agent端安装agent
将server端的zabbix-5.2.6的包传到agent端上
[root@localhost ~]# scp zabbix-5.2.6.tar.gz 192.168.147.10:/root/
The authenticity of host '192.168.147.10 (192.168.147.10)' can't be established.
ECDSA key fingerprint is SHA256:gSsPLJ32lTw4VyltfgKSGM3YOoC/tgzVRHXPrX8hyVY.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.147.10' (ECDSA) to the list of known hosts.
root@192.168.147.10's password:
zabbix-5.2.6.tar.gz 100% 20MB 16.8MB/s 00:01
在agent端解压传过去的文件
[root@localhost ~]# tar xf zabbix-5.2.6.tar.gz
[root@localhost ~]# ls
公共 视频 文档 音乐 anaconda-ks.cfg zabbix-5.2.6
模板 图片 下载 桌面 initial-setup-ks.cfg zabbix-5.2.6.tar.gz
安装需要的安装包
[root@localhost zabbix-5.2.6]# useradd -r -M -s /sbin/nologin zabbix
[root@localhost ~]# dnf -y install gcc gcc-c++ make pcre-devel
编译安装agent
[root@localhost ~]# cd zabbix-5.2.6/
[root@localhost zabbix-5.2.6]# ./configure --enable-agent
........
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
[root@localhost zabbix-5.2.6]# make install
[root@localhost etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d
[root@localhost etc]# vim zabbix_agentd.conf
113 Server=192.168.147.44 //server端的ip
154 ServerActive=192.168.147.44 //server端的ip
165 Hostname=node3 //可是任意指定,最好是随机数
进程监控
在web界面创建一个主机
[root@localhost ~]# dnf -y install httpd //安装httpd
[root@localhost ~]# systemctl start httpd //启动httpd
[root@localhost ~]# ss -antl //有80端口
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 *:80 *:*
LISTEN 0 80 *:2001 *:*
LISTEN 0 80 *:2002 *:*
LISTEN 0 80 *:2003 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
httpd安装完成
[root@localhost ~]# cd /usr/local/etc/
[root@localhost etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d
[root@localhost etc]# vim zabbix_agentd.conf
UnsafeUserParameters=1 //将这行取消注释 并将数值改为1
在agent端
[root@localhost ~]# mkdir /scripts
[root@localhost ~]# cd /scripts
[root@localhost scripts]# ls
[root@localhost 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@localhost etc]# pkill zabbix //重启zabbix
[root@localhost etc]# zabbix_agentd
[root@localhost scripts]# chmod +x check_process.sh //给脚本x的权限
[root@localhost scripts]# ll
总用量 4
-rwxr-xr-x. 1 root root 133 5月 19 19:09 check_process.sh
测试脚本
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# su - zabbix -s /bin/bash
su: 警告:无法更改到 /home/zabbix 目录: 没有那个文件或目录
[zabbix@localhost root]$ /scripts/check_process.sh httpd
0
[zabbix@localhost root]$ ps -ef|grep -v grep|grep -c httpd
5
[root@localhost etc]# vim zabbix_agentd.conf //在文本最后添加下列一行内容
UserParameter=check_process[*],/bin/bash /scripts/check_process.sh $1
[root@localhost etc]# pkill zabbix
[root@localhost etc]# zabbix_agentd
在server端
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# zabbix_get -s 192.168.147.10 -k check_process['httpd']
0
添加监控项