0

i run haproxy 1.6 in our environment for different applications. Former we used a Cisco product. Haproxy has a lot of advantages but there is one thing i could not configure with haproxy or i do not know how to do it.

Lets assume i have a backend configured like this:

backend test_farm
    mode http
    option httplog
    balance leastconn
    cookie test_farm insert nocache
    option httpchk /test
    option allbackups
    timeout check 10s
    default-server inter 4s fall 15 rise 6
    server host1_server1 host1:24320 check cookie PZ22
    server host1_server2 host1:24350 check cookie PZ23
    server host1_server3 host1:22250 check cookie PZ24
    server host1_server4 host1:22280 check cookie PZ25
    server host1_server5 host1:22310 check cookie PZ26
    server host1_server6 host1:22340 check cookie PZ27

    server host2_server1 host2:24320 check cookie BZ22 backup
    server host2_server2 host2:24350 check cookie BZ23 backup
    server host2_server3 host2:22250 check cookie BZ24 backup
    server host2_server4 host2:22280 check cookie BZ25 backup
    server host2_server5 host2:22310 check cookie BZ26 backup
    server host2_server6 host2:22340 check cookie BZ27 backup

All servers have the same application installed. I have several backends with other applications. But each backend serves only one specific app and the number of servers vary. The user must stay at one server as long as it is possible to avoid a relogin. As you can see, i use cookie insertion to stick a user to its first connected server. The application is not capable of using session persistence over all servers.

Haproxy only uses the backup servers, wenn all normal servers are down, but i cannot wait until all servers are down. In this case maybe 4 servers can handle the load, but losing one more will struggle the remaining 3 servers. For several reasons i can't simply loadbalance over all servers on host1 and host2. The backup servers should be with no load under normal conditions. I read through the 1.8 version docu, but this one has not changed and i did not found any new functionality in that direction. On the cisco product you could configure, that, when server1 on host1 goes down, immediately use server1 on host2 in the roundrobin or leastconn algo.

And that is my question, how to configure this behaviour.

I thought/tried on some approaches:

  1. Use nbsrv in an acl and define two or more backend sections to the same servers and adding the backup ones: This one worked, but i lost the session affinity and so the users will be kicked out of the application and need to relogin again. And also i guess the more backends exist using the same servers there are more checks do process which has a load impact i want to avoid.

  2. Define the same config as above but do not use backup keyword. Instead i define a weight of 0 to the backup servers. Then use a script triggered by cron and determine via adminsocket how many servers are alive and increase the weight of the backup servers (also via adminsocket) if two or more normal servers are down. I did not test that one, yet. But you can imagine that this is also not a prefered way.

  3. Get my my very old C knowledge up to date and try to code this behaviour, but you know, i would prefer to stick to the versions provided by the developers who have the far better knowledge how to code.

I hope some have perhaps the same scenario and can give me a hint how to that with bord mediums. Of course i read through everything i found on google, but nothing was related to my scenario.

best regards, kaniggl

1

Would this work more as you expect/want?

The way it works: when the number of active servers on test_farm goes under 4, it switches completely to test_farm_backup.

Remember anyway that as soon as you bring 4 servers up on test_farm traffic will switch over.

frontend ft_test_farm
    bind 10.10.10.10:80
    # detect if we go under 4 active servers
    acl test_farm_overflow nbsrv(test_farm) le 4
    use_backend test_farm_backup if test_farm_overflow
    default_backend test_farm

backend test_farm
    mode http
    balance leastconn
    cookie test_farm insert nocache
    option httpchk /test
    timeout check 10s
    default-server inter 4s fall 15 rise 6
    server host1_server1 host1:24320 check cookie PZ22
    server host1_server2 host1:24350 check cookie PZ23
    server host1_server3 host1:22250 check cookie PZ24
    server host1_server4 host1:22280 check cookie PZ25
    server host1_server5 host1:22310 check cookie PZ26
    server host1_server6 host1:22340 check cookie PZ27

backend test_farm_backup
    mode http
    balance leastconn
    cookie test_farm insert nocache
    option httpchk /test
    timeout check 10s
    default-server inter 4s fall 15 rise 6
    server host2_server1 host2:24320 check cookie BZ22
    server host2_server2 host2:24350 check cookie BZ23
    server host2_server3 host2:22250 check cookie BZ24
    server host2_server4 host2:22280 check cookie BZ25
    server host2_server5 host2:22310 check cookie BZ26
    server host2_server6 host2:22340 check cookie BZ27
  • Hi, thank you for your answer. I was in vaction so sorry for the late response. This solution i found also in the web, but it does not satisfy "The user must stay at one server as long as it is possible to avoid a relogin.". Each time the nbrsrv is triggered (no matter if it goes below 4 or raises) all users will be disconnected from their servers and have to relogin. Perhaps better described, we want to achive that only the users of a failed server have to relogin and the others should continue working without interruption. – kaniggl Aug 7 '18 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.