tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sriram Narayanan" <>
Subject A Howto for Tomcat 6.0.9, mod_jk, apache 2.2 load balancing + session replication
Date Tue, 13 Feb 2007 15:27:01 GMT
Hi all:

I just got this working, so I thought of posting a small howto for the list :)


An apache instance (httpd) that serves http://localhost/examples/
where /examples is served by two Tomcat instances (if one is
down/unavailable, then httpd decides to redirect requests to the
second tomcat instances.

What I've got working so far:
- Session replication between the various Tomcat instances in the cluster.
- In case one instance is not available, then apache sends new
requests to the next instance.
- When and instance comes back, it joins the cluster, receives session
replication, and is ready to take over when required.

What else is possible:
- Load balance based on the number of requests already sent to a Tomcat instance
- Configure timeouts, etc
- More information at

What's not possible:
- If the first instance dies, then the second instance carries on
processing from that point.

To try this yourself:
1. Download and install Apache Tomcat 6.0.9

2. In server.xml, uncomment the tag for clustering

3. Edit the webapps/example/WEB-INF/web.xml to include the distributable tag

4. Create a copy of this Tomcat folder (say, Tomcat2)

5. Edit the server.xml in Tomcat2. Change all the port numbers. e.g.
change the AJP port number to 8010

6. Download the file
and save it as at apache/modules folder.

7. Place the following contents in the file apache/conf/
	# The advanced router LB worker
	  # Define a worker using ajp13
	  # Define prefered failover node for worker1
	  # Define another worker using ajp13
	  # Disable worker2 for all requests except failover
	  # Define the LB worker
	  # Define a 'jkstatus' worker using status

8. Edit apache/conf/httpd.conf to include the following:
LoadModule    jk_module  modules/

#AddModule     mod_jk.c

JkWorkersFile conf/

JkShmFile     mod_jk.shm
JkLogFile     mod_jk.log

JkLogLevel    info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

JkMount /jkmanager/* jkstatus

JkMount  /examples/* router

9. Start the two Tomcat instances
	You should see some replication related messages in the console

	Feb 13, 2007 8:01:34 PM org.apache.catalina.ha.tcp.SimpleTcpCluster memberAdded
	INFO: Replication member
	 alive=1016,id={99 34 -19 82 10 -107 64 51 -119 77 9 -117 -91 9 24 -9
}, payload
={}, command={}, domain={}, ]

INFO: Manager [localhost#/examples]; session state send at 2/13/07 8:01 PM recei
ved in 125 ms.

10. Restart the httpd web server

Testing the session replication
1. Browse to http://localhost/examples/

2. Try the Session examples for the servlet.

3. Set a variable into the session with a value

4. Stop the first Tomcat instance

5. Set another variable into the session.
	This time, the second Tomcat instance will serve the content
	You'll see that the first variable is still in the session. This is a
sign that replication has been successful.

6. Restart the first instance, wait for it to enter the cluster and
for the replication to happen
INFO: Manager [localhost#/examples]; session state send at 2/13/07 8:01 PM recei
ved in 125 ms.

7. Stop the second Tomcat instance.

8. Set another variable into the session.

9. You'll see that all the variables are still available.

-- Sriram

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message