1.Keepalived单实例主备模式集群方案
这是最简单的模式,不只考虑高可用集群,先不考虑后方的Nginx负载均衡集群,即后端的服务器集群,参考下面的图示:
其对应的Keepalived核心配置如下:
lb01
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id lb01 # 用来标识一个Keepalived高可用集群中的一个节点服务器,因此是唯一的
}
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
}
}
lb02
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
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
}
}
2.Nginx负载均衡集群配合Keepalived单实例主备模式集群方案
在1的基础上,同时考虑后端的Nginx负载均衡集群,参考下面的图示:
其对应的Keepalived和Nginx配置如下:
lb01
Keepalive配置:
[email protected]
[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 {
10.0.0.12/24 dev eth0 label eth0:1
}
}
Nginx配置:
lb02
Keepalived配置:
[email protected]
[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 {
10.0.0.12/24 dev eth0 label eth0:1
}
}
Nginx配置:
3.Keepalived双实例双主模式集群方案
参考下面图示:
其对应的Keepalive核心配置如下:
lb01
global_defs {
notification_email {
[email protected]
[email protected]
[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 {
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 {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
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
}
}
然后在每个高可用集群节点中,为两个不同的业务分别配置两个不同的upstream服务器池,从而实现前端反向代理高可用和负载均衡,高可用集群后端的服务器池在不同的业务中也能提供负载均衡。
结合上面的分析,就可以得到Nginx负载均衡配合Keepalived双实例双主模式的场景了。
4.Nginx负载均衡集群配合Keepalived双实例双主模式集群方案
根据3的分析结果,参考下面的图示,注意下面这个图中的Keepalive配置与3的是一样的:
对应Nginx的配置如下:
lb01
lb02
可以看到,两台负载均衡器的Nginx配置是一样的。