zabbix自定义监控

本文介绍了如何在Zabbix中进行自定义监控,包括安装和配置Zabbix Agent,监控HTTPD进程,以及实现MySQL主从状态的监控。通过编写脚本和配置Zabbix,确保能够及时发现并处理问题。
摘要由CSDN通过智能技术生成

自定义监控的环境

安装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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值