欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

Linux项目之zabbix监控脑裂

程序员文章站 2022-03-26 18:19:52
环境需求主机IP地址所需服务zabbix server端192.168.159.135lamp、zabbix主keepalived端192.168.159.137keepalived备keepalived端192.168.159.144keepalived、zabbix1. 配置配置server端的lamp和zabbix,我这里就不过多阐述了,有疑问可以参考Liunx服务管理之lamp 和Linux监控服务之zabbix配置主备keepaliv...



环境需求

主机 IP地址 所需服务
zabbix server端 192.168.159.135 lamp、zabbix-server、zabbix-agentd
主keepalived端 192.168.159.137 keepalived
备keepalived端 192.168.159.144 keepalived、zabbix-agentd

1. 配置

配置server端的lamp和zabbix,我这里就不过多阐述了,有疑问可以参考Liunx服务管理之lampLinux监控服务之zabbix

配置主备keepalived的步骤,我上篇博客Linux服务之keepalived高可用里就有写到,这里也不做详细讲解了

2. 查看主备服务器上的vip状态

配置监控前,主keepalived端

 //VIP还是在主这里
[root@master ~]#  ss -anlt
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128             *:22                          *:*                  
LISTEN      0      100     127.0.0.1:25                          *:*                  
LISTEN      0      128            :::80                         :::*                  
LISTEN      0      128            :::22                         :::*                  
LISTEN      0      100           ::1:25                         :::*                  
[root@master ~]#  ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:b2:1a:0e brd ff:ff:ff:ff:ff:ff
    inet 192.168.159.137/24 brd 192.168.159.255 scope global dynamic eno16777736
       valid_lft 1647sec preferred_lft 1647sec
    inet 192.168.159.250/32 scope global eno16777736
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feb2:1a0e/64 scope link 
       valid_lft forever preferred_lft forever 

配置监控前,备keepalived端

 //目前,VIP不在备上面
[root@slave ~]#  ss -anlt
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128             *:22                          *:*                  
LISTEN      0      100     127.0.0.1:25                          *:*                  
LISTEN      0      128             *:10050                       *:*                  
LISTEN      0      128            :::22                         :::*                  
LISTEN      0      100           ::1:25                         :::*                  
[root@slave ~]#  ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:23:3e:ef brd ff:ff:ff:ff:ff:ff
    inet 192.168.159.144/24 brd 192.168.159.255 scope global dynamic eth0
       valid_lft 1521sec preferred_lft 1521sec
    inet6 fe80::250:56ff:fe23:3eef/64 scope link 
       valid_lft forever preferred_lft forever 

3. 在备上安装、配置zabbix

//安装一些常用的工具
[root@slave ~]# yum -y install vim wget gcc gcc-c++ net-snmp-devel libevent-devel

//下载zabbix安装包,进行编译、安装
[root@slave ~]# cd /usr/src/
[root@slave src]# ls
debug  kernels  zabbix-4.4.7  zabbix-4.4.7.tar.gz
[root@slave src]# cd zabbix-4.4.7
[root@slave zabbix-4.4.7]# ./configure --enable-agent
[root@slave zabbix-4.4.7]# make install

//修改配置文件
[root@slave ~]# cd /usr/local/etc/
[root@slave etc]# ls
zabbix_agentd.conf  zabbix_agentd.conf.d
[root@slave etc]# vim zabbix_agentd.conf
..........
Server=192.168.159.135
..........
ServerActive=192.168.159.135
..........
Hostname=Zabbix client

//创建zabbix用户
[root@slave ~]# useradd -r -M -s /sbin/nologin zabbix
[root@slave ~]# id zabbix
uid=996(zabbix) gid=994(zabbix) groups=994(zabbix)

//启动服务
[root@slave ~]# zabbix_agentd 
[root@slave ~]# ss -anlt
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128             *:22                          *:*                  
LISTEN      0      100     127.0.0.1:25                          *:*                  
LISTEN      0      128             *:10050                       *:*                  
LISTEN      0      128            :::22                         :::*                  
LISTEN      0      100           ::1:25                         :::* 

//写入监控脑裂的脚本
[root@slave ~]# cd /scripts/
[root@slave scripts]# ls
notify.sh
[root@slave scripts]# vim check_keepalived.sh 
[root@slave scripts]# cat check_keepalived.sh
#!/bin/bash

if [ `ip a show eth0 |grep 192.168.159.250|wc -l` -ne 0 ]
then
    echo "1"
else
    echo "0"
fi
[root@slave scripts]# chmod +x check_keepalived.sh 
[root@slave scripts]# ll
total 8
-rwxr-xr-x 1 root root 110 Jul 31 18:01 check_keepalived.sh
-rwxr-xr-x 1 root root 451 Jul 31 17:32 notify.sh
[root@slave scripts]# ./check_keepalived.sh 
0

//把脚本写入配置文件
[root@slave ~]# vim /usr/local/etc/zabbix_agentd.conf
.............
UnsafeUserParameters=1
UserParameter=check_process[*],/bin/bash /scripts/check_keepalived.sh $1

//重启服务
[root@slave ~]# pkill zabbix
[root@slave ~]# zabbix_agentd 

4. 在server端,手动测试脚本有没有问题

[root@Server ~]# zabbix_get -s 192.168.159.144 -k check_process
0                      //能看到0就是没错的!! 

5. 在web界面配置监控项(zabbix server端)

5.1 创建主机

Linux项目之zabbix监控脑裂

5.2 添加监控项

Linux项目之zabbix监控脑裂

5.3 添加触发器

Linux项目之zabbix监控脑裂
Linux项目之zabbix监控脑裂

5.4 添加媒介

Linux项目之zabbix监控脑裂
Linux项目之zabbix监控脑裂

5.5 添加动作

Linux项目之zabbix监控脑裂
Linux项目之zabbix监控脑裂

5.6 进入Latest data查看

Linux项目之zabbix监控脑裂
Linux项目之zabbix监控脑裂

6. 触发监控

修改备上的配置文件,让备与主的virtual_router_id不一样,就是争抢VIP,导致脑裂

[root@slave ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

...............

    virtual_router_id 52

...............

//重启服务
[root@slave ~]# systemctl restart keepalived
[root@slave ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:23:3e:ef brd ff:ff:ff:ff:ff:ff
    inet 192.168.159.144/24 brd 192.168.159.255 scope global dynamic eth0
       valid_lft 1681sec preferred_lft 1681sec
    inet 192.168.159.250/32 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe23:3eef/64 scope link 
       valid_lft forever preferred_lft forever 

查看有没有监控到
Linux项目之zabbix监控脑裂
Linux项目之zabbix监控脑裂

本文地址:https://blog.csdn.net/DragonYear/article/details/107835201

相关标签: Linux zabbix