Clustering Liferay + Tomcat + Mysql on Windows XP.

Recently I set up a clustered environment using three servers, two with liferay-tomcat-4.4.2 bundle and one with apache 2.2 http server.  Here are my steps:

STEP 1:
Download and install the following, each on a different server:
Server A - Apache 2.2
Server B - Tomcat1 (Liferay-tomcat-4.4.x bundle)
Server C - Tomcat2 (Liferay-tomcat-4.4.x bundle)

At this point you should have unzipped the liferay-tomcat-4.4.x 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 portal442 character set utf8;

Modify the ROOT.xml of Tomcat1 and Tomcat2 so that they connect to 'portal442' database. Liferay will automatically populate the database with tables and some minimal data when I start either one of the servers up if I don't run any of the sql scripts availabe in the portal source.

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:

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

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

comm.link.properties=UDP(bind_addr=127.0.0.1;mcast_addr=231.12.21.102;
mcast_port=45566;ip_ttl=32;mcast_send_buf_size=150000;
mcast_recv_buf_size=80000):PING(timeout=2000;num_initial_members=3):MERGE2(min_interval=5000;
max_interval=10000):FD_SOCK:VERIFY_SUSPECT(timeout=1500):pbcast.NAKACK(gc_lag=50;
retransmit_timeout=300,600,1200,2400,4800; max_xmit_size=8192):UNICAST(timeout=300,600,1200,2400):
pbcast.STABLE(desired_avg_gossip=20000):FRAG(frag_size=8096;down_thread=false;
up_thread=false):pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=true)

web.server.display.node=true

Restart both Tomcat1 and Tomcat2.
 

Blogs
Great Post! Is this setup applicable to Liferay 4.34?
Jeff, theoretically yes, this setup will work for 4.34 because most of the configuration is non-Liferay specific. I know we introduced Ehcache in 4.3.x, so any issues would be dependent on the Liferay codebase. Would you mind letting me know the outcomes on 4.34?
Hi Friends,

Nice Post but I was also willing to implement clustering using heartbeat with DRBD and mysql database clusering and got a great ebook on clustering on http://www.ebooksyours.com/what-is-clustering.html , this ebook guides you everything from scratch from setting up linux cluster with heartbeat,DRBD,OCFS and GFS. It also guides up for setting mysql dual master replication too. I would highly recommend to buy ebook from http://www.ebooksyours.com.

Cheers !
Alok
Hi. What about session replication? How is that managed? In previous cluster configuration there used to be mention about configuring SimpleTCPCluster for tomcat and JBoss. Is that not needed now?