I'm trying to make sure that when a server goes up after being down (and not active any more) it will be re-enabled automatically.

This is my haproxy.cfg:

    log local0
    log local1 notice
    chroot /var/lib/haproxy
    user haproxy
    group haproxy
    # daemon

    log global
    mode tcp
    #retries 3
    option tcplog
    option dontlognull
    option redispatch
    no option persist
    #balance roundrobin
    balance leastconn
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms
    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

listen stats       #Listen on all IP's on port 9000
    mode http
    timeout client 5000
    timeout connect 4000
    timeout server 30000

    #This is the virtual URL to access the stats page
    stats uri /haproxy_stats

    #Authentication realm. This can be set to anything. Escape space characters with a backslash.
    stats realm HAProxy\ Statistics

    #The user/pass you want to use. Change this password!
    stats auth admin:adminpassword

    #This allows you to take down and bring up back end servers.
    #This will produce an error on older versions of HAProxy.
    stats admin if TRUE

frontend www-http
    bind *:80
    # detect capacity issues in production farm
    acl MAIN_not_enough_capacity nbsrv(www-unsecure-backend-proxy) le 2
    # failover traffic to backup farm
    use_backend www-unsecure-backend-direct if MAIN_not_enough_capacity
    default_backend www-unsecure-backend-proxy

backend www-unsecure-backend-proxy
    mode tcp
    server rproxycache01 rpcache01.container:80 check
    server rproxycache02 rpcache02.container:80 check

backend www-unsecure-backend-direct
    option allbackups
    server rproxycache01 rpcache01.container:80 check
    server rproxycache02 rpcache02.container:80 check
    server frontend01    web01.container:80 check backup
    server frontend02    web02.container:80 check backup

so, let's say all the servers are down, whenever one goes back up it should be used, but I've checked in the web interface and all the servers are red.

How can I do it?

Thank you in advance.

  • Have you encountered this problem again? I once hit a problem that brought me to this question but I later found out that the backend server had actually shut down Apache for some reason. I guess that in that case it was some kind of misconfiguration that caused systemd to bring apache down instead of restarting it. Try to connect from proxy to backend port with e.g. nc and see if it's really available. In my case that failed even though I tought the backend was alive. – Mikko Rantalainen Mar 20 at 6:19

I'd say that global setting retries 3 is causing problems for you. After 3 retries, HAProxy will give up on further checks. See the documentation for retries directive.

Since you didn't set inter value, HAProxy will check server availability every 2 seconds. If your server was unavailable for more than 6 seconds, HAProxy will consider it permanently down.

I'd suggest that you comment out retries 3 line (or set bigger value) and/or adjust check inter value, restart HAProxy and redo the tests.

| improve this answer | |
  • this is still not working, I tried to shut a server down and restart it but it is still down for HA. Also what should I do if HAProxy will consider the server permanently down? I'm trying to avoid to do any manual action. – Fabio Cicerchia Nov 21 '15 at 21:53
  • Can you update your haproxy configuration in the question, so that we can get clearer picture what did you exactly modify? Also, if you restart haproxy, does the backed server appear as available? – Tubeless Nov 21 '15 at 22:10
  • done, I've just commented out retries. – Fabio Cicerchia Nov 22 '15 at 10:56
  • 1
    I've took your haproxy.cfg and changed only server hostnames and ports. I left all other options as-is. Whenever I shut down one of the backend servers, HAProxy recognized it as DOWN, and whenever I brought the backend server online, HAProxy recognized it as UP. I tested with HAProxy 1.5.4. The configuration itself looks good, so I'd suggest that you try running HAProxy in debug mode without forking while you start/stop backend servers (e.g. haproxy -f /etc/haproxy/haproxy.cfg -d). – Tubeless Nov 22 '15 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.