Search code examples
tomcattomcat7replicationsession-replication

Tomcat Clustering Configuration


I'm configuring Liferay on Tomcat 7 for clustering. I searched on the web and found several instructions. Reading all of them raised some questions to me. I would appreciate it if someone help me.

A. I know that by inserting the following line in server.xml in "${CATALINA_HOME}/conf", it configures Tomcat with default values as described in Tomcat Documentation (link):

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

Here are some of the important default values:

1- Multicast address is 228.0.0.4
2- Multicast port is 45564 (the port and the address together determine cluster membership.
3- The IP broadcasted is java.net.InetAddress.getLocalHost().getHostAddress() (make sure you don't broadcast 127.0.0.1, this is a common error)
4- The TCP port listening for replication messages is the first available server socket in range 4000-4100
5- Two listeners are configured ClusterSessionListener
6- Two interceptors are configured TcpFailureDetector and MessageDispatch15Interceptor

Since my cluster environment is small (two Tomcat instances), I think the default configurations would be good enough.

Q#A. I would like to know what exactly item #3 means. How may I make that mistake?

B. Based on the above the default configuration uses Dynamic clustering on IP address 228.0.0.4. I assume this is a broadcasting address (correct me if I'm wrong). If so, this link says:

In Linux Environment most of the system kernel is capable to process the multicast address. but we need to add route entry in kernel routing table.

sudo route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0

Q#B. What does this means? How can I know whether I should this or not?

C. As the next step for clustering, I need to add "<distributable/>" element to my web.xml file of the web application. There one web.xml for each web application in "${CATALINA_HOME}/webapps" folder on the server. I understand that all of them should have this element to included in the session replication (correct me if I'm wrong).

Q#C1. I found another "web.xml" file with "liferay-" as prefix for every web application. Should they be considered as another web.xml and have this element?

Q#C2. Is there any way to add "<distributable/>" element in one place and have it applied on all web applications? Some sort of parent/global "web.xml" file?

D. Some instructions says that "distributable='true'" attribute should be added to "<Context>" element in "${CATALINA_HOME}/conf/context.xml" file. And some don't instruct it.

Q#D. Is this configuration mandatory? What is the consequence of having this attribute and not having it?

Thanks in advance.


Solution

  • A.) The boardcasted ip address is the cluster nodes ip address and not the multicast address. The udp packages will contain this ip, to tell the recipient who did send this package; the senders ip. If it was set to localhost/127.0.0.1 the recipients wont be able to call the sender, because the would call themselves.

    B.) I never had to add such a route. Sorry, cant tell. I would give it a try without it.

    C.) Only the "main" Liferay app needs the distributable flag, since it will handle the session.

    D.) Adding the flag in web.xml does the same. In the context element you can overwrite this property for a specific server. If the flag is set, the app will participate in session replication, i.e. if the balancer has the sticky session flag set to false, clients will be redirected continuously, creating new sessions on every node. If set, they will be redirected too, but keep their first session.