Setting up Session Replication in Tomcat With Liferay DXP

The purpose of this article is to setup a basic Tomcat cluster that has session replication. For true session replication, there must be a load balancer that redirects the traffic to the nodes. This article does not cover how to set up a load balancer. For information on how to set up a load balancer, refer to the vendor's documentation (e.g. Apache.).

This article also does not cover distributed caching or index replication, which are also necessary for clustering. Please refer to the article: Installing Liferay DXP in a Clustered Environment.

Make sure that all nodes have the same time and sync with a Network Time Protocol (NTP) service.

Please note: This is not the only way to achieve session replication with Tomcat; other methods like memcached are also available.


The following instructions will guide through the proper setup protocol.

  1. In ${TOMCAT_HOME}/conf/server.xml add the jvmRoute value to the Engine section.

    It will look something like this:

     <Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1">

    To clarify, worker1 is the name assigned to it, and can be any alphanumeric value; for example: [a-z][A-Z][0-9][_\-]

    If the Tomcat instances are running on the same machine, make sure the tcpListenPort attribute is unique for each instance. In most cases Tomcat is smart enough to resolve this on its own by auto-detecting available ports in the range 4000-4100. This is set in the server.xml.

  2. Replace <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" /> with the following lines in the Engine:
     <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8"> 
    <Manager className="org.apache.catalina.ha.session.DeltaManager" 
    <Channel className=""> <Membership className="org.apache.catalina.tribes.membership.McastService"
    <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
    <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
    <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
    </Sender> <Interceptor className=""/>
    <Interceptor className=""/> </Channel> <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/> <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

    <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
    <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/> </Cluster>
  3. In ${APACHE_HOME}/conf/, add in the worker information.

    It should look something like this:


    Please note the use of worker1 in the names. This is the same value as the jvmRoute value set in the first step. As stated previously, this value can be any alphanumeric value but must remain consistent throughout the configuration.

    If there are going to be more than 2 nodes, then create additional entries with the appropriate values, like worker3, worker4, etc...

  4. In the file of the Liferay bundle, add the following:

    Please note: The second property will allow things like AUI buttons to function with the Apache Server. The third property will make the node IDs visible as footers. These two properties are independent of session replication. Liferay Support assistance with further session replication configuration is limited.

  5. Repeat the steps for the second node and all other nodes. Set the same database connections such that all nodes point to the same database. The choice of database is up to the user and Liferay Support can give only basic assistance in this matter.
  6. Start servers sequentially. Cluster nodes cannot be started simultaneously because the process takes time to determine which node is the master node.
  7. Start the load balancer Web Server.
  8. Access the Web Server's IP Address or Domain Name. The web server will redirect the request to one node. Create a page, a user, or an asset.
  9. Shut down one node. Verify that the traffic has redirected automatically to the second node, and that the page, user, and asset appear on the second node.


  • Session state is tracked by a cookie, so the URL must look the same from the outside, otherwise a new session will be created.
  • All session attributes must implement
  • If there are custom cluster valves defined, make sure the ReplicationValve is defined as well under the Cluster element in server.xml
  • The Cluster module uses the Tomcat JULI logging framework, so logging can be configured through the regular file. To track messages, enable logging on the key: org.apache.catalina.tribes.MESSAGES
  • The property <distributable /> has been deprecated in Apache Tomcat 8.x onwards. It is no longer necessary to add this to the Manager element of conf/web.xml. You only need to add this to the Context element in WEB-INF/web.xml.

Additional Information

0 人中有 0 人觉得有帮助