自定义监控

自定义监控添加步骤:

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                                :::*  

仪表板恢复正常
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值