Dear HAProxy Community!
Please, help me solve the problem.
There are 2 boxes running 2 identical services: service-A
and service-B
. With backend clients
if the client connects to the service-A
on the box1
, then his connection to the service-B
should also come to box1
.
The difficulty is: if the service-A
has failed on the box1
, then no client should be able to connect to any services on the box1
. So, if any of the services goes down, then the entire box should not be balanced. I can’t figure out how to do this.
backend clients
stick-table type ip size 10k expire 45m
listen service-A
bind 0.0.0.0:81
mode tcp
stick on src table clients
server box1 10.20.0.1:8081 check
server box2 10.20.0.2:8081 check
listen service-B
bind 0.0.0.0:82
mode tcp
stick on src table clients
server box1 10.20.0.1:8082 check
server box2 10.20.0.2:8082 check
Thanks in advance!
With track you can use the health-check of a server in another backend.
However it doesn’t work both ways, you can’t combine the two. When you use track, you are no longer checking health locally.
listen service-b
bind 0.0.0.0:82
mode tcp
stick on src table clients
server box1 10.20.0.1:8082 track service-a/box1
server box2 10.20.0.2:8082 track service-a/box2
But this will disable all health-checks to port 8082.
Do you need to health-check both services? I do not think we can achieve this with, we can’t health-check multiple ports afaik.
Thank You for quick response! I do, I need health-check for every service. May be with ACL I could achive desired behaviour?
Actually I was wrong, you can health-check multiple ports with tcp-check connect:
# check both POP and IMAP from a single server:
option tcp-check
tcp-check connect port 110 linger
tcp-check expect string +OK\ POP3\ ready
tcp-check connect port 143
tcp-check expect string *\ OK\ IMAP4\ ready
server mail 10.0.0.1 check
If you want to avoid double health check traffic, you could health check in only one backend, and track the server status from the other one (see above).
1 Like
Wow! HAProxy is absolutely AWESOME!
Thank You, dear @lukastribus, it’s working as desired!
backend clients
stick-table type ip size 10k expire 45m
backend healthcheck
option tcp-check
tcp-check connect port 8081
tcp-check send GET\ /\ HTTP/1.0\r\nHost:\ localhost\r\n\r\n
tcp-check expect string HTTP/1.0\ 200\ OK
tcp-check connect port 8082
tcp-check send GET\ /\ HTTP/1.0\r\nHost:\ localhost\r\n\r\n
tcp-check expect string HTTP/1.0\ 200\ OK
default-server check inter 30s fall 2 rise 2
server box1 10.20.0.1 check
server box2 10.20.0.2 check
listen service-A
bind 0.0.0.0:81
mode tcp
stick on src table clients
server box1 10.20.0.1:8081 track healthchecks/box1
server box2 10.20.0.2:8081 track healthchecks/box2
listen service-B
bind 0.0.0.0:82
mode tcp
stick on src table clients
server box1 10.20.0.1:8082 track healthchecks/box1
server box2 10.20.0.2:8082 track healthchecks/box2
2 Likes