Hi, Le Lundi 31 Octobre 2011 17:21:02 Piavlo a écrit : > I have been using *capture cookie* and *appsession *in one haproxy > configuration for sticky sessions. > The problem is that then haproxy restarted/reload or domain is migrated > to failover server the sticky data is lost. > Today I realised that I don't need to use sticky sessions at all in > haproxy - what I do is setup custom session name > different in each backend http server based on it's name and then using > acl match on *hdr_beg(Cookie)* to direct to the correct backend > and if Cookie is not set then send it to round robin backend that has > all the http servers listed.
Is there any reason to use a different cookie name per server instead of using much standard behaviour of haproxy (using cookie insert and others) ? Your configuration would be a lot more simple and maintainable (see at the end). > Below is the relevant frontend & backend config. > It works great - but there is one problem. It's is very important that > the *maxconn* that is set in *server *will be set globally per real http > server > but since I now have same server http server listed twice. > For example for lb-srv1 web server there are *lb-srv1/lb-srv1* and > *testing_rr/lb-srv1* - it means the total maxconn for lb-srv1 is now x2 > larger. > I could split split the maxconn between lb-srv1/lb-srv1 and > testing_rr/lb-srv1 - so that in total it's 900 - but this will not use > the possible 900 slots > since there is no way to know that ratio of lb-srv1/lb-srv1 vs > testing_rr/lb-srv1 and it's highly dynamic. > > Is there some trick to share the same *maxconn* for lb-srv1/lb-srv1 > testing_rr/lb-srv1 > Or something similar to*track* - that would make *server* track other > *server*'s maxconn too? and not only health checks. No, or not yet. > afaiu the haproxy backends lb-srv1 & lb-srv1 cannot be load balanced > but only chosen based on acl or as default fallback? No. > ------------------------------------------------------------ > frontend testing 0.0.0.0:88 > mode http > maxconn 20000 > > option httplog > monitor-uri /up.html > > option http-server-close > option forwardfor > reqadd X-Forwarded-Proto:\ http > > acl acl-lb-srv1 hdr_beg(Cookie) lb-srv1= > acl acl-lb-srv1-up nbsrv(lb-srv1) 1 > > acl acl-lb-srv2 hdr_beg(Cookie) lb-srv2= > acl acl-lb-srv2-up nbsrv(lb-srv2) 1 > > use_backend lb-srv1 if acl-lb-srv1 acl-lb-srv1-up > use_backend lb-srv2 if acl-lb-srv2 acl-lb-srv2-up > default_backend testing_rr > > monitor fail if !acl-lb-srv1-up !acl-lb-srv2-up > > backend lb-srv1 > mode http > option httpchk /up.html > option abortonclose > > server lb-srv1 lb-srv1.private:82 maxconn 900 check > inter 2000 fall 3 > > backend lb-srv2 > mode http > option httpchk /up.html > option abortonclose > > server lb-srv2 lb-srv2.private:82 maxconn 900 check > inter 2000 fall 3 > > backend testing_rr > mode http > option httpchk /up.html > option abortonclose > > balance roundrobin > server lb-srv1 lb-srv1.private:82 maxconn 900 track > lb-srv1/lb-srv1 > server lb-srv2 lb-srv2.private:82 maxconn 900 track > lb-srv2/lb-srv2 > ----------------------------------------------------------- Proposed version (untested) : ------------------------------------------------------------ listen testing 0.0.0.0:88 mode http maxconn 20000 option httplog monitor-uri /up.html option abortonclose option http-server-close option forwardfor reqadd X-Forwarded-Proto:\ http acl acl-lb-down nbsrv 0 monitor fail if acl-lb-down cookie lb insert server lb-srv1 lb-srv1.private:82 maxconn 900 cookie srv1 check inter 2000 fall 3 server lb-srv2 lb-srv2.private:82 maxconn 900 cookie srv2 check inter 2000 fall 3 ----------------------------------------------------------- -- Cyril Bonté