keepaliaved 抢占式配置
抢占模式即MASTER从故障中恢复后,会将VIP从BACKUP节点中抢占过来。非抢占模式即MASTER恢复后不抢占BACKUP升级为MASTER后的VIP
rpm -qc keepalived
vim /etc/keepalived/keepalived.conf
-
master配置
! Configuration File for keepalived global_defs { router_id lb02 #标识信息,一个名字而已; } vrrp_instance VI_1 { state MASTER #角色是master interface eth0 #vip 绑定端口 virtual_router_id 50 #让master 和backup在同一个虚拟路由里,id 号必须相同; priority 150 #优先级,谁的优先级高谁就是master ; advert_int 1 #心跳间隔时间 authentication { auth_type PASS #认证 auth_pass 1111 #密码 } virtual_ipaddress { 10.0.0.3 #虚拟ip } }
-
backup配置
! Configuration File for keepalived global_defs { router_id lb02 } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 50 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.0.0.3 } }
Keepalived非抢占式配置
非抢占式不再有主从之分,全部都为BACKUP,并且配置文件中添加nopreempt,用来标识为非抢占式;
其中一个节点的优先级必须要高于另外一个节点的优先级
-
主机
vrrp_instance VI_1 { state BACKUP nopreempt priority 100 advert_int 1 virtual_router_id 1 interface eth0 authentication { auth_type PASS auth_pass abcd@hehe } virtual_ipaddress { 100.92.2.110 } }
-
备机
vrrp_instance VI_1 { state BACKUP nopreempt priority 90 advert_int 1 virtual_router_id 1 interface eth0 authentication { auth_type PASS auth_pass abcd@hehe } virtual_ipaddress { 100.92.2.110 } }
“
nopreempt
” allows the lower priority machine to maintain the master role, even when a higher priority machine comes back online.NOTE: For this to work, the initial state of this entry
must be
BACKUP
.