Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 4 down vote accepted
+50

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!

share|improve this answer
    
Many new things you brought in front, I'm trying, I'll let you know!! –  user53864 Aug 14 '11 at 6:49
    
No luck, I completely changed the configuration with your's. I update my question with some log info. –  user53864 Aug 14 '11 at 15:49
1  
You have to put the <Cluster node inside the <Host element, not <Engine. –  quanta Aug 15 '11 at 2:01
    
Yes, It's deploying to other node(node2) but the page still shows 404 error. When I tried with the IP/myapp then it displays the page on node1 and on node2 but not with the site url. I have updated the question with my logs. Please have a look at it as it says something!. –  user53864 Aug 15 '11 at 3:21
1  
Hey guy this Bounty is yours for sure!!!. You really helped a lot, Thank you very much!!. What if I have multiple webservers(nodes) rather than two nodes? and why it's not working with multicast config?. If you are ready to help me again, I'll create one more bounty for new question or in this. If possible upvote my question, so that it round figures. –  user53864 Aug 15 '11 at 4:25

Multicast address works if your /etc/hosts file contains the actual NIC ip address and not the loopback address 127.0.0.1. Tomcat picks up the Receiver.address attribute which is determined by the:

 <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                      address="auto"

Multicast service will broadcast the IP address which is associated with server's hostname. Catalina.out should show what ip address it picked up during startup. If loopback address is detected then cluster nodes will not be able to communicate with each other. A false address pickup example in catalina.out log file which results in no communication between nodes:

INFO: Cluster is about to start
09/08/2013 7:38:14 PM org.apache.catalina.tribes.transport.ReceiverBase bind
INFO: Receiver Server Socket bound to:/127.0.1.1:5000
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.