抢占模式下,优先级决定VIP的归属
经实验测试,抢占还是看priority
的参数
实验环境1:
服务器1
- state MASTER priority 100
服务器2
- state BACKUP priority 100
测试结果:
第一次启动,MASTER会先转换MASTER状态并确认MASTER状态,优先抢占
Feb 26 18:13:28 centos7 Keepalived_vrrp[11535]: VRRP_Instance(web) Transition to MASTER STATE
Feb 26 18:13:30 centos7 Keepalived_vrrp[11535]: VRRP_Instance(web) Entering MASTER STATE
Feb 26 18:13:25 centos7 Keepalived_vrrp[12033]: Using LinkWatch kernel netlink reflector...
Feb 26 18:13:25 centos7 Keepalived_vrrp[12033]: VRRP_Instance(web) Entering BACKUP STATE
服务器1down,服务器2抢占
服务器1 up,但抢占不成功,直到服务器2 down
Feb 26 18:15:33 centos7 Keepalived_vrrp[11553]: VRRP_Instance(web) Transition to MASTER STATE
Feb 26 18:15:33 centos7 Keepalived_vrrp[11553]: VRRP_Instance(web) Received advert with higher priority 100, ours 100
Feb 26 18:15:33 centos7 Keepalived_vrrp[11553]: VRRP_Instance(web) Entering BACKUP STATE
实验环境2:
服务器1
- state BCAKUP priority 100
服务器2
- state BACKUP priority 80
测试结果:
启动服务器1抢占
服务器1down,服务器2抢占
服务器1 up,优先级高于服务器2,抢占成功
实验环境3:
服务器1
- state MASTER priority 100
服务器2
- state BACKUP priority 120
测试结果
Feb 26 18:26:57 centos7 Keepalived_vrrp[11594]: VRRP_Instance(web) Transition to MASTER STATE
Feb 26 18:26:57 centos7 Keepalived_vrrp[11594]: VRRP_Instance(web) Received advert with higher priority 120, ours 100
Feb 26 18:26:57 centos7 Keepalived_vrrp[11594]: VRRP_Instance(web) Entering BACKUP STATE
服务器2优先级高,从BACKUP转换成MASTER,抢占成功
Feb 26 18:26:50 centos7 Keepalived_vrrp[12069]: VRRP_Instance(web) Entering BACKUP STATE
Feb 26 18:26:50 centos7 Keepalived_vrrp[12069]: VRRP sockpool: [ifindex(2), proto(112), unicast(1), fd(10,11)]
Feb 26 18:26:56 centos7 Keepalived_vrrp[12069]: VRRP_Instance(web) Transition to MASTER STATE
Feb 26 18:26:56 centos7 Keepalived_vrrp[12069]: VRRP_Instance(web) Received advert with lower priority 100, ours 120, forcing new election
Feb 26 18:26:58 centos7 Keepalived_vrrp[12069]: VRRP_Instance(web) Entering MASTER STATE
实验环境4:
服务器1
- state BCAKUP priority 100
服务器2
- state BACKUP priority 100
测试结果
哪个服务器优先启动,优先抢占
非抢占模式nopreempt’
MASTER下不生效
Feb 26 18:32:10 centos7 Keepalived_vrrp[11615]: (web): Warning - nopreempt will not work with initial state MASTER
实验环境1:
服务器1
- state BACKUP priority 100
服务器2
- state BACKUP priority 80
测试结果
服务器1down后,重启,即使优先级高也不抢占