Liferay Clustering can be done with two ways.
1. Multicast
2. Unicast
Amazon AWS doesn’t support multicast traffic, hence we need to setup Liferay unicast clustering.
In below example, we have used Jgroups for ehcache replication. Session replication was done by configuring tomcat for unicast communication in cluster.
Prerequisites:
Tomcat Node 1:
IP: 192.168.100.100
Tomcat Node 2:
IP: 192.168.100.200
- Install liferay on both Amazon nodes.
- Set JvmRoute in Server.xml file of tomcat. Add “worker1” in tomcat node 1 and “worker2” in tomcat node2.
<Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”worker1“>
- Add <distributable/> in web.xml file in both tomcat nodes.
<distributable/>
</web-app>
</web-app>
- Download below mentioned jar files and add it into /{TOMCAT_HOME}/webapps/ROOT/WEB-INF/lib folder from Cluster Files
- ehcache.jar
- ehcache-jgroupsreplication.jar
- jgroups.jar
- Add below lines in server.xml of both the tomcat nodes.
In tomcat node1, set address=”192.168.100.100” and port=”4444” as receiver properties. And as a member add host=”192.168.100.200”. We will have to keep different uniqueid in both tomcats.
In tomcat node2, set address=”192.168.100.200” and port=”4444” as receiver properties. And as a member add host=”192.168.100.100”. We will have to keep different uniqueid in both tomcats.
<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.100.101″ 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.100.102″
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>
- Now add below properties in tomcat/bin/setenv.sh file.
In Tomcat node 1, keep below mentioned properties.
JAVA_OPTS=”$JAVA_OPTS -Djgroups.bind_addr=192.168.100.100 -Djgroups.tcpping.initial_hosts=192.168.100.100[7800],192.168.100.200[7800]”
In Tomcat Node 2, keep below mentioned properties.
JAVA_OPTS=”$JAVA_OPTS -Djgroups.bind_addr=192.168.100.200 -Djgroups.tcpping.initial_hosts=192.168.100.200[7800],192.168.100.200[7800]”
- Now create tcp.xml file in /{TOMCAT_HOME}/webapps/ROOT/WEB-INF/classes/myehcache location and add below content into it.
<config xmlns=”urn:org:jgroups”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”urn:org:jgroups http://www.jgroups.org/schema/JGroups-2.8.xsd”>
<TCP bind_port=”7800″
loopback=”true”
recv_buf_size=”${tcp.recv_buf_size:20M}”
send_buf_size=”${tcp.send_buf_size:640K}”
discard_incompatible_packets=”true”
max_bundle_size=”64K”
max_bundle_timeout=”30″
enable_bundling=”true”
use_send_queues=”true”
sock_conn_timeout=”300″
singleton_name=”liferay_jgroups_tcp”
timer_type=”new”
timer.min_threads=”4″
timer.max_threads=”10″
timer.keep_alive_time=”3000″
timer.queue_max_size=”500″thread_pool.enabled=”true”
thread_pool.min_threads=”1″
thread_pool.max_threads=”10″
thread_pool.keep_alive_time=”5000″
thread_pool.queue_enabled=”false”
thread_pool.queue_max_size=”100″
thread_pool.rejection_policy=”discard”oob_thread_pool.enabled=”true”
oob_thread_pool.min_threads=”1″
oob_thread_pool.max_threads=”8″
oob_thread_pool.keep_alive_time=”5000″
oob_thread_pool.queue_enabled=”false”
oob_thread_pool.queue_max_size=”100″
oob_thread_pool.rejection_policy=”discard”/><TCPPING timeout=”3000″
initial_hosts=”${jgroups.tcpping.initial_hosts:localhost[7800],localhost[7801]}”
port_range=”1″
num_initial_members=”3″/>
<MERGE2 min_interval=”10000″
max_interval=”30000″/>
<FD_SOCK/>
<FD timeout=”3000″ max_tries=”3″ />
<VERIFY_SUSPECT timeout=”1500″ />
<BARRIER />
<pbcast.NAKACK
use_mcast_xmit=”false” gc_lag=”0″
retransmit_timeout=”300,600,1200,2400,4800″
discard_delivered_msgs=”true”/>
<UNICAST timeout=”300,600,1200″ />
<pbcast.STABLE stability_delay=”1000″ desired_avg_gossip=”50000″
max_bytes=”4M”/>
<pbcast.GMS print_local_addr=”true” join_timeout=”3000″view_bundling=”true”/>
<UFC max_credits=”2M”
min_threshold=”0.4″/>
<MFC max_credits=”2M”
min_threshold=”0.4″/>
<FRAG2 frag_size=”60K” />
<pbcast.STREAMING_STATE_TRANSFER/>
<!– <pbcast.STATE_TRANSFER/> –>
</config>
8. Now add below properties in portal-ext.properties.
#In 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
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
#Setup hibernate
net.sf.ehcache.configurationResourceName=/myehcache/hibernate-clustered.xml#Setup distributed ehcache
ehcache.multi.vm.config.location=/myehcache/liferay-multi-vm-clustered.xml
- Now add liferay-multi-vm-clustered.xml and hibernate-clustered.xml files at /{TOMCAT_HOME}/webapps/ROOT/WEB-INF/classes/myehcache location.
- Now restart both liferay portal tomcat and verify clustering.
ReplyDeleteI recently came across your blog and have been following it. I'm very impressed. You're truly well informed and very intelligent. You've been able to write in a way people can understand easily. I'm saving this for future use.
liferay training in hyderabad