检测思路:正常情况下keepalived的VIP地址是在主节点上的,如果在从节点发现了VIP,就设置报警信息
脚本如下:
#!/bin/bash # 检查脑裂的脚本,在备节点上进行部署 LB01_VIP=10.10.10.229 LB01_IP=10.10.10.129 LB02_IP=10.10.10.130 while true doping -c 2 -W 3 $LB01_VIP &>/dev/nullif [ $? -eq 0 -a `ip add|grep "$LB01_VIP"|wc -l` -eq 1 ];thenecho "ha is brain."elseecho "ha is ok"fisleep 5 done 执行结果如下: [root@mysql-master mysqlbackup]# bash check_split_brain.sh ha is ok ha is ok ha is ok ha is ok 当发现异常时候的执行结果: [root@mysql-master mysqlbackup]# bash check_split_brain.sh ha is ok ha is ok ha is ok ha is ok ha is brain. ha is brain.