检测思路:正常情况下keepalived的VIP地址是在主节点上的,如果在从节点发现了VIP,就设置报警信息
脚本如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#!/bin/bash
# 检查脑裂的脚本,在备节点上进行部署
LB01_VIP=10.10.10.229
LB01_IP=10.10.10.129
LB02_IP=10.10.10.130
while
true
do
ping
-c 2 -W 3 $LB01_VIP &>
/dev/null
if
[ $? -
eq
0 -a `ip add|
grep
"$LB01_VIP"
|
wc
-l` -
eq
1 ];
then
echo
"ha is brain."
else
echo
"ha is ok"
fi
sleep
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.
|
说明:可以将此脚本与监控平台进行结合(比如zabbix以及nagios等)
本文转自 冰冻vs西瓜 51CTO博客,原文链接:http://blog.51cto.com/molewan/1880210,如需转载请自行联系原作者