Skip to main content
06 Aug 2014

Liferay-Tomcat Cluster Setup

Prerequisites:

Software :

Liferay-portal-tomcat.6.1.10-ee-ga1.tar.gz

Systems:

Liferay Tomcat Node 1:

IP: 192.168.56.1 (LOCALIP)

Liferay Tomcat Node 2:

IP: 192.168.56.2 (NODE2)

Liferay 6.1.10 Installation:

  • Download Liferay-portal-tomcat-6.1.10-ee-ga1.tar.gz from Liferay with Cluster License file.

  • Copy installation source to /opt directory as below.

# cp Downloads/liferay-portal-tomcat-6.1.10-ee-ga1.tar.gz /opt/

  • Extract Liferay bundle for configuration.

# cd /opt/

# tar -zxvf liferay-portal-tomcat-6.1.10-ee-ga1.tar.gz

# mv liferay-portal-6.1.10-ee-ga1 liferay

  • Create portal-ext.properties file with following properties for UNICAST cluster in /opt/liferay directory.

setup.wizard.enabled=false

# Unicast Cluster Configuration

net.sf.ehcache.configurationResourceName=/myehcache/hibernate-clustered.xml

ehcache.multi.vm.config.location=/myehcache/liferay-multi-vm-clustered.xml

# Unicast Cluster Config order to make use of jgroups

ehcache.bootstrap.cache.loader.factory=com.liferay.portal.cache.ehcache.JGroupsBootstrapCacheLoaderFactory

ehcache.cache.event.listener.factory=net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory

ehcache.cache.manager.peer.provider.factory=net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory

net.sf.ehcache.configurationResourceName.peerProviderProperties=file=myehcache/tcp.xml

ehcache.multi.vm.config.location.peerProviderProperties=file=myehcache/tcp.xml

  • Enable Jvm route in tomcat server.xml for load-balancing with AJP. For node2 add jvmRoute=worker2”.

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

  • Edit server.xml file of tomcat with following changes for Cluster configuration. Add same configuration in node2 server.xml make sure to change IP Address and UniqueID respectively. IP ADDRESS in Receiver properties must be Local system IP address and Sender properties must be Remote node IP address. UNIQUEID MUST BE DIFFERENT ON EACH TOMCAT CONFIGURATION.

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6" channelStartOptions="3">

<Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true" />

<Channel className="org.apache.catalina.tribes.group.GroupChannel">

<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" autoBind="0" selectorTimeout="5000" maxThreads="6" address="192.168.56.2" port="4444" />

<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">

<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" timeout="60000" keepAliveTime="10" keepAliveCount="0"/>

</Sender>

<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor" staticOnly="true"/>

<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" host="192.168.56.3" port="4444" uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9}"/>

</Interceptor>

</Channel>

<Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter="" />

<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" />

<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>

<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>

</Cluster>

  • Edit both tomcat web.xml file for enabling session replication between two cluster nodes. Add <distributable/> tag in tomcat web.xml file just before </web-app>.

  • Need to add following Java library files to Liferay for enabling jgroup and ehcache replication for clustering. Download and copy following files and copy in Liferay's lib directory. (e.g. /path/to/liferay/tomcat/webapps/ROOT/WEB-INF/lib/)

  • Add following java options to setenv.sh of both node's tomcat as below. Edit /path/to/tomcat/bin/setenv.sh and add following lines at end.

JAVA_OPTS= -Djgroups.bind_addr=<LOCALIP> -Djgroups.tcpping.initial_hosts=<LOCALIP>[7800],<NODE2IP>[7800]"

  • For UNICAST Clustering we need to add ehcache configuration files inside liferay classes with new folder named myehcache. Create myehcache directory in /path/to/liferay/tomcat/webapps/ROOT/WEB-INF/classes/ and add put following files in that. This files can be found in liferay src package, for tcp.xml available here and then add singleton_name="liferay_jgroups_tcp" line after timer_type="new" line.

    • hibernate-clustered.xml

    • liferay-multi-vm-clustered.xml

    • tcp.xml

  • Process same configuration for Node2 and verify.

  • After verification Start both Liferay node one by one. You will see "INFO: Cluster is about to start” message in logs.