tomcat-cluster
Other information
http://examples.javacodegeeks.com/enterprise-java/tomcat/tomcat-clustering-session-replication-tutorial/
http://www.datadisk.co.uk/html_docs/java_app/tomcat6/tomcat6_clustering.htm
https://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html
How can we set up session replication for a static cluster?
This involves 3 steps.
In this example, we have two servers (192.168.91.88, and 192.168.91.89). The server.xml file on 192.168.91.88 contains:
<Cluster
channelSendOptions="8"
channelStartOptions="3"
className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
<Manager
className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"
/>
<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
address="192.168.91.88"
autoBind="0"
className="org.apache.catalina.tribes.transport.nio.NioReceiver"
maxThreads="6"
port="4100"
selectorTimeout="5000"
/>
<!-- <Interceptor className="com.dm.tomcat.interceptor.DisableMulticastInterceptor" /> -->
<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.StaticMembershipInterceptor">
<Member
className="org.apache.catalina.tribes.membership.StaticMember"
port="4100"
host="192.168.91.89"
uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2}"
/>
</Interceptor>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
</Channel>
<Valve
className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"
/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>
And the server.xml file on 192.168.91.89 contains:
<Cluster
channelSendOptions="8"
channelStartOptions="3"
className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
<Manager
className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"
/>
<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
address="192.168.91.89"
autoBind="0"
className="org.apache.catalina.tribes.transport.nio.NioReceiver"
maxThreads="6"
port="4100"
selectorTimeout="5000"
/>
<!-- <Interceptor className="com.dm.tomcat.interceptor.DisableMulticastInterceptor" /> -->
<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.StaticMembershipInterceptor">
<Member
className="org.apache.catalina.tribes.membership.StaticMember"
port="4100"
host="192.168.91.88"
uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}"
/>
</Interceptor>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
</Channel>
<Valve
className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"
/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>
Make sure that port 4100 is not blocked by a Firewall. On the server itself, use netstat -an to check to see which ports are listening. From outside, just telnet host port (or telnet host:port on Unix systems) to see if the connection is refused, accepted, or timeouts. In general:
- connection refused means that nothing is running on that port
- accepted means that something is running on that port
- timeout means that a firewall is blocking access
And add <distributable/> to web.xml such that it is direct descendant of the root web-app node:
<distributable/>
</web-app>
How can we determine if session replication is working?
Stop Tomcat. Go to its log folder, and delete all existing log files or move them to a separate folder. Start Tomcat. Go to the log folder, and look at the catalina or tomcat6-stderr log file. It should contains:
WARNING: Member added, even though we werent notified:org.apache.catalina.tribes.membership.MemberImpl[tcp://192.168.91.89:4100,192.168.91.89,4100, alive=0,id={0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 }, payload={}, command={}, domain={}, ]
Mar 26, 2015 6:42:35 PM org.apache.catalina.ha.tcp.SimpleTcpCluster memberAdded
INFO: Replication member added:org.apache.catalina.tribes.membership.MemberImpl[tcp://192.168.91.89:4100,192.168.91.89,4100, alive=0,id={0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 }, payload={}, command={}, domain={}, ]
INFO: Starting clustering manager at /...
Nov 12, 2015 3:57:07 PM org.apache.catalina.ha.session.DeltaManager getAllClusterSessions
WARNING: Manager [localhost#/...], requesting session state from org.apache.catalina.tribes.membership.MemberImpl[tcp://192.168.210.81:4100,192.168.210.81,4100, alive=0,id={0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }, payload={}, command={}, domain={}, ]. This operation will timeout if no session state has been received within 60 seconds.
Nov 12, 2015 3:57:07 PM org.apache.catalina.ha.session.DeltaManager waitForSendAllSessions
INFO: Manager [localhost#/MicroStrategy]; session state send at 11/12/15 3:57 PM received in 265 ms.