Keepalived脑裂监控

Keepalived脑裂监控

环境说明:使用的vip是192.168.100.100

系统 ip
redhat 8 /keepalived—master 192.168.100.139
redhat 8 /keepalived—slave 192.168.100.140
redhat 8 /zaabix 192.168.100.1

准备工作:

master和slave配置详情见:Keepalived实现Nginx负载均衡机高可用

zabbix监控配置详情见:监控服务Zabbix部署 和 Zabbix配置

slave主机安装zabbix客户端

//slave关闭防火墙和selinux
# systemctl disable --now firewalld
# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
# setenforce 0

//安装依赖包
# yum -y install gcc gcc-c++ bzip2 pcre* make
#wget https://cdn.zabbix.com/zabbix/sources/stable/5.2/zabbix-5.2.6.tar.gz
[root@slave ~]# tar xf zabbix-5.2.6.tar.gz 
[root@slave ~]# useradd -r -M -s /sbin/nologin zabbix
[root@slave ~]# cd zabbix-5.2.6
[root@slave zabbix-5.2.6]# ./configure --enable-agent
[root@slave zabbix-5.2.6]# make install

配置zabbix配置文件

[root@slave zabbix-5.2.6]# vim /usr/local/etc/zabbix_agentd.conf
······
Server=192.168.100.6            #修改成服务端IP
······
ServerActive=192.168.100.6        #修改成服务端IP
······
Hostname=slave

[root@slave zabbix-5.2.6]# zabbix_agentd 
[root@slave zabbix-5.2.6]# ss -antl
State       Recv-Q       Send-Q              Local Address:Port              Peer Address:Port      
LISTEN      0            128                       0.0.0.0:22                     0.0.0.0:*         
LISTEN      0            128                       0.0.0.0:10050                  0.0.0.0:*         
LISTEN      0            128                          [::]:22                        [::]:*    

编写监控脚本

//slave
[root@slave zabbix-5.2.6]# cd /scripts/
[root@slave scripts]# ll / |grep scripts
drwxr-xr-x    2 zabbix zabbix   50 5月  22 00:12 scripts
[root@slave scripts]# vim check_keepalived.sh

#!/bin/bash
  
if [ `ip a show ens160 |grep 192.168.100.100|wc -l` -ne 0 ]
then
    echo "1"
else
    echo "0"
fi

[root@slave scripts]# chmod +x check_keepalived.sh
//开启自定义监控并添加指标
[root@slave ~]# vim /usr/local/etc/zabbix_agentd.conf
······
#在最后面添加以下内容
UnsafeUserParameters=1                    
UserParameter=check_slave,/scripts/check_keepalived.sh

//重启zabbix
[root@slave scripts]# pkill zabbix
[root@slave scripts]# ss -antl
State       Recv-Q       Send-Q              Local Address:Port             Peer Address:Port       
LISTEN      0            128                       0.0.0.0:22                    0.0.0.0:*          
LISTEN      0            128                          [::]:22                       [::]:*          
[root@slave scripts]# ps -ef |grep zabbix
root       9067   1132  0 02:17 pts/0    00:00:00 grep --color=auto zabbix
[root@slave scripts]# zabbix_agentd


//测试zabbix是否能获取客户端的指标
//zabbix
[root@zabbix ~]# zabbix_get -s 192.168.100.140 -k check_slave
0

编写脚本时要注意,网卡要改成你自己的网卡名称,VIP也要改成你自己的VIP,最后不要忘了给脚本赋予执行权限,且要修改/scripts目录的属主属组为zabbix

网页配置

添加主机组

Configuration —— Host groups —— 右上角 Create host group

Keepalived脑裂监控

添加主机

Configuration —— Hosts —— 右上角 Create host

Keepalived脑裂监控

添加监控项

Configuration --- Hosts --- 客户机的Items --- 右上角Create Items

Keepalived脑裂监控

添加触发器

Configuration --- Hosts --- 客户机的Triggers --- 右上角Create triggers

Keepalived脑裂监控

配置企业微信报警

详情见 Zabbix企业微信报警配置

触发触发器

//master
//master启动了keepalived和nginx
[root@RedHat ~]# ss -antl
State       Recv-Q       Send-Q              Local Address:Port             Peer Address:Port       
LISTEN      0            128                       0.0.0.0:22                    0.0.0.0:*          
LISTEN      0            128                       0.0.0.0:80                    0.0.0.0:*          
LISTEN      0            128                          [::]:22                       [::]:*          
LISTEN      0            128                          [::]:80                       [::]:*  

//slave
//slave启动了keepalived
[root@slave ~]# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-05-25 01:57:11 CST; 39min ago
  Process: 936 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 945 (keepalived)
    Tasks: 3 (limit: 12391)
   Memory: 8.6M

//master
//模拟master挂掉,slave继承,从而触发触发器
[root@master ~]# systemctl stop nginx
[root@master ~]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port        Peer Address:Port    
LISTEN    0         128                0.0.0.0:22               0.0.0.0:*       
LISTEN    0         128                   [::]:22                  [::]:* 

功能已经实现,稍后更新(使用企业微信实现zabbix监控)

Keepalived脑裂监控

 

上一篇:编程词汇


下一篇:centos7系统 安装遇到没有网络的问题