zabbix自定义监控

zabbix自定义监控

  1. 进程监控
  2. 日志文件监控
  3. mysql主从状态监控
  4. 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 519 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

添加监控项

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值