sca*_*a05 2 reverse-proxy load-balancing haproxy apache-2.2
我正在测试运行 HAProxy 作为 Apache 2.2 后面的专用负载均衡器,替换我们当前使用 Apache 负载均衡器的配置。在我们当前的 Apache 设置中,如果所有后端(源)服务器都关闭,Apache 将提供 503 服务不可用消息。使用 HAProxy,我得到 502 错误的网关响应。
我在 Apache 中使用了一个简单的反向代理重写规则
RewriteRule ^/(.*) http://127.0.0.1:8000/$1 [last,proxy]
Run Code Online (Sandbox Code Playgroud)
在 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
Run Code Online (Sandbox Code Playgroud)
在后端服务器关闭时测试直接连接到负载均衡器:
[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.
Run Code Online (Sandbox Code Playgroud)
所以大概这归结为 HAProxy 接受连接然后关闭它的事实。
在 TCP 模式下,haproxy 不会发出任何状态代码,因此唯一剩下的一点显然是 apache。我认为这仅仅是因为 haproxy 接受然后关闭使 apache 返回 502 的连接,这是预期的。
所以你观察到的行为是正确的。无论如何,在 HTTP 模式下工作通常会更好。我还建议您启用“option httplog”,它将为您提供非常详细的日志,并启用“option http-server-close”以利用 apache 与 haproxy 保持保持连接的能力,它将显着减少本地源端口消耗在机器上。
归档时间: |
|
查看次数: |
2453 次 |
最近记录: |