There are two ways of Clustering Liferay on Tomcat
1. Sticky Session
User request will always goes to same Liferay instance
2. Session Replication
User request can go to any tomcat in cluster and his session is copied on entire cluster
Lets get started for Sticky Session based clustering and load balancing.
Use-Case
Setting up two tomcat Liferay along with apache on same windows machine.
Pre-requirements
1. install Apche 2.x
2. download Liferay5.x and make an extra copy
Steps 1:
open httpd.conf from apache_home/conf/ and add these lines at the end
<Proxy balancer://mycluster>
BalancerMember ajp://localhost:8009/ route=tomcatA smax=15 max=50 loadfactor=20
BalancerMember ajp://localhost:8010/ route=tomcatB smax=15 max=50 loadfactor=20
</Proxy>
<Location / >
ProxyPass balancer://mycluster/ stickysession=JSESSIONID
</Location>
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Deny from all
Allow from localhost
</Location>
Step 2:
uncomment the following four lines on httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule status_module modules/mod_status.so
Step 3:
open liferay/tomcat_home_1/conf/server.xml and add jvmRoute="tomcatA" to the following line
Engine name="Catalina" defaultHost="localhost"
so it should look like this
Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatA"
Step 4:
open liferay/tomcat_home_2/conf/server.xml and add jvmRoute="tomcatB" to the following line
Engine name="Catalina" defaultHost="localhost"
so it should look like this
Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatB
also change the following port nos
Server port="8006" shutdown="SHUTDOWN"
Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8444"
Connector port="8010" protocol="AJP/1.3" redirectPort="8444"
Thats It!
start apache, tomcatA, tomcatB and
navigate to http://localhost/
also checkout balancer-manager
http://localhost/balancer-manager
for more configuration and understanding checkout the following link
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
Note:
If your tomcats run on different server make sure you change index directory to some central place (e.g /common-dir/liferay ) i.e resource.repositories.root=/common-dir/liferay in portal-ext.properties
Lets get started for Session Replication based clustering and load balancing.
clustered environment using three servers, two with Tomcat with Liferay-tomcat-bundle bundle and one with apache 2.2 http server.
Step by step:
STEP 1:
Download and install the following, each on a different server:
Server A - Apache 2.2
Server B - Tomcat with Liferay-tomcat-bundle
Server C - Tomcat with Liferay-tomcat-bundle
At this point you should have unzipped the Tomcat with Liferay-tomcat-bundle bundle to two different servers and Apache 2.2 to a third server. You shouldn't have changed any of the configurations.
STEP 2:
Create a new Liferay schema on Server B on Mysql and connect Tomcat1 and Tomcat2 to the new database.
Assuming you have Liferay core compiled, or our sql script pack, execute this in windows command window, in the mysql prompt:
mysql> create database clusterlrdb character set utf8;
Modify the portal-ext.properties
########################## Local MySQL Server ##########################
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/clusterlrdb?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=root
STEP 3:
Download and install the mod_jk shared object file into Server A - $Apache_2.2_HOME/modules/
I renamed my mod_jk file so now I have a mod_jk.So in $Apache_2.2_HOME/modules/. After you've installed mod_>jk into the Apache server, you can continue to the next step.
STEP 4:
Create httpd-mod_jk.conf in $Apache_2.2_HOME/conf/extras. Paste these contents into httpd-mod_jk.conf:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkLogLevel info
JkShmFile logs/jk-runtime-status
Note:
"LoadModule jk_module modules/mod_jk.so" - loads mod_jk.so so that you could use mod_jk arguments.
"JkWorkersFile conf/workers.properties" - specifies location of workers.properties file where the load balancer and any servers involved with the cluster are defined.
STEP 5:
Create workers.properties in $Apache_2.2_HOME/conf/. Paste these contents in there:
worker.properties:
worker.list=portal-01,portal-02,loadbalancer
worker.portal-01.port=8009
worker.portal-01.host=<IP-address of Server B>
worker.portal-01.type=ajp13
worker.portal-01.cachesize=10
worker.portal-02.port=8009
worker.portal-02.host=<IP-address of Server C>
worker.portal-02.type=ajp13
worker.portal-02.cachesize=10
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=portal-01,portal-02
worker.loadbalancer.sticky_session=1
Note:
I've designated Server B and Server C to be my Liferay servers, an in worker.properties I've given Server B a symbolic name (portal-01) as well as Server C (portal-02). You can give your servers any symbolic name so long as they are consistent!
Also make sure that the port and host for each server configuration in workers.properties is consistent with the server itself.
STEP 6:
Modify $Apache_2.2_HOME/conf/extras/httpd-vhosts.conf
Make a backup of httpd-vhosts.conf. The contents of httpd-vhosts.conf should now just consist of:
NameVirtualHost *:80
<VirtualHost *:80>
JkMount /* loadbalancer
</VirtualHost>
This makes it so that anytime the localhost url of Server A is hit, the load balancing mechanism will control whether the user will actually go to Server B or Server C.
STEP 7:
In Apache's httpd.conf we need to include our new httpd-mod_jk.conf and our modified httpd-vhosts.conf.
Uncomment the following in $Apache_2.2_HOME/conf/httpd.conf:
#Include conf/extra/httpd-vhosts.conf
Append the following in $Apache_2.2_HOME/conf/httpd.conf:
Include conf/extra/httpd-mod_jk.conf
Restart Apache.
STEP 8:
Paste this into portal-ext.properties for Tomcat1 and Tomcat2:
cluster.link.enabled=true
net.sf.ehcache.configurationResourceName=/ehcache/hibernate-clustered.xml
ehcache.multi.vm.config.location=/ehcache/liferay-multi-vm-clustered.xml
cluster.link.channel.system.properties=\
#
# Common
#
\
jgroups.bind_addr:localhost,\
#jgroups.bind_interface:eth0,\
\
#
# UDP
#
\
jgroups.udp.mcast_addr:<IP...server1>,\
jgroups.udp.mcast_port:server1port,\
jgroups.udp.ip_ttl:8,\
\
#
# Multicast
#
\
jgroups.mping.mcast_addr:<IP...server2>,\
jgroups.mping.mcast_port:server2port,\
jgroups.mping.ip_ttl:8,\
\
#
# TCP
#
\
jgroups.tcpping.initial_hosts:localhost[port1],localhost[port2]
Restart both Tomcat1 and Tomcat2.
For EhChache settings look into link
http://www.liferay.com/documentation/liferay-portal/6.0/administration/-/ai/distributed-cachi-4
look into this link also:
http://www.liferay.com/community/forums/-/message_boards/message/12891790
Hi Veera :)
ReplyDeleteGreat post. This may be of interest. We published an article on how to create highly available cluster for Liferay in the cloud with Jelastic
http://blog.jelastic.com/2013/06/06/liferay-cluster/
Nice Article Veera
ReplyDeleteVery Helpful information.
ReplyDeleteAs per my opinion, videos play a vital role in learning. And when you consider Big data consulting services , then you should focus on all the learning methods. Udacity seems to be an excellent place to explore machine learning.
ReplyDelete