keepalived脑裂切换思路

2023年 7月 15日 62.9k 0

keepalived切换脚本实现ps -ef查看nginx进程少于2个则判定nginx宕机,而后关闭keepalived

[root@nginx-proxy ~]# cat keepalived.sh 
#!/bin/bash
while true
do
if [ `ps -ef|grep nginx|grep -v grep|wc -l` -lt 2 ]
    then
    /etc/init.d/keepalived stop
fi
sleep 5
done
[root@nginx-proxy ~]# 

两台机器通过同一个机房使用keepalived时候,竟可能使用串口线之类的直连1,使用单独的网卡直连2,使用电源管理器3,脚本(只要发生切换则报警,人为介入)例子:假设备用节点收到vip地址且主节点还活着则人为是脑裂状态可以如下的判定,在备节点上运行脚本ping主节点,如果主节点能ping同,且vip飘逸到备几点则判定为脑裂

另外,我们可以使用arping来ping,如下

[root@DS-VM-linuxea /etc/graylog/collector-sidecar/generated]# arping -c 1 10.10.194.100
ARPING 10.10.194.100 from 10.10.231.61 eth0
Unicast reply from 10.10.194.100 [88:88:2F:9A:97:84]  1.768ms
Unicast reply from 10.10.194.100 [88:88:2F:60:CD:40]  1.858ms
Sent 1 probes (1 broadcast(s))
Received 2 response(s)
[root@DS-VM-linuxea /etc/graylog/collector-sidecar/generated]# 

但我们在旁路机器上arping vip地址如果出现脑裂这会有两个mac地址!

更多可参考这几篇文章:heartbeat心跳问题解决二fence思路 http://www.linuxea.com/939.htmlheartbeat列脑的发生和防止思路 http://www.linuxea.com/941.html

[root@nginx-proxy scripts]# cat lienao.sh 
#!/bin/sh
while true
do
ping -c 5 -w 3 10.0.0.91 &>/dev/null
if [ $? -eq 0 -a `ip add|grep 10.0.0.100|wc -l` -eq 1 ]
then
     echo "HA is Brain column!"
else
    echo "HA is run OK!"
fi
sleep 5
done
[root@nginx-proxy scripts]# 

keepalived双主

[root@nginx-proxy scripts]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
   734943463@qq.com   
}
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface eth1
    virtual_router_id 51
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    10.0.0.100/24
    }
}

    vrrp_instance VI_2 {
        state BACKUP
        interface eth1
        virtual_router_id 52
        priority 50
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
        10.0.0.101/24
        }
    }
    [root@nginx-proxy scripts]# 
[root@nginx-proxy2 scripts]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
   734943463@qq.com   
}
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth1
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    10.0.0.100/24
    }
}
vrrp_instance VI_2 {
    state MASTER
    interface eth1
    virtual_router_id 52
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    10.0.0.101/24
    }
}
[root@nginx-proxy scripts]# 

请输入图片描述

相关文章

LeaferJS 1.0 重磅发布:强悍的前端 Canvas 渲染引擎
10分钟搞定支持通配符的永久有效免费HTTPS证书
300 多个 Microsoft Excel 快捷方式
一步步配置基于kubeadmin的kubevip高可用
istio全链路传递cookie和header灰度
REST Web 服务版本控制

发布评论