Keepalived+Nginx 高可用集群(双主模式)

将keepalived做成双主模式,其实很简单,就是再配置一段新的vrrp_instance(实例)规则,主上面加配置一个从的实例规则,从上面加配置一个主的实例规则。

集群架构图:

环境参考

https://www.cnbugs.com/post-2615.html

说明:还是按照上面的环境继续做实验,只是修改LB节点上面的keepalived服务的配置文件即可。

1、keepalived1配置文件

[root@LB-01 ~]# vim /etc/keepalived/keepalived.conf   //编辑配置文件,增加一段新的vrrp_instance规则
! Configuration File for keepalived

global_defs {
   notification_email {
    381347268@qq.com
   }
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    10.168.1.222/24 dev ens33 label ens33:1
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface ens33
    virtual_router_id 52
    priority 100
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 2222
    }
    virtual_ipaddress {
    10.168.1.223/24 dev ens33 label ens33:2
    }
}
 [root@LB-01 ~]# systemctl restart keepalived    //重新启动keepalived 

keepalived2配置文件

[root@LB-02 ~]# vim /etc/keepalived/keepalived.conf    //编辑配置文件,增加一段新的vrrp_instance规则
! Configuration File for keepalived

global_defs {
   notification_email {
    381347268@qq.com
   }
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    10.168.1.222/24 dev ens33 label ens33:1
    }
}

vrrp_instance VI_2 {
    state MASTER
    interface ens33
    virtual_router_id 52
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        10.168.1.223/24 dev ens33 label ens33:2
    }   
}
 [root@LB-02 ~]# systemctl restart keepalived    //重新启动keepalived 

查看IP都会出现VIP地址

测试

发表评论

后才能评论