2

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.

user53864
  • 1,653
  • 8
  • 36
  • 66

2 Answers2

5

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!

quanta
  • 50,327
  • 19
  • 152
  • 213
  • Many new things you brought in front, I'm trying, I'll let you know!! – user53864 Aug 14 '11 at 06: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 ` – quanta Aug 15 '11 at 02: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 03:21
  • If you can access your webapp on the node 2 via IP, it means that the webapp was deployed successful. Did you point the domain to the Apache (HTTP) server? Please post your `mod_jk.conf` and `workers.properties`. – quanta Aug 15 '11 at 04:04
  • Yeah It was my worker properties mistake, it's working!. I removed the `update 2` in my question. But, should I restart the tomcat on all the machine in the cluster once placed in the watch directory?. – user53864 Aug 15 '11 at 04:11
  • No need to restart. – quanta Aug 15 '11 at 04:18
  • 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 04:25
  • why did you remove your config part? – user53864 Aug 15 '11 at 04:35
  • @user53864 let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/1079/discussion-between-quanta-and-user53864) – quanta Aug 15 '11 at 04:43
  • I have some problem in joining chat as it says `Your login data seems too old; please log in to any StackExchange site, possibly logging out before.` and I'm already logged in to serverfault. I'm checking...if it's the problem with google chrome.... – user53864 Aug 15 '11 at 04:51
  • Sure, I will help as possible as I can – quanta Aug 15 '11 at 05:07
  • Hai!, I opened the new question here:`http://serverfault.com/questions/301164/tomcat-cluster-farm-deployer-issue` – user53864 Aug 15 '11 at 10:20
  • Probably I can't start a bounty at the starting itself and I assure I'll definitely start and assign the bounty even if my problem is resolved easily. – user53864 Aug 15 '11 at 10:24
  • If you really have to put the cluster element inside host element, why oh why do all the sample config files--even for tomcat 8!-- have the element outside of host? Is this just an incredible oversight on their part? – Alkanshel Oct 17 '16 at 23:53
  • Pretty sure you only have to make it a subelement of host if host isn't a self-closing tag. You can move any Valves in it to the Cluster element to do this. – Alkanshel Oct 20 '16 at 19:14
1

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
  • Can you please be more specific. Should the mac address be mapping to localhost in the hosts file, or what? – Alkanshel Oct 17 '16 at 23:21