Tomcat Cluster – Farm Deployer Not Working in Tomcat Cluster

clusterfarmwardeployermod-jktomcat6Ubuntu

I have setup apache-tomcat clustering(Ubuntu Server) and I used tomcat supported clustering technique with mod_jk following the link. I've setup with One Load Balancer and Two web servers.

The major problem is deploying the WAR file and to which web server?. I got to know about Farmed Deployment which deploys war file to other tomcat servers in the cluster but I haven't got it working yet. I used the farm deployer in the below fashion in the element on two of the web servers.

Web Server 1(192.168.1.101)

<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                    tempDir="/usr/share/tomcat/temp/"
                    deployDir="/usr/share/tomcat/webapps/"
                    watchDir="/usr/share/tomcat/watch/"
                    watchEnabled="true"/>

Web Server 2(192.168.1.102)

<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                    tempDir="/usr/share/tomcat/temp/"
                    deployDir="/usr/share/tomcat/webapps/"
                    watchDir="/usr/share/tomcat/webapps/"
                    watchEnabled="false"/>

I placed the WAR in watch directory on web server 1 but it's not deploying to other server. Anybody got this working, Any thing I'm doing wrong?, please let me know!.

Thank you!

Update:1

I could see the following info in either of the machines in catalina.out logs,

14 Aug, 2011 9:12:11 PM org.apache.catalina.ha.deploy.FarmWarDeployer start
SEVERE: FarmWarDeployer can only work as host cluster subelement!

It don't even deploy to webserver1 and also not to webserver2. Getting 404 error when accessed the site. Any more help…?. One more thing, I didn't install tomcat from apt repository but I built it from source which is working perfectly for the our java apps.

Best Answer

The first location you should take a look at is catalina.out, it will tell you what might be wrong.

If you can't make it works with multicast, just try static membership (I think it will simpler).

Below is my config:

Put the <Cluster node inside the <Host element:

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">         
  <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">

    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
        <Channel className="org.apache.catalina.tribes.group.GroupChannel">
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                  address="192.168.5.149"
                  port="4000"
                  selectorTimeout="100"
                  maxThreads="6"/>
            <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="4001"
                      securePort="-1"
                      host="192.168.5.199"
                      domain="staging-cluster"
                      uniqueId="{0,1,2,3,4,5,6,7,8,9}"/>
            </Interceptor>
        </Channel>
        <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
            tempDir="/usr/share/tomcat6/tempdir/"
            deployDir="/usr/share/tomcat6/webapps/"
            watchDir="/usr/share/tomcat6/watchdir/"
            watchEnabled="true"/>
    </Cluster>
  </Host>
</Engine>
  • The address attribute in <Receiver element is the node1's IP address. (in your case is .101)
  • The port is listening for replication messages on node 1 (4000-4100)
  • The Member's port in <Interceptor is listening for cluster messages on node 2
  • The Member's host is the IP address of node 2 (.102)

server.xml on the node 2:

    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
        <Channel className="org.apache.catalina.tribes.group.GroupChannel">
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                  address="192.168.5.199"
                  port="4001"
                  selectorTimeout="100"
                  maxThreads="6"/>
            <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="4000"
                      securePort="-1"
                      host="192.168.5.149"
                      domain="staging-cluster"
                      uniqueId="{0,1,2,3,4,5,6,7,8,9}"/>
            </Interceptor>
        </Channel>
        <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
            tempDir="/usr/share/tomcat6/tempdir/"
            deployDir="/usr/share/tomcat6/webapps/"
            watchDir="/usr/share/tomcat6/watchdir/"
            watchEnabled="false"/>
    </Cluster>

Make sure that Tomcat can write to tempDir and watchDir folder:

chmod g+w tempDir watchDir
chgrp tomcat tempDir watchDir

If you don't do this, you will get the below error:

Aug 13, 2011 10:28:33 PM org.apache.catalina.ha.deploy.FarmWarDeployer messageReceived
SEVERE: Unable to read farm deploy file message.
java.io.IOException: Permission denied

Remember to add <distributable/> into webapps/ROOT/WEB-INF/web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  ...
  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
  <distributable/>
</web-app>

Whenever you copy a .war file into watchdir folder on node 1, you will see something like the following in catalina.out:

Aug 14, 2011 1:40:58 AM org.apache.catalina.ha.deploy.WarWatcher check
INFO: check cluster wars at /usr/share/tomcat6/watchdir
Aug 14, 2011 1:40:59 AM org.apache.catalina.ha.deploy.FarmWarDeployer fileModified
INFO: Installing webapp[/cas] from /usr/share/tomcat6/webapps/cas.war
Aug 14, 2011 1:40:59 AM org.apache.catalina.ha.deploy.FarmWarDeployer remove
INFO: Cluster wide remove of web app /cas
Aug 14, 2011 1:40:59 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive cas.war

and on the node 2:

Aug 14, 2011 1:40:59 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive cas.war

Good luck!