高可用--Nginx+keepalived

主从

Nginx安装

源码安装:请看 Nginx 篇 Yum安装::yum install epel-release -y && yum install nginx -y

keepalived 安装

源码安装:请参考 Lvs + keepalived 中安装keepalived Yum 安装:yum install keepavlied -y

keepalived 主要配置:

···
vrrp_instance VI_1 {  
    state MASTER  
    interface eth0  
    virtual_router_id 51  
    priority 100  
    advert_int 1  
    authentication {  
        auth_type PASS  
        auth_pass 1111  
    }  
    virtual_ipaddress {  
        10.128.25.24  
    }  
}  

···

vrrp_instance VI_1 {  
    state BACKUP  
    interface eth0  
    virtual_router_id 51  
    priority 90  
    advert_int 1  
    authentication {  
        auth_type PASS  
        auth_pass 1111  
    }  
    virtual_ipaddress {  
        10.128.25.24  
    }  
}  

主主

初始化

主一

vrrp_instance VI_1 {  
    state MASTER  
    interface eth0  
    virtual_router_id 51  
    priority 100  
    advert_int 1  
    authentication {  
        auth_type PASS  
        auth_pass 1111  
    }  
    virtual_ipaddress {  
        10.128.25.24  
    }  
}  
  
#VIP2  
  
vrrp_instance VI_2 {  
    state BACKUP  
    interface eth0  
    virtual_router_id 52  
    priority 90  
    advert_int 1  
    authentication {  
        auth_type PASS  
        auth_pass 2222  
    }  
    virtual_ipaddress {  
        10.128.25.26  
    }  
}  

主二

vrrp_instance VI_1 {  
    state BACKUP  
    interface eth0  
    virtual_router_id 51  
    priority 90  
    advert_int 1  
    authentication {  
        auth_type PASS  
        auth_pass 1111  
    }  
    virtual_ipaddress {  
        10.128.25.24  
    }  
}  
#VIP2  
  
vrrp_instance VI_2 {  
    state MASTER  
    interface eth0  
    virtual_router_id 52  
    priority 100  
    advert_int 1  
    authentication {  
        auth_type PASS  
        auth_pass 2222  
    }  
    virtual_ipaddress {  
        10.128.25.26  
    }  
}  

Last updated