nginx负载均衡三:keepalive+nginx双机热备 和负载均衡

环境 centos7.0 nginx:1.15

1.主备四台服务器
f1:负载均衡  192.168.70.169
f2:web站点  192.168.70.170
f3:web站点  192.168.70.172
f4:web站点   192.168.70.173
 

2.安装keepalived需要的依赖包

yum install openssl-devel
yum install popt-devel
yum install ipvsadm
yum install libnl*

3.下载keepalived

yum install keepalived

4.修改主服务器配置文件

vim /etc/keepalived/keepalived.conf

主服务器配置 192.168.70.169

global_defs {
   notification_email {
     acassen@firewall.loc   // 没有配置服务器邮箱,可以去掉
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER     //  双机热备(主)
    interface eth4     // 选择网络(用ip add 查看网络,选择其中1个)
    virtual_router_id 51  // 和(副机)一样
    priority 100  // 主机选100(副机要低于100)
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111  //  密码(主副要保持一直)
    }
    virtual_ipaddress {
    192.168.70.84  // 虚拟ip(随便写一个没用过的),通常写1个(也可以多个),注意:这里不是填写web服务器ip(如:192.168.70.172,192.168.70.173)
    #192.168.70.83
    }
}

副服务器配置  192.168.70.170

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth4
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
#192.168.70.83
192.168.70.84

    }
}

 5.浏览器打开

5.1启动主服务器

service keepalived start
// 或者
#systemctl start keepalived

再浏览器打开:192.168.70.84

5.2关闭主服务器,打开BACKUP服务器

service keepalived start
// 或者
#systemctl start keepalived

再浏览器打开:192.168.70.84

总结:打开192.168.70.84 都可以访问到内容

最后nginx负载均衡

总结:

准备

f1:负载均衡  192.168.70.169 (keepalived主)
f2:web站点  192.168.70.170(keepalived副)
f3:web站点  192.168.70.172(web站点)
f4:web站点   192.168.70.173(web站点)
步骤1:给192.168.70.169配置负载均衡,给192.168.70.170配置负载均衡
步骤2:keepalived创建虚拟ip:192.168.70.84把192.168.70.169和192.168.70.170进行关联
原文地址:https://www.cnblogs.com/wesky/p/9530754.html