我正在testing运行HAProxy作为Apache 2.2后面的专用负载均衡器,replace我们当前使用Apache负载均衡器的configuration。 在我们目前的Apache中,如果所有的后端(原始)服务器都closures了,Apache将会提供503服务不可用的消息。 与HAProxy我得到一个502坏的网关响应。
我在Apache中使用简单的反向代理重写规则
RewriteRule ^/(.*) http://127.0.0.1:8000/$1 [last,proxy]
在HAProxy我有以下(运行在默认的TCP模式)
defaults log global option tcp-smart-accept timeout connect 7s timeout client 60s timeout queue 120s timeout server 60s listen my_server 127.0.0.1:8000 balance leastconn server backend1 127.0.0.1:8001 check observe layer4 maxconn 2 server backend1 127.0.0.1:8001 check observe layer4 maxconn 2
当后端服务器closures时,直接testing连接到负载平衡器:
[root@dev ~]# wget http://127.0.0.1:8000/ test.html --2012-05-28 11:45:28-- http://127.0.0.1:8000/ Connecting to 127.0.0.1:8000... connected. HTTP request sent, awaiting response... No data received.
所以大概是这个事实,HAProxy接受连接,然后closures它。
在TCP模式下,haproxy不会发出任何状态码,所以唯一的剩余点就是apache。 我认为这只是因为haproxy接受然后closures连接,使Apache返回一个502,这是预期的。
所以你观察的行为是正确的。 无论如何,通常更好的工作在HTTP模式下。 我也build议你启用“选项httplog”,它将提供非常详细的日志,并select“http-server-close”来利用apache的能力来保持haproxy的活力,这将显着减less本地源端口的消耗在机器上。
我不能在tcp模式下工作,但如果你切换到http模式,那么你得到的503
defaults mode http