我正在尝试为同一IP上的多个端口上运行的Jabber连接配置Haproxy v1.5.为了使配置尽可能简单,我想使用单个前端和一个或多个后端.有没有办法让我将源端口传递给后端或使用ACL根据端口路由到不同的后端?
frontend Jabber_IN bind 10.60.0.12:5222 name port5222 bind 10.60.0.12:5223 name port5223 bind 10.60.0.12:9090 name port9090 bind 10.60.0.12:9091 name port9091 bind 10.60.0.12:7070 name port7070 bind 10.60.0.12:7443 name port7443 bind 10.60.0.12:5229 name port5229 mode tcp option tcplog option tcpka timeout client 60m timeout server 60m timeout http-keep-alive 1m default_backend Jabber backend Jabber tcp-check connect tcp-check send PING\r\n tcp-check expect string +PONG server Server1ZoneD 10.60.30.209:80 check server Server1ZoneE 10.60.47.4:80 check server Server2ZoneD 10.60.17.8:80 check server Server2ZoneE 10.60.45.219:80 check
解决方法
确实可以使用单个前端和多路复用到后端.您将需要为每个后端服务器添加一个后端部分,例如:
backend JabberD1 tcp-check connect tcp-check send PING\r\n tcp-check expect string +PONG server Server1ZoneD 10.60.30.209:80 check backend JabberE1 tcp-check connect tcp-check send PING\r\n tcp-check expect string +PONG server Server1ZoneE 10.60.47.4:80 check
等等
在您的前端,像这样拆分流量
acl d1 dst_port 5222 use_backend JabberD1 if d1
等等