Reputation: 365
I have three servers(MariaDB services) and one HAProxy server on front of them and the HAProxy distributes connections to these servers with roundrobin. But I want that the HAProxy server must route all connections to server1. If server1 is unreachable, it must route to the server2.. Is there any load balancing algorithm that makes it possible?
Upvotes: 1
Views: 1621
Reputation: 26925
What probably you are looking for is for a failover/backup configuration, check more details here (https://www.haproxy.com/blog/failover-and-worst-case-management-with-haproxy/), this is a basic example:
backend mysql
mode tcp
balance leastconn
server s1 10.0.0.1:3306 check
server s2 10.0.0.2:3306 check backup
server s3 10.0.0.3:3306 check backup
From the HAProxy docs:
backup
When "backup" is present on a server line, the server is only used in load balancing when all other non-backup servers are unavailable. Requests coming with a persistence cookie referencing the server will always be served though. By default, only the first operational backup server is used, unless the "allbackups" option is set in the backend. See also the "no-backup" and "allbackups" options.
In case your servers belong to a galera cluster something you could try httpwsrep:
backend mysql
mode tcp
option httpchk
default-server check port 9200
server s1 10.0.0.1:3306
server s2 10.0.0.2:3306
server s3 10.0.0.3:3306
Upvotes: 3