1

We've 2 active hosts for load balancing using haproxy. Haproxy is running on both the hosts. Due to maintenance we need to stop services on Host 1. During the maintenance window we want haproxy instance to stop sending traffic to host 1 and send all requests to Host 2.

Purpose: No outage during server maintenance.

Current behaviour: When service goes down on Host 1. Traffic is still sent to both Host 1 and 2. Since the backend services are down on Host 1, request times out and it is then Haproxy stops sending requests to Host 1. After the event of first failure all traffic if being sent to Host 2 and processed normally.

Is there a way to avoid losing this 1 transaction ( the first failure on Host 1) ? I read about enabling and disabling backend servers using socket file which needs socat or netcat. Haven't tested it but looking solution with haproxy configuration to resolve this.

Backend definition in haproxy config

backend myBackend
   balance leastconn
   option httpchk HEAD /
   default-server inter 5s fastinter 1s downinter 10s fall 2 rise 2
   timeout server 20s
   server s1 ActiveHost1:port check  maxconn 10
   server s2 ActiveHost2:port check  maxconn 10
   server s3 standByHost1:port check  maxconn 10  backup
   server s4 standByHost1:port check  maxconn 10  backup
0

Does commenting the line and reload haproxy would be ok for you?

sed -i \"/server s1/c\\ #server s1 ActiveHost1:port check maxconn 10\" /etc/haproxy/haproxy.cfg && sudo service haproxy reload

  • off course updating the haproxy config to remove the balanced node under maintenance will work. However it won't be a simple sed replace in my case as the config contains multiple balanced node where each node have multiple backends and all running on different port. Still I can write a script to do that. However I was looking for some out of box configuration in haproxy to do that. I read about http-check disable-on-404 , httpchk and check but not completely understand how they can be used to acheive this. – Abhishek Feb 11 at 23:48
  • But this definitely is an option if I don't get any out of box solution :) .. thanks again – Abhishek Feb 12 at 4:36
0

You can also decrease the time when a host is considered as DOWN by defining the service checking option. According to the documentation, for example for a HTTP service:

  • Define the service to check

  • Define what to expect as result

  • Define when a host is down - Here check every 3s. After 3 failed attemps, host is considered as DOWN. When 2 checks have the expected status, the host is considered as UP

  • Define your hosts

option httpchk GET /check http-check expect status 200 default-server inter 3s fall 3 rise 2 server srv1 10.0.0.1:80 check server srv2 10.0.0.2:80 check

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.