0

My task is to loadbalance web traffic among Apache Tomcat server instances via mod_jk.

I already have configured the load-balancing, but It does not keep the same session for same request, it redirects to another Tomcat server instance.

Stefan
  • 12,108
  • 5
  • 47
  • 66
Madura Dissanayake
  • 8,309
  • 5
  • 25
  • 34

1 Answers1

3

In your workers.properties set the sticky_session option to 1:

worker.list=balancer,lbstats

#node1
worker.node1.type=ajp13
worker.node1.host=127.0.0.1
worker.node1.port=8009
worker.node1.lbfactor=10

#node2
...

#lb config
worker.balancer.type=lb
worker.balancer.sticky_session=1

worker.balancer.balance_workers=node1,node2

#lb status information (optional)
worker.lbstats.type=status

Update

One reason could be that the session gets lost during requests. Make sure you did set the jvmRoute attribute in the engine element in server.xml:

<Engine jvmRoute="node1" defaultHost="localhost" name="Catalina">

The name must match the nodes name from workers.properites (see above). This name will be appended to your session ids. Make sure it does not change during requests.

Furthermore define a status worker as shown above, and map it to a url in your httpd.conf file:

JkMount /modjkstatus    lbstats

After that access http://yourdomain.xyz/modjkstatus to see further cluster and lb information.

Stefan
  • 12,108
  • 5
  • 47
  • 66
  • Hello Stefan, I have set the value of "worker.balancer.sticky_session" to 1 , but still not working. any oather method? – Madura Dissanayake Jul 31 '14 at 04:51
  • Hi Stefan, Thank you for the update, I did all the things that u hv mentioned, but if I added this line , the tomcat server instance is not started. If I commented that one, the instance is started. Any idea about this? – Madura Dissanayake Aug 04 '14 at 05:05
  • 2
    The line already exists in you Tomcats server.xml. You only need to add the jvmRoute="NAME" attribute. – Stefan Aug 04 '14 at 06:30