Active/Passive Configuration for Multiple Backends

First of all congratulations for having a great open source community. So by using the backup keyword, we can configure the HAProxy to shift to the backup server (or servers) in case all the primary servers are down. But I couldn’t find a config example where I have 2 backends with 2 backups:

server1 1.1.1.1:8080 check
server1 2.2.2.2:8080 check backup
server1 3.3.3.3:8080 check
server1 4.4.4.4:8080 check backup

I want to shift to 2.2.2.2 in case 1.1.1.1 is down. Also I want to shift to 4.4.4.4 in case 3.3.3.3 is down. Configuration manual says (and in my testing) the HAProxy only shifts to the backup servers once both 1.1.1.1 and 3.3.3.3 are down. Is there anyway I can configure the backup servers separately for each server? I my description is clear.

Thank you very much.

No, it isn’t possible (and I don’t see how it makes sense).

Please explain the entire use-case and configuration so that we can understand what you are trying to achieve and make a suggestion.

Thank you for the response and let me clarify.

So HAProxy only shifts to the backup servers once all the primary servers are down. In our setup, we have two backend primary servers serving API stateless requests. However, during the course of operation, one or both servers become unavailable due to a driver crash. What we want is that we setup HAProxy in such a way that if one of the primary servers are down, the backup server takes over in its place.

This is the configuration:
frontend api_frontend_8080
bind 0.0.0.0:8080
default_backend api_backend_8080

backend api_backend_8080
balance roundrobin
option forwardfor
server S1 10.1.1.1:8080 check port 8080 inter 5s
server S2 10.1.1.2:8080 check port 8080 inter 5s backup
server S3 10.1.1.3:8080 check port 8080 inter 5s
server S4 10.1.1.4:8080 check port 8080 inter 5s backup

S2 is the backup of S1 so if S1 is unavailable, S2 should serve the API requests. It should not be dependent on the availability of S3. Right now, S2 will only server contents once both S1 and S3 is down.

Thanks once again Lukas for your time and help.

I would suggest Chaining

create 2 backends

backend api_backend_8081
balance roundrobin
option forwardfor
server S1 10.1.1.1:8080 check port 8080 inter 5s
server S2 10.1.1.2:8080 check port 8080 inter 5s backup

backend api_backend_8082
balance roundrobin
option forwardfor
server S3 10.1.1.3:8080 check port 8080 inter 5s
server S4 10.1.1.4:8080 check port 8080 inter 5s backup

then create a backend to talk those backends

backend api_backend_8080
balance roundrobin
option forwardfor
server S3 127.0.0.1:8081 check port 8081 inter 5s
server S4 127.0.0.1:8082 check port 8082 inter 5s

1 Like