大网数据广告活动
服务器运维问答

HAProxy Does Not Recover After Failed Check

· 52CE 我爱测

All, I'm having an issue with HAProxy not recovering after a backend server is restarted. I'm not using the proxy for load balancing, but to direct different URLs to different servers (web and web services) to avoid cross-domain …

问题原文

原帖链接 · Michael Wooten · CC BY-SA 3.0

All,

I'm having an issue with HAProxy not recovering after a backend server is restarted. I'm not using the proxy for load balancing, but to direct different URLs to different servers (web and web services) to avoid cross-domain issues. The proxy works fine until the first check fails, but then HAProxy never resumes forwarding to it once it is back up. The proxy is running inside a docker container (https://registry.hub.docker.com/u/dockerfile/haproxy/dockerfile/) and it should be running 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

In the logs for HAProxy, I see the following error messages:

[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!

In the browser I see:

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

Once I restart the server, I never see a log message indicating that HAProxy has determined it has come back up and I still receive the 503 error in the browser, even though I can hit server1:8080 and see that the site is back up.

社区高分解答

原帖链接 · TheHandofTheKing · CC BY-SA 4.0

We had similar behavior. After running for a month or so the server would be marked as down and would not come back up.

By default HAProxy resolves any hostnames to IPs at startup. If the server changes IP address HAProxy does not resolve the DNS again until a restart. Specifically for us we are AWS and we where pointing at an ALB/ELB. After a month the ALB/ELB would change its IP (most likely some maintenance). At that point the IP is bad and will continue to fail.

The solution for us was to add a resolver to the HAProxy.cfg:

resolvers myresolver
  nameserver dns1 10.110.0.2:53
  resolve_retries       30
  timeout retry         1s
  hold valid           30s

server myserver <server_name>:443 maxconn 32 check ssl verify none resolvers myresolver

HApRoxy Documentation

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-02-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。