I want do like this,look my haproxy:
backend app
balance roundrobin
cookie ha_gray_cookie insert indirect nocache
server app1 127.0.0.1:5001 cookie 110 check
server app2 127.0.0.1:5002 cookie 110 check
server app3 127.0.0.1:5003 cookie 110 check
server app4 127.0.0.1:5004 cookie 120 check
server app5 127.0.0.1:5005 cookie 120 check
server app6 127.0.0.1:5006 cookie 120 check
server app7 127.0.0.1:5007 cookie 120 check
server app8 127.0.0.1:5008 cookie 120 check
server app9 127.0.0.1:5009 cookie 120 check
when users come to here,this has 3/9 chance to visit the new versions(5001 5002 5003) and 6/9 chance to visit the old versions.
above config has some problems, namely that when I set cookie to 110, and then client always visits app1, when I set cookie to 120 then client always visits app4.
I want do this: If I set cookie to 110, client can visit all 3 servers (5001,5002,5003) by roundrobin
The cookie keyword is for stickiness to a particular server, so haproxy won't fall back to round robin like you expect.
Instead, you can create two backends, one with your 110 servers and another with your 120 servers. Use an ACL to direct traffic to either backend based on cookie. Something like this:
frontend cookie_balancer
bind :80
mode http
acl is_110 hdr(Cookie) 110
acl is_120 hdr(Cookie) 120
use_backend backend_110 if is_110
use_backend backend_120 if is_120
default_backend backend_110
backend backend_110
balance roundrobin
server app1 127.0.0.1:5001 check
server app2 127.0.0.1:5002 check
server app3 127.0.0.1:5003 check
backend backend_120
balance roundrobin
server app4 127.0.0.1:5004 check
# ...
See:
Using ACLs documentation.
hdr, hdr_sub, or hdr_beg documentation, which you can use to check for a particular cookie and direct traffic accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With