Keepalived双主模式配置流程
Posted liming-linux-python
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Keepalived双主模式配置流程相关的知识,希望对你有一定的参考价值。
实验说明
1)keepalived 支持配置多个VRRP实例,每个实例对应一个业务
2)本次实验将实现 keepalived 的互为主备:
业务A:keepalived01为Master,keepalived02为Backup
业务B:keepalived01为Backup,keepalived02为Master
环境介绍
1)K1
Hostname:keepalived01.example.com
IP:192.168.3.31
OS:Centos 7
2)K2
Hostname:keepalived02.example.com
IP:192.168.3.25
OS:Centos 7
3)VIP
业务A:192.168.3.33
业务B:192.168.3.133
安装配置
1、环境准备(略)
1)主机名配置
2)hosts文件解析
3)时间同步
2、keepalived01
[[email protected] ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id keepalived01
}
vrrp_instance A1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.3.33/24 dev eth0 label eth0:0
}
}
vrrp_instance B1 {
state BACKUP
interface eth0
virtual_router_id 52
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
192.168.3.133/24 dev eth0 label eth0:1
}
}
3、keepalived01
[[email protected] ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id keepalived02
}
vrrp_instance A2 {
state BCAKUP
interface eth0
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.3.33/24 dev eth0 label eth0:0
}
}
vrrp_instance B2 {
state MASTER
interface eth0
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
192.168.3.133/24 dev eth0 label eth0:1
}
}
4、配置测试
[[email protected] ~]# systemctl reload keepalived.service
[[email protected] ~]# ifconfig|grep 192.168.3.33|wc -l
1
[[email protected] ~]# ifconfig|grep 192.168.3.133|wc -l
0
[[email protected] ~]# systemctl reload keepalived.service
[[email protected] ~]# ifconfig|grep 192.168.3.33|wc -l
0
[[email protected] ~]# ifconfig|grep 192.168.3.133|wc -l
1
[[email protected] ~]# systemctl stop keepalived.service
[[email protected] ~]# ifconfig|grep 192.168.3.33|wc -l
0
[[email protected] ~]# ifconfig|grep 192.168.3.133|wc -l
0
[[email protected] ~]# ifconfig|grep 192.168.3.33|wc -l
1
[[email protected] ~]# ifconfig|grep 192.168.3.133|wc -l
1
[[email protected] ~]# systemctl stop keepalived.service
[[email protected] ~]# ifconfig|grep 192.168.3.33|wc -l
0
[[email protected] ~]# ifconfig|grep 192.168.3.133|wc -l
0
[[email protected] ~]# systemctl start keepalived.service
[[email protected] ~]# ifconfig|grep 192.168.3.33|wc -l
1
[[email protected] ~]# ifconfig|grep 192.168.3.133|wc -l
1
以上是关于Keepalived双主模式配置流程的主要内容,如果未能解决你的问题,请参考以下文章