5

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?

1
  • @Santhosh should it not be =ROUTEID instead of =BALANCEID
    – Sprout
    Sep 10, 2015 at 13:46

2 Answers 2

4

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.

1
  • 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, 2010 at 6:39
3

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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .