keepalived实验

http://www.keepalived.org/manpage.html
https://www.cnblogs.com/clsn/p/8052649.html

master

! Configuration File for keepalived

global_defs {
   router_id lb01
}
vrrp_script check {
   script "/server/scripts/check_www.sh"
   interval 2
   weight 2
}
vrrp_instance VI_1 {
    state MASTER
    interface ens160
    virtual_router_id 51
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.88.1.99/24 dev ens160 label ens160:1
    }
    track_script {
    	check
    }
}

backup

! Configuration File for keepalived

global_defs {
   router_id lb02
}
vrrp_script check {
   script "/server/scripts/check_www.sh"
   interval 2
   weight 2
}
vrrp_instance VI_1 {
    state BACKUP
    interface ens160
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.88.1.99/24 dev ens160 label ens160:1
    }
    track_script {
        check
    }
}

check_www.sh

#查出id
ps -ef |grep nginx |grep -v grep |wc -l 
#!/bin/bash

while true
do
if [ `ps -ef |grep nginx |grep -v grep |wc -l` -lt #查出id ]
then
   /etc/init.d/keepalived stop
   exit
fi
done

如果nginx 服务stop的话 keepalived就会自动down掉,然后虚拟ip自动切换
如果nginx服务再次启动的话,还要手动启动keepalived

由于走的是arp协议,所以不能跨网段
使用vpn两个局域网测试 虚拟ip可以浮动,但一方不通?@todo

发表评论

电子邮件地址不会被公开。 必填项已用*标注