Hi Thomas,

We do it like this, haproxy add a cookie, and base on the cookie it will
send it to teh same web server

I'm no haproxy expert but it work for us with a very basic php application.

here are the related config in our haproxy


backend bk-prod
        balance        roundrobin
        cookie          SERVERID insert indirect nocache
        server          lb10-3w-101 172.21.11.101:80 cookie lb11-3w-101
check inter 5s fall 3 maxconn 200 weight 20
        server          lb10-3w-102 172.21.11.102:80 cookie lb11-3w-102
check inter 5s fall 3 maxconn 200 weight 20


This will load balance in a round robin way but a second pass from the
same visitor will end up on the same server which will do what you want.

Good luck !



2011/3/11 Thomas Manson <[email protected]>

> Hi Gabriel,
>
>   I've read that HAProxy is capable of keeping a set of http request
> directed to the same webserver. (I think the feature is called 'Sticky
> Session' on Websphere Cluster)
>
>   I've seen this in the documentation :
>
> appsession <cookie> len <length> timeout <holdtime>
>>
>>
>>            [request-learn] [prefix] [mode <path-parameters|query-string>]
>>  * Define session stickiness on an existing application cookie.*
>>
>>
> I'm just looking for some howto/best practices on this subject.
>
> Also the shared session with memcache can be a valid option. (I've to dig
> this subject).
>
> So, can anyone confirm that it's possible or not possible to have a "sticky
> session" feature with HAProxy  ?
> If possible : howto/best practice?
> If not : well I'll try the memcache solution ;)
>
> Thanks for your help,
> Regards,
> Thomas.
>
>
>
>
> On Fri, Mar 11, 2011 at 16:19, Gabriel Sosa <[email protected]> wrote:
>
>> this is not an HAProxy related problem
>>
>> What you need is to share the session across all webservers. You have
>> several ways to do it: memcache, redis, db, filesystem.
>>
>> We currently are using memcache for this
>>
>> check your php.ini for "session.save_handler"
>>
>> we have something like:
>>
>> session.save_handler = memcache
>> session.save_path = "tcp://mmc-server-01:11211,tcp://mmc-server-02:11211"
>>
>> some more info: http://php.net/manual/en/session.configuration.php
>>
>> Once you do this, haproxy will keep using the same algorithm  to balance
>> but webservers will be able to find/reuse the session users were on.
>>
>> Saludos
>>
>>
>>
>> On Fri, Mar 11, 2011 at 11:37 AM, Thomas Manson <
>> [email protected]> wrote:
>>
>>> Hi,
>>>
>>>   I've setup HAProxy to loadbalance the traffic across two web servers
>>> that runs some PHP website (based on JOOMLA, OSCommerce and some other
>>> solution)
>>>
>>>   However I've noticed that the session affinity is not working Out Of
>>> The BOX (which after 2sec of think is quite logical ;))
>>>
>>>   Does anybody have some pointers to configure HAProxy (and if necessary
>>> PHP) to make this work ?
>>>
>>> Thanks,
>>> Thomas.
>>>
>>
>>
>>
>> --
>> Gabriel Sosa
>> Si buscas resultados distintos, no hagas siempre lo mismo. - Einstein
>>
>
>


-- 
Guillaume Bourque, B.Sc.,
consultant, infrastructures technologiques libres
Logisoft Technologies inc.  http://www.logisoftech.com
514 576-7638,  http://ca.linkedin.com/in/GuillaumeBourque/fr

Reply via email to