Вы находитесь на странице: 1из 5

8/21/2015 Liferay cluster on Amazon EC2

30th April 2012 Liferay cluster on Amazon EC2

[http://3.bp.blogspot.com/-8Q6t8FkjAuc/T56a-
YSKD4I/AAAAAAAAUMI/x6fxI6OKhoU/s1600/liferay_logo.jpeg]

[http://2.bp.blogspot.com/--6ZD2XXFiLU/T56a8nZZ47I/AAAAAAAAUMA/kLFT9-
QOuy0/s1600/amazon_aws.jpeg]

Recently I got a challenge of setting up a Liferay cluster on Amazon EC2. This proved to be more than a cakewalk
and was a big learning experience for me. Following are the steps I took to setup this cluster. For those who are not
aware, Amazon EC2 doesn't allow for multicasting and hence most of the clustering/caching technologies don't
work out of the box. The setup which I created involves setting up of unicast cluster with cache replication also
happening over unicast.

Two issues are of concern when we are trying to setup a Liferay cluster:

1. Session replication (Need clustering of tomcat over unicast)


2. Cache replication (Need clustering of ehcache over unicast)

My setup involved use of Liferay 6.0 EE SP2 bundled with tomcat 6.0.32.

Configuration of tomcat:

Tomcat needs to be configured to allow for setup of cluster of two nodes over unicast. Following is section of my
${LIFERAY_HOME}/tomcat-6.0.32/conf/server.xml on server1 (replace node1 with node2 and swap location of
IP_ADDRESSES and change unique_id to anything 16 bit long other than {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2}, on
server.xml in server2) which allowed for this. IP_ADDRESSES here refer to private ip addresses of server1 and
server2 respectively.

http://pastebin.com/R8QnUqaY [http://pastebin.com/R8QnUqaY]

I know this is not safe considering the fact that Amazon doesn't guarantee persistence of this IP address across
reboots, but it was the easiest way out. I also kept both servers under same security group and allowed all
TCP/UDP access to this security group.

http://techynfreesouls.blogspot.in/2012/04/liferay-cluster-on-amazon-ec2.html 1/5
8/21/2015 Liferay cluster on Amazon EC2

Restart tomcat and I could see session replication working as intended. To verify this I loadbalanced both server1
and server2 behind Apache and followed following steps:

1. Start tomcat on server1.


2. Visit site through apache loadbalancer.
3. Login to site.
4. Start tomcat on server2.
5. Stop tomcat on server1.
6. Refresh my browser. If you aren't getting logged out then you can give yourself a pat on your back :)

Configuration of ehcache:

Once through with session replication, next step was to setup clustering of ehcache. Initially I tried unicast setup for
RMI but it didn't work out (need to understand it more), so I moved over to JGroups. Before trying out I upgraded
ehcache-core, ehcache-jgroupsreplication and jgroups jar files in ${LIFERAY_HOME}/tomcat­
6.0.32/webapps/ROOT/WEB­INF/lib with their latest versions available from http://ehcache.org
[http://ehcache.org/] and http://www.jgroups.org/ [http://www.jgroups.org/] . Then I extracted tcp.xml from the jgroups
jar file and placed it in a folder called ${LIFERAY_HOME}/tomcat­6.0.32/webapps/ROOT/WEB­
INF/classes/myehcache. I also extracted hibernate-clustered.xml and liferay-multi-vm-clustered.xml from
ehcache-core jar file and placed them in same folder.

Next I edited tcp.xml and added following to &lt TCP

singleton_name="liferay_jgroups_tcp"

Following is my portal-ext.properties file:

[http://www.blogger.com/goog_1948509805]

http://pastebin.com/kUSBfnyv [http://pastebin.com/kUSBfnyv]

Next I edited ${LIFERAY_HOME}/tomcat-6.0.32/bin/setenv.sh and it looks like this on server1:

JAVA_OPTS="$JAVA_OPTS  ­Dfile.encoding=UTF8  ­
Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false  ­Duser.timezone=GMT  ­Xmx1024m  ­
XX:MaxPermSize=256m  ­Djgroups.bind_addr=IP_ADDRESS_OF_SERVER1  ­
Djgroups.tcpping.initial_hosts=IP_ADDRESS_OF_SERVER1[7800],IP_ADDERSS_OF_SERVER2[7800]"

On server2 change jgroups.bind_addr to contain IP address of server2.

Next we start tomcat and voilla ! we are up and running :) There are few more tests which I'm planning to execute
and hopefully this system will move to production in next few days !
Posted 30th April 2012 by Mayank Joshi
Labels: Amazon EC2, Ehcache, Jgroups, Liferay, Tomcat

http://techynfreesouls.blogspot.in/2012/04/liferay-cluster-on-amazon-ec2.html 2/5
8/21/2015 Liferay cluster on Amazon EC2

9 View comments

Seren Thompson 7/14/12, 5:57 AM


Did you also use S3 as a storage for the Document Library Portlet? Thanks.
Reply

Mayank Joshi 7/14/12, 1:28 PM


Yes. I made use of S3 for document library.
Reply

fimez 7/26/12, 6:18 PM


Did you also change something in the hibernate-clustered.xml and liferay-multi-vm-clustered.xml files you copied
or did you just use them as is?
Reply

Mayank Joshi 7/26/12, 10:44 PM


I don't remember making any changes to hibernate-clustered.xml and liferay-multi-vm-clustered.xml except for
maybe some changes related to my own code.

You can find my hibernate-clustered.xml at http://pastebin.com/Jt7JL4ks and liferay-multi-vm-clustered.xml at


http://pastebin.com/Jt7JL4ks
Reply

Hadi Mansorati 1/16/13, 5:29 AM


hello

i tried to use amazon load balancer

i`v enables sticky session like so

Stickiness: AppCookieStickinessPolicy, cookieName='JSESSIONID'

but without success to replicate the session

ist possible to be done using amazon load balancer

thank you again for your help


Reply

Anonymous 2/9/13, 8:05 AM


Hi -

Look into VPC (Virtual Private Cloud). You can guarantee the server's IP address across reboots since you define

http://techynfreesouls.blogspot.in/2012/04/liferay-cluster-on-amazon-ec2.html 3/5
8/21/2015 Liferay cluster on Amazon EC2

the private network and can statically assign them.

Thanks for the writeup- I'm doing the same thing.


Reply

Anonymous 2/9/13, 8:06 AM


Look into VPC (Virtual Private Cloud). You can then guarantee the IP address of your servers since you define the
private network and can statically assign systems into it.
Reply

Scott Cupit 4/4/13, 4:06 AM


I followed your instructions and everything seems to be running ok, startup has no exceptions. The issue I am
having is with Lucene cache, which is the cache for users & organizations. After following your instructions, I
added cluster.link.enabled=true and
lucene.replicate.write=true to portal-ext.properties. When starting LIferay, I get 4 GMS blocks to startup on both
servers, so it looks like it is working. But when I add a user or organization to node1, it doesn't show up on
node2 until i manually reindex node2. How did you do lucene replication in your cluster? Also, I never see
replication events in the logs, is there a way to verify replication for jgroups and lucene is working?
Reply

Hadi Mansorati 4/14/13, 6:05 PM


hello

clustering seams to work fine

but i have this weird issue that i cant change the language after login

but i can do so as a guest

is something in session replication i should look into

kind regards

Reply

http://techynfreesouls.blogspot.in/2012/04/liferay-cluster-on-amazon-ec2.html 4/5
8/21/2015 Liferay cluster on Amazon EC2

Enter your comment...

Comment as:  Norman (Google) Sign out

 
Publish Preview   Notify me

http://techynfreesouls.blogspot.in/2012/04/liferay-cluster-on-amazon-ec2.html 5/5

Вам также может понравиться