16

Let's say I have 2 servers - SA and SB. Is it possible to configure HAProxy to work like this:

All connections goes to SA -> SA goes down -> HAProxy switches all connections to SB -> until SB is not down - no connections go to SA, even if it is up again -> SB down -> HAProxy switches to SA...

In brief I would like HAProxy to switch only when current server goes down. Maybe I should use sth else than HAProxy?

2 Answers 2

28

Check out this config:

listen my-server 0.0.0.0:80
    balance roundrobin
    server web01 10.10.10.1:80 check inter 10s fall 3 rise 99999999
    server web02 10.10.10.2:80 check backup

All requests will hit web01 by default. web02 will not be used. If web01 stops responding, after 30s (3 checks at 10 seconds intervals) the server will be taken offline. web02 will be brought online and all requests will hit it.

If web01 recovers, it will only be brought back online once 99999999 checks at an interval of 10 seconds pass - which is effectively never.

4
  • That looks interesting. I'll try your and @Dennis solution. I also have to make some tests so I can get some results. Thank you.
    – Joe
    Feb 5, 2013 at 11:18
  • 1
    Is it possible to take web01 offline manually? Not shutting down web01 / killing its process, just mark it as down?
    – Limbo Peng
    Dec 10, 2014 at 13:53
  • FYI: inter defaults to 2s, fall defaults to 2, and rise defaults to 2. More can be found here: haproxy.org/download/1.5/doc/configuration.txt Sep 1, 2015 at 22:31
  • 7
    -1, solution stopped working after 31 years of uptime =P
    – Gaspa79
    Jul 17, 2017 at 16:32
7

If you have only two, and exactly two servers, it may make more sense to use a vip for the service that you manage via pacemaker/corosync to make it highly available.

It is possible with haproxy too, by marking SB as backup server. That way it's only used when SA is not available:

backend mybackend
mode            http
balance         roundrobin
option          httpchk /test.html
server          server1.example.com server1.example.com:80 weight 1 check port 80 inter 5s rise 3 fall 2
server          server2.example.com server2.example.com:80 backup weight 1 check port 80 inter 5s rise 3 fall 2

However, this does not accomplish part two of what you want: it will start using A SA again as soon as it's back. I'm not sure whether there's an option to make haproxy behave the way you want. I've at least never used it.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .