Load-Balancing and health checking
Health checking is the method to check a service availability on a server.
It is one of the most important feature of a load-balancer. How could we balance traffic amongst servers if we don’t know if the service is alive???
HAProxy and HTTP check
HAProxy can probe HTTP applications using httpchk option.
This option can be customized using the http-check expect directive to match different status codes or content.
That said, a single http-check expect rule can match.
So we can’t match a status code and the presence of a string in the page, for example.
Make HAProxy match multiple conditions for HTTP health checking
The solution is to use to the raw tcp-check and write a health check script sequence which match all the conditions.
For example, you want to ensure the server’s response has:
- HTTP status code is 200
- absence of keyword Error
tcp-check send GET /my/check/url HTTP/1.1rn
tcp-check send Host: myhostrn
tcp-check send Connection: closern
tcp-check send rn
tcp-check expect string HTTP/1.1 200 OK
tcp-check expect ! string Error