【问题标题】:HaProxy - group tcp and http hosts dependent of each otherHaProxy - 组 tcp 和 http 主机相互依赖
【发布时间】:2017-01-06 08:08:54
【问题描述】:
我有以下场景:
Haproxy 在我的两组服务器前面运行:
- 两个 http 服务器(主动/备份)
- 两个 tcp 服务器(主动/备份)
我现在想从活动端故障转移到任何活动服务发生故障的备份端(同时故障转移 HTTP 和 TCP)。
在 HAproxy 中有什么方法可以做到这一点吗?到目前为止,我只能根据协议故障切换到其中一个,但不能同时切换到两者。这些可以分组吗?
我想知道是否可以通过 ACL 和诸如 fe_conn 指令之类的东西来完成
【问题讨论】:
标签:
load-balancing
haproxy
high-availability
failover
【解决方案1】:
我认为 haproxy 的 nbsrv 在这里工作。如果您的 nbsrv 计数(健康实例的数量)低于任一池的所需数量,则将两个池切换到备份后端。否则,只需使用默认池。这是一个在 1.5.18 上验证的示例,但在新版本上应该可以正常工作:
defaults all
timeout connect 30s
timeout client 30s
timeout server 30s
mode http
# http frontend
frontend http *:80
# use the backup service if EITHER service is down
acl use_backup nbsrv(http_service) lt 1
acl use_backup nbsrv(tcp_service) lt 1
use_backend http_service_backup if use_backup
default_backend http_service
# tcp frontend
frontend tcp_10000 *:10000
mode tcp
# use the backup service if EITHER service is down
acl use_backup nbsrv(http_service) lt 1
acl use_backup nbsrv(tcp_service) lt 1
use_backend tcp_service_backup if use_backup
default_backend tcp_service
backend tcp_service
mode tcp
# main tcp instance here
# can also include backup server here with backup directive if desired
server tcp-service1 tcp-service1.local:10000 check
backend tcp_service_backup
mode tcp
# backup tcp instance here
server tcp-service2 tcp-service2.local:10000 check
backend http_service
# main http instance here
# can also include backup server here with backup directive if desired
server http-service1 http-service1.local:80 check
backend http_service_backup
# backup http instance here
server http-service2 http-service2.local:80 check
有关更多 nbsrv 详细信息,请参阅 https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#nbsrv。