nippo
nippo

Reputation: 134

How to write haproxy check on 2 different servers in the same time maybe with a lua script?

I have 2 servers (A and B) for the same backend with one as backup but these servers depend on 2 others servers (A' and B') to work, one for each server : server A can be used if server A is up AND if server A' is up, server B can be use if server B is up AND server B' is up.

For now, I can't tell to haproxy "use server A if server A is up AND if server A' is up" ?

Ex.:

backend foo
        option httpchk
        server A 10.99.98.97:8001 check inter 10s rise 2 fall 5
        server B 10.99.98.96:8001 check inter 10s rise 2 fall 5 backup

backend bar
        option httpchk
        server A' 10.99.98.95:8001 check inter 10s rise 2 fall 5
        server B' 10.99.98.94:8001 check inter 10s rise 2 fall 5 backup

If A' is down, I can't use anymore A but haproxy don't know this with theses tests (I don't really need backend bar, it just to show what is the problem)... For different reasons, I can't use a specific path to check server A' from A test :

backend foo
        option httpchk GET /url_on_A_which_checks_A'
        server A 10.99.98.97:8001 check inter 10s rise 2 fall 5..

I wonder if it's possible maybe with lua to test two different servers before considering a server is "up" ? I don't want to make the test for each incoming requests in a frontend section for example (performance issue)...

I imagine something like :

backend foo
        option lua.check
        server A 10.99.98.97:8001 lua.check inter 10s rise 2 fall 5..

With a request to port 8001 on A AND on A' in lua.check...

Sorry for my english,

Thanks

Upvotes: 1

Views: 2051

Answers (1)

mweiss
mweiss

Reputation: 1373

If you need to check multiple servers for your health check, there's a trick you can use using an external-check. The basic summary of the trick is to have an external check that then calls your haproxy stats socket and checks the health checks of servers on different backends.

Here's an example I wrote up that uses an external health check to check the status for all servers named the same. Note that there are two backends whose only purpose to do health checks, e.g. they're not connected to any frontend:

https://gist.github.com/mweiss/125ce3eaf1f511d103c229f4b0cb419c

For more information about external checks, see:

https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#option%20external-check


As an aside, if you can compromise and only have one health check for the server you're dependent on, you may want to use the track option. However, this doesn't solve your issue if you want to have multiple health checks.

Upvotes: 1

Related Questions