Keepalived非抢占模式配置
1、前言
非抢占模式,这种模式主要是针对主机崩溃,集群已经重新选出新的主机,并且原来的主机重新上线后并不争夺主机的情况。这种模式适合那些倾向于认为崩溃的主机即便上线还是会出现崩溃的场景。
这种模式的核心思想是将所有节点的优先级(priority)值设为相同,当两个节点的优先级相同时,以节点发送VRRP通告的IP作为比较对象,IP较大者为MASTER。
2、keepalived 非抢占配置
主机名 | 物理IP | VIP |
---|---|---|
slave01 | 192.168.200.21 | 192.168.200.23 |
slave02 | 192.168.200.22 | 192.168.200.23 |
2.1 安装Keepalived
[root@slave01 ~]# yum -y install keepalived
2.2 修改Keepalived配置
1、修改keepalived配置
# slave01
vrrp_instance VI_1 {
state BACKUP # 都设置为BACKUP,首先启动的作为Master
nopreempt # 非抢占模式
interface ens32
virtual_router_id 50
priority 100
advert_int 1
authentication {
auth_type AH # keepalived认证,类型有AH加密和PASS明文
auth_pass 111111
}
unicast_src_ip 192.168.200.21 # 绑定本地IP
unicast_peer {
192.168.200.22 # 集群内其他IP,可以有多个
}
virtual_ipaddress {
192.168.200.23/24 dev ens32 albel ens32:1 # 虚拟VIP
}
}
# slave02
vrrp_instance VI_1 {
state BACKUP
nopreempt
interface ens32
virtual_router_id 50
priority 100
advert_int 1
authentication {
auth_type AH
auth_pass 111111
}
unicast_src_ip 192.168.200.22
unicast_peer {
192.168.200.21
}
virtual_ipaddress {
192.168.200.23/24 dev ens32 albel ens32:1
}
}
2.3 测试
都设置为BACKUP,首先启动的作为Master
2.3.1 测试VIP是否可正常漂移
# 模拟测试先启动slave02
[root@slave02 ~]# systemctl start keepalived
[root@slave02 ~]# ip addr | grep 192.168.200.23
inet 192.168.200.23/24 scope global secondary ens32
# 最后启动slave01
[root@slave01 ~]# systemctl start keepalived
# 手动停止slave02的keepalived进程
[root@slave01 ~]# systemctl stop keepalived
# slave02上面的VIP不见了
[root@slave01 ~]# ip addr | grep 192.168.200.23
[root@slave01 ~]#
# 发现VIP漂移到了slave01了
[root@slave01 ~]# ip addr | grep 192.168.200.23
inet 192.168.200.23/24 scope global secondary ens32
2.3.2 测试非抢占模式功能
# 启动slave02上面keepalived进程
[root@slave02 ~]# systemctl start keepalived
[root@slave02 ~]# systemctl start keepalived
[root@slave02 ~]#
# 发现VIP并未漂移,还在slave01节点
[root@slave01 ~]# ip addr | grep 192.168.200.23
inet 192.168.200.23/24 scope global secondary ens32
标签:抢占,keepalived,200.23,Keepalived,192.168,slave01,模式,root,slave02
From: https://www.cnblogs.com/ywb123/p/17585993.html