Chapter 20 Clustering
To enable clustering, simply add the following code in the <Engine> or <Host> element:
Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
The configuration enables all-to-all session replication using the DeltaManager to replicate session deltas. All sessions are replicated to all other nodes in the cluster.
The following lists some important default values:
- Multicast address – 228.0.04
- Multicast port – 45564
- IP broadcasted –
java.net.InetAddress.getLocalHost().getHostAddress()
- Server Socket 4000-4100 – TCP port listening for replication messages
- Configured Listeners –
ClusterSessionListenerandJvmRouteSessionIDBinderListener
- Configured Interceptors –
TcpFailureDetectorandMessageDispatch15Interceptor
To run session replication in Tomcat 6, follow these steps:
1.Ensure that all session attributes implement java.io.Serializable.
2.Remove the comment of the Cluster element in server.xml.
3.Define custom cluster valves and the ReplicationValve under the Cluster element in server.xml.
4.If the Tomcat instances run on the same machine, ensure that the tcpListenPort attribute is unique for each instance.
In most cases, Tomcat resolves this issue by auto-detecting available ports in the range 4000-4100.
5.Make sure that the web.xml includes the <distributable> element. You may also set <Context distributable> to “true”.
6.When using mod_jk, ensure that jvmRoute attribute is set at the Engine <Engine name="Catalina" jvmRoute="node01" > and that the jvmRoute attribute value matches your worker name in workers.properties.
7.Configure the nodes to have the same time and sync with NTP service.
8.Configure the load balancer for sticky session mode.


