配置 keepalived非抢占模式方法
1、有两台keepalived主备服务器 192.168.122.38 是主 192.168.122.49是备

2、两台机器均已经使用了yum install keepalived进行了安装,安装完成后先把主配置文件备份一下

3、keep1的配置keepalived.conf,我们这里只做ip资源的漂移切换
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 50
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.122.200
}
}

4、keep2的配置keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 50
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.122.200
}
}

5、当前vip 192.168.122.200在keep1上,目前把keep1重启操作。192.168.122.200飘向了keep2


6、但是当系统重启完成,恢复健康之后VIP 192.168.122.200 又被keep1给"争夺"回来了

7、keep1的keepalived.conf修改如下
state MASTER -->state BACKUP
增加nopreempt

8、当keep1重启完成,系统恢复之后,VIP这次没有再"抢夺"过来。配置成功,完美。
主要是在之前的master上操作,只有master“喜欢”抢占资源,而且还是默认抢占的哦
