zoukankan      html  css  js  c++  java
  • 开发监测keepalived裂脑的脚本

    检测思路:在备节点上执行脚本,如果可以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
    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脚本执行情况:

    在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
    

     裂脑报警就恢复了。

  • 相关阅读:
    CF 7C. Line(扩展欧几里德)
    HDU 1700 Points on Cycle(向量旋转)
    POJ 1673 EXOCENTER OF A TRIANGLE(垂心)
    SRM 594 DIV1 250
    Codeforces Round #207 (Div. 1) A. Knight Tournament(STL)
    POJ 1654 Area(水题)
    POJ 1474 Video Surveillance(半平面交)
    POJ 1473 There's Treasure Everywhere!
    POJ 1329 Circle Through Three Points(三角形外心)
    POJ 1279 Art Gallery(半平面交)
  • 原文地址:https://www.cnblogs.com/Mr-Ding/p/9745317.html
Copyright © 2011-2022 走看看