Tomcat unicast cluster configuration example

We have two Amazon EC2 instances running Apache Tomcat

Tomcat Node 1: IP: 192.168.0.50
Tomcat Node 2: IP: 192.168.0.51

Basic cluster configuration was set up from Tomcat’s documentation [http://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html] and working fine on local test environment.

But Amazon AWS doesn’t support multicast traffic and there is no documentation how to set up unicast cluster.
Here is example config of unicast cluster.

Set JvmRoute in Server.xml file of tomcat. Add “node1” in tomcat node 1 and “node2” in tomcat node2.
In production environment I use EC2 instance id

<Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”node1“>

Add in web.xml file in both tomcat nodes.

<distributable/>
</web-app>

Example cluster configuration based on Tomcat’s doc.

 <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">

 <Channel className="org.apache.catalina.tribes.group.GroupChannel">

 <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
 <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
 </Sender>

 <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
 address="auto"
 port="4000"
 autoBind="100"
 selectorTimeout="5000"
 maxThreads="6"/>

 <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">

 <Member className="org.apache.catalina.tribes.membership.StaticMember"
 host="10.0.1.51"
 port="4000"
 uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,51}"/>

 </Interceptor>

 <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor" staticOnly="true"/>
 <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
 <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>

 </Channel>

 <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter="" />
 <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" />
 <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener" />
 <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />

 </Cluster>

You can add as many cluster members as you need – just add another record to StaticMembershipInterceptor:.
Port value should match port in NioReceiver of remoute node. Also – do not forget to change uniqueId too.

<Member className="org.apache.catalina.tribes.membership.StaticMember"
host="192.168.0.52"
port="4000"
uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,52}"/>

Залишити відповідь

Ваша e-mail адреса не оприлюднюватиметься.