開發監測keepalived裂腦的指令碼

2022-08-03 00:51:09 字數 2136 閱讀 4339

檢測思路:在備節點上執行指令碼,如果可以ping通主節點並且備節點有vip就報警,讓人員介入檢查是否裂腦。

在lb02備節點上開發指令碼並執行:

[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

doping -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"

fisleep 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指令碼執**況:

在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上指令碼輸出情況:

[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

裂腦報警就恢復了。

Keepalived監測指令碼一直不執行

今天在搭建nginx keepalived集群時,啟動keepalievd發現檢查指令碼不執行,指令碼本身是沒有問題的。a ps c nginx no header wc l if a eq 0 then root nginx sbin nginx if ps c nginx no header w...

利用shell開發keepalived啟動指令碼

啟動方式 keepalived f 配置檔案 絕對路徑 p pid檔案 絕對路徑 關閉方式 kill cat pid檔案 絕對路徑 注意 該指令碼只能linux的超級使用者root才能啟動,因為指令碼中有進行限制 bin bash define variables retval 0 conf exc...

iOS開發 電池電量監測

一 電池狀態獲取及監測 pragma mark 電池狀態獲取及監控 void checkandmonitorbatterystate tvos prohibited uidevicebatterystate state device.batterystate nsarray statearray n...