Keepalived 双实例双主模式配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Keepalived 双实例双主模式配置相关的知识,希望对你有一定的参考价值。

一、环境

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

 

 

 

 

     

 

    

以上是关于Keepalived 双实例双主模式配置的主要内容,如果未能解决你的问题,请参考以下文章

配置MySQL实现主主互备模式并利用keepalived实现双主高可用

Keepalived双主模式配置流程

Keepalived实现双主的LVS-DR模式

keepalived 安装配置(高可用VIP),双主模式

Nginx+keepalived(高可用双主模式)

Keepalived 高可用集群