利用子配置文件实现master/master的keepalived双主架构
Posted y_zilong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了利用子配置文件实现master/master的keepalived双主架构相关的知识,希望对你有一定的参考价值。
ka1的子配置文件
[root@ka1 ~]# cat /etc/keepalived/conf.d/m1.conf
vrrp_instance m1 {
state MASTER
interface ens33
virtual_router_id 66
priority 100
advert_int 1
preempt_delay 10
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
10.0.0.100/24 dev ens33 label ens33:1
}
unicast_src_ip 10.0.0.10
unicast_peer {
10.0.0.20
}
}
[root@ka1 ~]# cat /etc/keepalived/conf.d/m2.conf
vrrp_instance m2 {
state MASTER
interface ens33
virtual_router_id 88
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
10.0.0.200/24 dev ens33 label ens33:1
}
unicast_src_ip 10.0.0.10
unicast_peer {
10.0.0.20
}
}
[root@ka1 ~]#
ka2的子配置文件
[root@ka2 ~]# cat /etc/keepalived/conf.d/m1.conf
vrrp_instance m1 {
state BACKUP
interface ens33
virtual_router_id 66
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
10.0.0.100/24 dev ens33 label ens33:0
}
unicast_src_ip 10.0.0.20
unicast_peer {
10.0.0.10
}
}
[root@ka2 ~]# cat /etc/keepalived/conf.d/m2.conf
vrrp_instance m2 {
state MASTER
interface ens33
virtual_router_id 88
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
10.0.0.200/24 dev ens33 label ens33:0
}
unicast_src_ip 10.0.0.20
unicast_peer {
10.0.0.10
}
}
[root@ka2 ~]#
查看IP
[root@ka1 ~]# hostname -I
10.0.0.10 10.0.0.100
[root@ka1 ~]#
[root@ka2 ~]# hostname -I
10.0.0.20 10.0.0.200
[root@ka2 ~]#
ka1主机故障,测试VIP漂移至ka2主机
[root@ka1 ~]# killall keepalived
[root@ka1 ~]# hostname -I
10.0.0.10
[root@ka2 ~]# hostname -I
10.0.0.20 10.0.0.200 10.0.0.100
[root@ka2 ~]#
恢复ka1主机
[root@ka1 ~]# systemctl start keepalived.service
[root@ka1 ~]# hostname -I
10.0.0.10 10.0.0.100
[root@ka2 ~]# hostname -I
10.0.0.20 10.0.0.200
[root@ka2 ~]#
脑裂现象
[root@ka1 ~]# hostname -I
10.0.0.10 10.0.0.100
[root@ka1 ~]# iptables -A INPUT -s 10.0.0.20 -j DROP
[root@ka1 ~]# hostname -I
10.0.0.10 10.0.0.100 10.0.0.200
[root@ka2 ~]# hostname -I
10.0.0.20 10.0.0.200
[root@ka2 ~]#
[root@ka2 ~]# hostname -I
10.0.0.20 10.0.0.200
[root@ka2 ~]# iptables -A INPUT -s 10.0.0.10 -j REJECT
[root@ka2 ~]# hostname -I
10.0.0.20 10.0.0.200 10.0.0.100
[root@ka2 ~]#
[root@ka1 ~]# iptables -F
[root@ka1 ~]# hostname -I
10.0.0.10 10.0.0.100
[root@ka1 ~]#
[root@ka2 ~]# iptables -F
[root@ka2 ~]# hostname -I
10.0.0.20 10.0.0.200
[root@ka2 ~]#
以上是关于利用子配置文件实现master/master的keepalived双主架构的主要内容,如果未能解决你的问题,请参考以下文章