Search code examples
haproxy

Haporxy : redirect connection to 2nd server if server 1 down and ; to 3rd server when server 2 goes down;


I have layer 4 Haproxy setup with three servers configured as follows :

listen  db_rw
    bind *:3306
    log global
    mode tcp
    option tcpka
default-server port 9200 inter 2s downinter 5s rise 3 fall 2 slowstart 60s maxconn 1024 weight 100
    server server1 192.168.0.101:3306 check
    server server2 192.168.0.102:3306 check backup
    server server3 192.168.0.103:3306 check backup

Here always server1 is up since others are configured backup until server1 is down; But when server1 is down it will then send request to other two servers 2,3 when server1 is down;

My intension is that, when server 1 is down ; request should be forwarded to server2; when server 2 is down then send request to server 3 only; I am using listen ;

Could anyone tell me how to accomplish this sitation; I think using acl and *srv_is_up * could be possible;


Solution

  • I Think you have done it right already, have a look at this article : failover-and-worst-case-management-with-haproxy

    It seems as though it will only use 1 backup until it fails in turn. If you want to use both you need to specify option allbackups in backend