Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I really have no idea...

I have a java web application which stores the session id in URL rather than using cookies. I want to run the application on 2 tomcat servers and fronting them with an Apache server for load balancing.


            __ tomcat1
Apache ----/
           \__ tomcat2

By setting the jvmRoute to tomcat1in the Tomcat server.xml file, the url will become http://url;jsessionid=id.tomcat1. So it is possible to achieve session stickyness by looking at the url, and route it to the corresponding server.

I know that mod_proxy and mod_jk and do the load balancing, but their sticky session only work when the session id is stored in cookies. In my case, the session id is encoded in the URL. How can I do the load balancing?

share|improve this question

2 Answers 2

Maybe your configuration is wrong. Documentation is not specified sticky-session working only cookies.

stickysession - Balancer sticky session name. The value is usually set to something like JSESSIONID or PHPSESSIONID, and it depends on the backend application server that support sessions. If the backend application server uses different name for cookies and url encoded id (like servlet containers) use | to to separate them. The first part is for the cookie the second for the path.

So you can specify the sessionid like below.

ProxyPass / balancer://mycluster/ stickysession=|jsessionid

Hope this helps.

share|improve this answer
    
Thx for your help. But we find that the dynamic resources generated by the app does not contains session IDs in their URL. So we are forced to use cookies to store session id. –  KK Lo Jul 11 '10 at 6:39

For creating the sticky we need to add the following line in your configuration(mod_proxy)

Header add Set-Cookie "BALANCEID=hej.%{BALANCER_WORKER_ROUTE}e; path=/;" env=BALANCER_ROUTE_CHANGED

Then specify the route name in the config

<Proxy balancer://mycluster>
    BalancerMember http://tomcat sever1.ip:8080  route=AcZxv
    BalancerMember http://tomcat server2.ip:8080 route=AcXxv
    lbmethod=byrequests stickysession=BALANCEID
</Proxy>

And add these routenames to tcserver.node in catalina.properties of tomcat servers

tcserver.node=AcZxv (tomcat 1st server)
tcserver.node=AcXxv (tomcat 2nd server)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.