開發監測keepalived裂腦的腳本

檢測思路:在備節點上執行腳本,若是能夠ping通主節點而且備節點有VIP就報警,讓人員介入檢查是否裂腦。shell

在LB02備節點上開發腳本並執行:bash

[root@lb02 ~]# cat /server/scripts/shell/check_split_brain.sh 
#!/bin/bash
#Author:Mr.Ding
#Created Time:2018-10-05 17:11:33
#Name:check_split_brain.sh
#Description:監測keepalived裂腦的腳本.
lb01_vip=192.168.200.16
lb01_ip=192.168.100.105
while true
do
ping -c 2 -W 3 $lb01_ip &>/dev/null
	if [ $? -eq 0 -a `ip add|grep "$lb01_vip"|wc -l` -eq 1 ]
		then
			echo "ha is split brain.warning."
	else
			echo "ha is ok"
	fi
sleep 5
done

[root@lb02 shell]# sh check_split_brain.sh 
ha is ok
ha is ok
ha is ok
ha is ok

 正常狀況下主節點活着,VIP192.168.200.16在主節點,所以不會報警,提示「ha is ok」.服務器

停掉keepalived服務後看LB02腳本執行狀況:server

在LB01上中止keepalived服務:
[root@lb01 shell]# systemctl stop keepalived

LB02上腳本執行狀況以下:
[root@lb02 shell]# sh check_split_brain.sh 
ha is ok
ha is ok
ha is ok
ha is ok
ha is ok
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.

 關掉Lb01服務器,再次查看LB02上腳本輸出狀況:blog

[root@lb02 shell]# sh check_split_brain.sh 
ha is ok
ha is ok
ha is ok
ha is ok
ha is ok
ha is ok
ha is ok
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is split brain.warning.
ha is ok
ha is ok
ha is ok
ha is ok
ha is ok

 裂腦報警就恢復了。ip

相關文章
相關標籤/搜索