环境准备
test1
eth0:18.1.30.58 eth1:192.168.87.200
test2
eth0:18.1.30.59 eth1:192.168.87.180
VIP
18.1.30.30 192.168.87.87
test1 keepalived的配置
vrrp_sync_group VGM {
group {
VI_HA
}
}
vrrp_instance VI_HA {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_interface {
eth0
eth1
}
virtual_ipaddress {
18.1.30.30/24 dev eth0
192.168.87.87/24 dev eth1
}
}
test2 keepalived的配置
vrrp_sync_group VGM {
group {
VI_HA
}
}
vrrp_instance VI_HA {
state BACKUP
interface eth0
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_interface {
eth0
eth1
}
virtual_ipaddress {
18.1.30.30/24 dev eth0
192.168.87.87/24 dev eth1
}
}
测试
[root@test1 ~]# ifdown eth0
双网卡双vrrp实例
如果keepalived有两个网段,每个网段开启一个vrrp实例,当外网出现故障的话,keepalived任然认为自己很健康,所以就进行master和backup的切换,这样会导致外网不可用
解决方法是把两个实例放进一个sync group中
test2 keepalived的配置
global_defs {
router_id HAWEB
}
vrrp_sync_group VGM {
group {
VI_HA_1
VI_HA_1
}
}
vrrp_instance VI_HA_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_interface {
eth0
eth1
}
virtual_ipaddress {
18.1.30.30/24 dev eth0
}
}
vrrp_instance VI_HA_2 {
state BACKUP
interface eth1
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_interface {
eth0
eth1
}
virtual_ipaddress {
192.168.87.87/24 dev eth1
}
}
test1 keepalived的配置
global_defs {
router_id HAWEB
}
vrrp_sync_group VGM {
group {
VI_HA_1
VI_HA_1
}
}
vrrp_instance VI_HA_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_interface {
eth0
eth1
}
virtual_ipaddress {
18.1.30.30/24 dev eth0
}
}
state BACKUP
interface eth1
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_interface {
eth0
eth1
}
virtual_ipaddress {
192.168.87.87/24 dev eth1
}
}
测试
[root@test1 ~]# ifdown eth0