Sunday, February 11, 2007

Apache Tomcat Clustering

Apache Tomcat is a web-server, meaning it complies to JSP and Java-servlets spec given by Java. It is possible to cluster such servers and do load balancing on them. When i tried to do it, i hardly found any relevant help on it, now that i could get the clustering done, i thought thought that i would share this so that a new person can save a lot of time.

In discovering this approach the zip file provided by erricson @ http://www.ericsson.com/mobilityworld/sub/signup/login.html?oid=36443
was very helpful. I rec0mmend you get the download. It would speak about clustering all the tomcats under one umbrella of apache.

scenario 1:

But what if you want multiple clusters under one apache. For this you will have to proceed as follows.
1. Under /apache2.0/conf/workers.prop file: retain only the 'load balancer' parameter.
2. Say you have 4 workers (i.e. 4 tomcats, machine1.. machine 4) and you want machine1, machine2 into cluster a, and machine 3 & machine4 into cluster B then make the following changes in the workers.prop file
a. enter: worker.machine1.domain=A
worker.machine2.domain=A
worker.machine3.domain=B
worker.machine4.domain=D


Scenario 2:

Supposing that you need the request to be always server to the same server which served the first request from the browzer then:
../conf/workers.properties : make worker.loadbalancer.sticky_session=true


With scenario 1 + scenario2 done, you have achieved fail save mechanism. i.e. if the server of a cluster fails, then the neighboring servers of the same cluster take care of the request.


my state:
Right now i could make 1-cluster & a stand-alone tomcat servers, under one apache HTTP server. I shall update the site in-case i get any issues & how to rectify them.