Friday, September 6, 2013

Liferay Portal clustering using Apache Load Balancer

Liferay Portal clustering using Apache Load Balancer

Load balancing is one of the most popular in the world due to its impressive ease-of-use. Load balancing is techniques to distributed load on multiple-system. The load-balancing process is completely transparent to the end user. It’s configured optimally for a multiple server environment. If one server isn’t sufficient to serve the high traffic needs of your site, Liferay scales to the size you need.

Simply add load balancing to your current multiple tomcat server configuration in order to achieve high availability and build your own web cluster without burning your entire hosting budget. Load balancing can be implemented quickly and easily as an add-on to your current server solution to share the load between your web servers, using a simple script to replicate the data on the server.

Features of the load balancer:

·         Intercepts network-based traffic (such as web traffic) destined for a site.
·         Splits the traffic into individual requests and decides which servers receive individual requests
·         Maintains a watch on the available servers, ensuring that they are responding to traffic. If they are not, they are taken out of rotation.
·         Provides redundancy by employing more than one unit in a fail-over scenario
·         Offers content-aware distribution, by doing things such as reading URLS, intercepting cookies and XML parsing.

Benefits of the load balancer:

·         Flexibility:
§  Load balancing allows the addition and removal of servers to a site at any time, and the effect is immediate. Among other advantages, this allows for the maintenance of any machine, even during peak hours with little or no impact to the site. A load balancer can also intelligently direct traffic using cookies, URL parsing, static and dynamic algorithms, and much more.

·         High Availability:
§  Load balancer can check the status of the available servers, take any non-responding servers out of the rotation, and put them in rotation when they are functioning again. This is automatic, requiring no intervention by an administrator. Also, the load balancers themselves usually come in a redundant configuration, employing more than one unit in case any one unit fails.

·         Scalability:
§  Since load balancer distributes load among many servers, all that is needed to increase the serving power of a site is to add more servers. This can be very economical, since many small- to medium-sized servers can be much less expensive than a few high-end servers. Also, when site load increases, servers can be brought up immediately to handle the increase in traffic. Load balancers started out as PC-based devices, and many still are, but now load balancing functions have found their way into switches and routers as well.

Liferay Load Balancing

As we know that load balancing is a technique to distribute workload across resources. It is nothing but a high-availability cluster.
In Liferay Portal’s case, we are load balancing the volume of requests across multiple app servers, which may or may not be on physically separate hardware. Initially this may seem sufficient, until you realize some of the components that portal uses.
Use case: Setting up two Liferay tomcat instance which points to the same database along with Apache server on same windows machine

           ·         Install Apache 2.2 or latest stable version from here.
           ·         Download Liferay 6.1 CE version from here.
           ·         Install MySQL

    Step 1: Configure Apache Server
         ·      Open httpd.conf from Apache_Home/conf folder and add the following lines at the end of              the file
      <Proxy balancer://mycluster>
  BalancerMember ajp://localhost:8010/ route=tomcatA smax=15 max=50 loadfactor=20
  BalancerMember ajp://localhost:8011/ route=tomcatB smax=15 max=50 loadfactor=20

  <Location / >
  ProxyPass balancer://mycluster/ stickysession=JSESSIONID

  <Location /balancer-manager>
  SetHandler balancer-manager
  Order Deny,Allow
  Deny from all
  Allow from localhost

          ·         Uncomment the following lines in httpd.conf file
LoadModule proxy_module modules/
LoadModule proxy_ajp_module modules/
LoadModule proxy_balancer_module modules/
LoadModule proxy_connect_module modules/
LoadModule proxy_ftp_module modules/
LoadModule proxy_http_module modules/
LoadModule status_module modules/

   Step2: Configure Database
       ·    It’s assumed that you already have installed MySQL on your machine. Then go to your                 mysql command prompt and create a new database with the any name that you want.
 create database liferay_loadbalancer;

    Step3: Configure Liferay instance

       ·         It’s assumed that you created two Liferay instance under one main folder named as                       “Liferay_LAB” and give the first instance folder name as “liferay-portal-6.1.0-ce-ga1” and             another instance folder name as “liferay-portal-6.1.0-ce-ga2”.
       ·         Create a file with following properties

   # MySQL
jdbc.default.driverClassName=com.mysql.jdbc.Driver  jdbc.default.url=jdbc:mysql://localhost/liferay_loadbalancer?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
And put it under following paths


·         Open liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/conf/server.xml and apply following changes
§  Change the server port to 8006
<Server port="8006" shutdown="SHUTDOWN">
§  Change the connector port to 8081 and redirectPort to 8444
<Connector port="8081" protocol="HTTP/1.1"
               redirectPort="8444" URIEncoding="UTF-8" />
§  Change the AJP connector port to 8010 and redirectPort to 8444. Make sure that URIEncoding must match to "UTF-8"
<Connector port="8010" protocol="AJP/1.3" redirectPort="8444" URIEncoding="UTF-8" />
§  add jvmRoute="tomcatA" to following line
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatA" >
§  Uncomment the following line
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

·         Open liferay-portal-6.1.0-ce-ga2/tomcat-7.0.23/conf/server.xml and apply following changes
§  Change the server port to 8007
<Server port="8007" shutdown="SHUTDOWN">
§  Change the connector port to 8082 and redirectPort to 8445
<Connector port="8082" protocol="HTTP/1.1"
               redirectPort="8445" URIEncoding="UTF-8" />
§  Change the AJP connector port to 8011 and redirectPort to 8445. Make sure that URIEncoding must match to "UTF-8"
<Connector port="8011" protocol="AJP/1.3" redirectPort="8445" URIEncoding="UTF-8" />
§  add jvmRoute="tomcatB" to following line
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatB" >
§  Uncomment the following line
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

Congratulation! It's done.
Now start apache, tomcat A and tomcat B server.
Once all servers started, go to browser and hit http://localhost/. It will load any one of the Liferay instance page (http://localhost:8081/) or (http://localhost:8082/).

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.