首页 > 代码库 > Keepalived 双实例双主模式配置

Keepalived 双实例双主模式配置

一、环境

A 业务在 lb01 上是主模式,在 lb02 上是备模式
B 业务在 lb01 上是备模式,在 lb02 上是主模式

HostnameIP说明
lb01192.168.123.101VIP :192.168.123.100 ( 用于绑定 A 服务 www.abc.com 域名 )
lb02192.168.123.102VIP :192.168.123.200 ( 用于绑定 B 服务 bbs.abc.com 域名)

 

 

 

 

二、配置

[root@lb01 ~]# cat /etc/keepalived/keepalived.conf   ! Configuration File for keepalived                                           global_defs {                             notification_email {                     1054890557@qq.com   }   notification_email_from Alexandre.Cassen@firewall.loc      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       }}
[root@lb02 ~]# cat /etc/keepalived/keepalived.conf! Configuration File for keepalived                                           global_defs {                             notification_email {                     1054890557@qq.com   }   notification_email_from Alexandre.Cassen@firewall.loc      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     }}
[root@lb01 ~]# /etc/init.d/keepalived restart    # 查看 lb01 上的主服务器
[root@lb01 ~]# ip addr | egrep "192.168.123.100|192.168.123.200"
inet 192.168.123.100/24 scope global secondary eth0:1
[root@lb02 ~]# /etc/init.d/keepalived restart    # 查看 lb02 上的主服务器[root@lb02 ~]# ip addr | egrep "192.168.123.100|192.168.123.200"    inet 192.168.123.200/24 scope global secondary eth0:2
[root@lb01 ~]# /etc/init.d/keepalived stop       # 停掉 lb01 看会不会切换到 lb02
[root@lb02 ~]# 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
[root@lb01 ~]# /etc/init.d/keepalived start      # 再次启动看会不会切换回来[root@lb01 ~]# ip addr | egrep "192.168.123.100|192.168.123.200"    inet 192.168.123.100/24 scope global secondary eth0:1

 

 

 

 

     

 

    

Keepalived 双实例双主模式配置