Switching the load balancing algorithm from round robin to the source algorithm (seems to be) an easy way to enable sticky-mode on your HAProxy load balancer.
The reason for this was simple. I installed HAProxy with a very basic configuration using a Round-Robin load balancing algorithm – the session variable was created on web server A while the user was one web server B and vice versa.
listen LoadBalancer 95.84.73.62:80
mode http
stats enable
balance roundrobin
option httpclose
option forwardfor
option httpchk HEAD /check.txt HTTP/1.0
server inst1 127.0.0.15:80 cookie ServerA check inter 2000 fall 3
server inst2 127.0.0.16:80 cookie ServerB check inter 2000 fall 3
capture cookie vgnvisitor= len 32
- Forms-Authentication
- Document-Editor
- The Captcha-Images for the Comment section
- etc.
But today, I finally took the time to read the HAProxy documentation.
And the solution to my problem seems quite easy and obvious:
listen LoadBalancer 95.84.73.62:80
mode http
stats enable
balance source
option httpclose
option forwardfor
option httpchk HEAD /check.txt HTTP/1.0
server inst1 127.0.0.15:80 cookie ServerA check inter 2000 fall 3
server inst2 127.0.0.16:80 cookie ServerB check inter 2000 fall 3
capture cookie vgnvisitor= len 32
Since I don't need "real" load balancing on my servers, I think this option will be just fine for me. But I am not sure if there is a better way to enable sticky-mode on your load-balancer.
I briefly tried using cookies, but it did not work for me. If you have any ideas on how to make the cookie solution work please drop me line.
Mahalo– Andreas Koch
sitemap.xml Enabling-Sticky-Mode-for-HAProxy.kml Enabling-Sticky-Mode-for-HAProxy.rss Enabling-Sticky-Mode-for-HAProxy.xml Enabling-Sticky-Mode-for-HAProxy.json Enabling-Sticky-Mode-for-HAProxy.print