Hi,
I am in a situation where I have a backend with a main server A and a backup server B.
The intention is to have 100% of requests served by server A, and fallback to the server B if A is failing.
But I’d like to be able to switch the roles of the servers. Server B should them serve all the requests and the server A should become the backup i case of B failing.
I don’t want disable server A in HAproxy for it to use server B. because I still want the fallback to be possible.
I’ve found a weird option : having my 2 different configurations and a symlink to one of them to tell wich one HAProxy should use. But it forces me to reload the configuration each time I want to switch, and to maintain 2 different files.
I’ve search in the API and I’ve found my settings I can change (weight…) but nothing about the “backup” attribute of a server.
Also I didn’t find an algorithme which would do this automatically.
Anyone have an idea to solve this use case?
Hi Jeremy
There are a few options available, and you already mentioned a few of them:
- in the config file, use the
backup
keyword on the backup server and reload HAProxy
- play with server weight, this can be adjusted at runtime
- there is a LB algorithm whose name is
first
. It picks up the first available server in the backend. Just play with runtime api to trigger some other changes
- have a single server and use the runtime API to update the server’s IP address
- you can play with health check or agent check to report a server status that HAProxy can use to decide where to route the traffic
Hi Baptiste,
Thank you for your time and answer.
in the config file, use the backup keyword on the backup server and reload HAProxy
That’s already what I’m doing and I want to invert the “main”/“backup” statuses.
play with server weight, this can be adjusted at runtime
If I give 100% to one and 0% to the other, there is no fallback anymore, am I right ?
there is a LB algorithm whose name is first. It picks up the first available server in the backend. Just play
with runtime api to trigger some other changes
That is a lead. Thanks.
have a single server and use the runtime API to update the server’s IP address
I need to have a backup if the main one is faulty
you can play with health check or agent check to report a server status that HAProxy can use to decide where to route the traffic
same answer, I need to have a backup
If I give 100% to one and 0% to the other, there is no fallback anymore, am I right ?
yes you are correct. Just one thing, this will be applied to new connections. Established connections will keep on being established on the current server.