一、环境
A 业务在 lb01 上是主模式,在 lb02 上是备模式
B 业务在 lb01 上是备模式,在 lb02 上是主模式
Hostname | IP | 说明 |
lb01 | 192.168.123.101 | VIP :192.168.123.100 ( 用于绑定 A 服务 www.abc.com 域名 ) |
lb02 | 192.168.123.102 | VIP :192.168.123.200 ( 用于绑定 B 服务 bbs.abc.com 域名) |
二、配置
[[email protected]lb01 ~]# cat /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 lb01 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 55 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.123.100/24 dev eth0 label eth0:1 } } vrrp_instance VI_2 { state BACKUP interface eth0 virtual_router_id 56 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.123.200/24 dev eth0 label eth0:2 } }
[[email protected]lb02 ~]# cat /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 lb02 } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 55 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.123.100/24 dev eth0 label eth0:1 } } vrrp_instance VI_2 { state MASTER interface eth0 virtual_router_id 56 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.123.200/24 dev eth0 label eth0:2 } }
[[email protected] ~]# /etc/init.d/keepalived restart # 查看 lb01 上的主服务器[[email protected] ~]# ip addr | egrep "192.168.123.100|192.168.123.200" inet 192.168.123.100/24 scope global secondary eth0:1
[[email protected] ~]# /etc/init.d/keepalived restart # 查看 lb02 上的主服务器 [[email protected] ~]# ip addr | egrep "192.168.123.100|192.168.123.200" inet 192.168.123.200/24 scope global secondary eth0:2
[[email protected] ~]# /etc/init.d/keepalived stop # 停掉 lb01 看会不会切换到 lb02[[email protected] ~]# ip addr | egrep "192.168.123.100|192.168.123.200" inet 192.168.123.200/24 scope global secondary eth0:2 inet 192.168.123.100/24 scope global secondary eth0:1
[[email protected] ~]# /etc/init.d/keepalived start # 再次启动看会不会切换回来 [[email protected] ~]# ip addr | egrep "192.168.123.100|192.168.123.200" inet 192.168.123.100/24 scope global secondary eth0:1
时间: 2024-10-13 12:02:14