11

My current setup has 2 HAProxies configured with keepalived for High Availability, the 2 proxies serve as a Reverse Proxy and Load Balancer for virtual webservices. I know that HAProxy can check the health of its backend (I've already configured this) but my question is something else.

At my company there's a F5 Big-IP Load Balancer which serves as the first line of defense, it will redirect requests to my HAProxies when needed.

I need to know if there is a way to let my F5 Big-IP check the health of the HAProxies frontend, so when the proxies are booting no requests will be lost.

Thanks

user3145921
  • 139
  • 1
  • 1
  • 5

3 Answers3

14

There used to be a mode health option but in recent versions the easiest way is to use a monitor-uri on a given port:

listen health_check_http_url
    bind :8888
    mode http
    monitor-uri /healthz
    option      dontlognull

You can use the monitor-uri in a frontend and select it with an ACL too but the port version is much clear and straightforward.

https://cbonte.github.io/haproxy-dconv/1.6/configuration.html#4.2-mode

https://cbonte.github.io/haproxy-dconv/1.6/configuration.html#4.2-monitor-uri

Pau Ruŀlan Ferragut
  • 7,536
  • 2
  • 12
  • 5
4

From the HAProxy Reference Manual:

Health-checking mode
--------------------
This mode provides a way for external components to check the proxy's health.
It is meant to be used with intelligent load-balancers which can use send/expect
scripts to check for all of their servers' availability. This one simply accepts
the connection, returns the word 'OK' and closes it. If the 'option httpchk' is
set, then the reply will be 'HTTP/1.0 200 OK' with no data, so that it can be
tested from a tool which supports HTTP health-checks. To enable it, simply
specify 'health' as the working mode :

Example :
---------
    # simple response : 'OK'
    listen health_check 0.0.0.0:60000
        mode health

    # HTTP response : 'HTTP/1.0 200 OK'
    listen http_health_check 0.0.0.0:60001
        mode health
        option httpchk
guest666
  • 41
  • 1
  • In the more recent haproxy version `This mode is deprecated and should not be used anymore as it is possible to do the same and even better by combining TCP or HTTP modes with the "monitor" keyword.` http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#monitor – nelaaro Apr 01 '19 at 13:00
  • Is there an example of the newer "monitor" keyword style with a TCP listener - does not seem to be obvious in the docs (checking version 2.6). – tuck1s Aug 04 '22 at 14:46
1

From the HAProxy Docs

Example:
frontend www
    mode http
    acl site_dead nbsrv(dynamic) lt 2
    acl site_dead nbsrv(static)  lt 2
    monitor-uri   /site_alive
    monitor fail  if site_dead

Checkout the reference documentation.

http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4.2-monitor-uri

<uri>     is the exact URI which we want to intercept to return HAProxy's
          health status instead of forwarding the request.

When an HTTP request referencing <uri> will be received on a frontend,
HAProxy will not forward it nor log it, but instead will return either
"HTTP/1.0 200 OK" or "HTTP/1.0 503 Service unavailable", depending on failure
conditions defined with "monitor fail". This is normally enough for any
front-end HTTP probe to detect that the service is UP and running without
forwarding the request to a backend server. Note that the HTTP method, the
version and all headers are ignored, but the request must at least be valid
at the HTTP level. This keyword may only be used with an HTTP-mode frontend.

Monitor requests are processed very early. It is not possible to block nor
divert them using ACLs. They cannot be logged either, and it is the intended
purpose. They are only used to report HAProxy's health to an upper component,
nothing more. However, it is possible to add any number of conditions using
"monitor fail" and ACLs so that the result can be adjusted to whatever check
can be imagined (most often the number of available servers in a backend).
nelaaro
  • 3,006
  • 5
  • 38
  • 56