How to Setup a Tomcat Cluster?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux
    • 7.x, 6.x
  • Tomcat
    • 7.x, 6.x

Issue

  • Need to have a detailed set of instructions for setting up a Tomcat 6 cluster.
  • We are trying to do tomcat 7 clustering in our new datacenter and seeing issues related to multicast setup.

Resolution

EWS/JWS

As referenced in Is Tomcat Clustering Supported? :
Red Hat has no plans to support Tomcat clustering at this time because it is not deemed to be enterprise ready. Tomcat clustering is NOT supported with the EWS/JWS Tomcat distributions

RHEL

  • Tomcat 7: Tomcat clustering is not supported
  • Tomcat 6: Supported with caveats below
RHEL Tomcat 6 clustering caveats
  • Clustering is only supported with Red Hat Enterprise Linux Entitlements.
  • Requires two physically separated machines or VMs - each with the tomcat6 rpm installed.
  • Only one tomcat instance per machine is supported when setting up a tomcat cluster. Though it is possible to run multiple instance, this is NOT supported unless you have EWS entitlements.

Content from tomcat.apache.org is not included.Tomcat clustering is not much use without being properly fronted with a Load Balancer to distribute requests from a single point of origin.
Load Balancer options:

  • mod_jk, - requires EWS or JWS or EAP Entitlements for support
  • mod_proxy - available with RHEL entitlements

Given the above caveats/limitations, Red Hat does not recommend clustering with Tomcat 6, but will support the provided configuration in scenarios where the components are packaged and shipped to customers.
Instead Red Hat recommends, usage of Content from www.jboss.com is not included.Enterprise Application Platform (EAP) for clustering JAVA applications

RHEL Tomcat 6 Cluster Configuration

[Tomcat 6 community documentation](http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html) explains the 3 different ways to implement a cluster.
  • Using session persistence, and saving the session to a shared file system (PersistenceManager + FileStore)
  • Using session persistence, and saving the session to a shared database (PersistenceManager + JDBCStore)
  • Using in-memory-replication, using the SimpleTcpCluster that ships with Tomcat 6 (lib/catalina-tribes.jar + lib/catalina-ha.jar)

The focus of the configuration here is SimpleTcpCluster. Configuration details are as follows:

  1. Verify that you are running a supported configuration.
  2. Verify you are running a supported version
  3. Add the following configuration to each Tomcat6 node so it can establish an application based cluster
<!--This uses UDP MULTI-CAST for establishing the cluster ([Tomcat6 community documentation](http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html) has more info on TCP based cluster formation) -->
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6">
    <!-- <Manager className="org.apache.catalina.ha.session.BackupManager"
                  expireSessionsOnShutdown="false" 
                   notifyListenersOnReplication="true mapSendOptions="6"/> -->

          <Manager className="org.apache.catalina.ha.session.DeltaManager"
                   expireSessionsOnShutdown="false" notifyListenersOnReplication="true"/>
    
               <Channel className="org.apache.catalina.tribes.group.GroupChannel">
                         <Membership className="org.apache.catalina.tribes.membership.McastService" address="228.0.0.4"
                                     port="45564" frequency="500" dropTime="3000"/>
                         <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto"                                                                                 
                                   port="5000" selectorTimeout="100" maxThreads="6"/>
                         <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
                                 <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
                         </Sender>
                         <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
                         <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
                         <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
                </Channel>

          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
                 filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>

     <!-- <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                    tempDir="/tmp/war-temp/" deployDir="/usr/share/tomcat6/webapps/" watchDir="/usr/share/tomcat6/webapps/"
                    watchEnabled="true"/> -->
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
      </Cluster>
Verify a supported version is installed
    # rpm -qa | grep tomcat
    [Tue Sep 25 16:07:09 2012] [error] (13)Permission denied: proxy: HTTP: attempt to connect to 10.12.52.82:8080 (10.12.52.82) failed
    [Tue Sep 25 16:07:09 2012] [error] ap_proxy_connect_backend disabling worker for (10.12.52.82)
Components
Category
Tags

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.