global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
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 {
10.0.0.12/24 dev eth0 label eth0:1
}
}
vrrp_instance VI_2 {
state BACKUP
interface eth0
virtual_router_id 55
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.13/24 dev eth0 label eth0:2
}
}
lb02
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 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 {
10.0.0.12/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 {
10.0.0.13/24 dev eth0 label eth0:2
}
}
如此一来,两个Keepalived集群节点的资源都得到了充分利用,可以考虑两个实例为不同的业务提供服务,例如,实例1可以作为业务bbs.linuxidc.com的主用设备,实例2可以作为业务blog.linuxidc.com的主用设备。
然后在每个高可用集群节点中,为两个不同的业务分别配置两个不同的upstream服务器池,从而实现前端反向代理高可用和负载均衡,高可用集群后端的服务器池在不同的业务中也能提供负载均衡。
结合上面的分析,就可以得到Nginx负载均衡配合Keepalived双实例双主模式的场景了。
4.Nginx负载均衡集群配合Keepalived双实例双主模式集群方案
根据3的分析结果,参考下面的图示,注意下面这个图中的Keepalive配置与3的是一样的:
对应Nginx的配置如下:
lb01
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream bbs_server_pools { # bbs业务服务器池
server 10.0.0.101:80 weight=1;
server 10.0.0.102:80 weight=1;
# 假设10.0.0.101和10.0.0.102为bbs业务的两个集群节点
}
upstream blog_server_pools { # blog业务服务器池
server 10.0.0.103:80 weight=1;
server 10.0.0.104:80 weight=1;
# 假设10.0.0.103和10.0.0.104为bbs业务的两个集群节点
}
server {
listen 10.0.0.12:80;
server_name bbs.linuxidc.com;
location / {
proxy_pass ;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
server {
listen 10.0.0.13:80;
server_name blog.linuxidc.com;
location / {
proxy_pass ;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}
}
lb02