检查失败后,HAProxy不会恢复

所有,

我遇到了HAProxy在后台服务器重新启动后无法恢复的问题。 我没有使用代理进行负载均衡,而是将不同的URL指向不同的服务器(Web和Web服务)以避免跨域问题。 该代理工作正常,直到第一次检查失败,但后来HAProxy从不恢复转发到它一旦它备份。 代理运行在Docker容器( https://registry.hub.docker.com/u/dockerfile/haproxy/dockerfile/ )中,它应该运行HAProxy 1.5.3。

haproxy.cfg

global log 127.0.0.1 local0 log 127.0.0.1 local1 notice user haproxy group haproxy defaults mode http log global option dontlognull option httpclose option httplog option forwardfor option persist option redispatch option http-server-close contimeout 5000 clitimeout 50000 srvtimeout 50000 maxconn 60000 retries 3 errorfile 400 /etc/haproxy/errors/400.http errorfile 403 /etc/haproxy/errors/403.http errorfile 408 /etc/haproxy/errors/408.http errorfile 500 /etc/haproxy/errors/500.http errorfile 502 /etc/haproxy/errors/502.http errorfile 503 /etc/haproxy/errors/503.http errorfile 504 /etc/haproxy/errors/504.http stats enable stats uri /haproxy-stats frontend http-in bind *:80 default_backend server1 acl url_server1 path_beg -i /server1 acl url_server2 path_beg -i /services/server2 use_backend server1 if url_server1 use_backend server2 if url_server2 backend server1 balance roundrobin option httpchk GET /server1/content/ server server1 server1:8080 check inter 10s rise 1 fall 5 backend server2 balance roundrobin option httpchk GET /services server server2 server2:8181 check inter 5s rise 1 

在HAProxy的日志中,我看到以下错误消息:

 [WARNING] 040/210248 (1) : Server server1/server1 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue. [ALERT] 040/210248 (1) : backend 'server1' has no server available! 

在浏览器中我看到:

 503 Service Unavailable No server is available to handle this request. 

一旦我重新启动服务器,我从来没有看到一条日志消息,指出HAProxy已经确定它已经恢复,我仍然收到在浏览器中的503错误,即使我可以打到server1:8080,并看到该网站备份。

我遇到了同样的问题,我的理解是HaProxy认为整个后端如果后端的所有服务器都closures了。 一旦后端被标记为down,它就不会恢复(这没有logging,我根据自己的经验得出了这个结论)。

由于您只有一台服务器,因此很可能在重新启动期间将服务器标记为closures。 如果您有多台服务器,这将是负载均衡器的正确行为。

我的解决scheme是增加检查和下降参数之间的间隔:

  • rise参数设置服务器必须通过检查的操作次数。 默认值是2。
  • fall参数设置服务器不能被声明为无效的检查次数。 缺省值是3。
  • inter参数设置这些检查之间的时间间隔。 缺省值是2000毫秒。

例如:

 server foo 1.2.3.4:80 check inter 5000 fall 5 rise 1 

我偶然发现了同样的问题,我认为这是devise。 HAProxy有一个财产负责这种行为 :

 fall <count> The "fall" parameter states that a server will be considered as dead after <count> consecutive unsuccessful health checks. This value defaults to 3 if unspecified. See also the "check", "inter" and "rise" parameters. 

我不知道如何恢复死亡的实例。 我甚至尝试过这个问题中提到的交互式控制台