一共两台机器(43和47,43为主),虚拟IP可以实现自动在两台机器之间切换,刚开始启动虚拟ip在43上,无法访问;把43的keepalived停掉,虚拟ip到47上,可以访问;重启43的keepalived,无法访问。配置文件内容如下:
! Configuration File for keepalived
global_defs {
router_id host-10-193-0-43
}
vrrp_script chk_consul{
script "/home/keepalived/consul_check.sh"
interval 2
weight -20
}
vrrp_script chk_rpcxc{
script "/home/keepalived/rpcxc_check.sh"
interval 2
weight -20
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.193.0.198/20
}
track_script{
chk_consul
}
}
两台机器除了router_id和priority不一样外,其他都一样