Now, both the Liferay Portal server nodes are ready. As a next step, we need to configure the Apache Web Server to connect with both the Liferay Portal nodes and also distribute the load on both the Liferay Portal nodes. The Apache Web Server provides many options to connect with the Liferay Portal Tomcat server. But there are three options which are more popular. Let's understand these options and the scenarios in which they are best suitable.
This option allows us to configure the load balancer using the mod_jk
module of the Apache Web server. Internally, the mod_jk
module connects with the Liferay Portal Tomcat server using the AJP protocol. Using this option, the Apache Web Server distributes all requests on the AJP port of Liferay Portal Tomcat servers. Let's learn how to configure the software load balancer using this option.
mod_jk
module in the <APACHE_HOME>/modules
directory.mod_jk.conf
in the <APACHE_HOME>/conf
directory, and add the following configuration into it:LoadModule jk_module modules/mod_jk.so JkWorkersFile /etc/httpd/conf/workers.properties JkShmFile /var/log/httpd/mod_jk.shm JkLogFile /var/log/httpd/mod_jk.log JkLogLevel info JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " JkMount /* loadbalancer
httpd.conf
file located in the <APACHE_HOME>/conf
directory, and add the following line at the bottom:Includemod_jk.conf
worker.properties
in the <APACHE_HOME>/conf
directory, and add the following lines into it:#Name of the load balancer workers worker.list=loadbalancer #Worker configuration for liferay-node-01 #AJP Connector port of node-01 on liferay-node-01 server worker.node-01.port=8009 worker.node-01.host=<IP of liferay-node-01 server> worker.node-01.type=ajp13 #Factor which decides the load sharing by this worker in the cluster worker.node-01.lbfactor=1 #Worker configuration for liferay-node-02 worker.node-02.port=8009 worker.node-02.host=<IP of liferay-node-02 server> worker.node-02.type=ajp13 worker.node-02.lbfactor=1 #load balancer configuration properties worker.loadbalancer.type=lb #list of worker nodes that are part of the cluster worker.loadbalancer.balance_workers=node-01,node-02 worker.loadbalancer.sticky_session=1 worker.loadbalancer.method=B
server.xml
file of liferay-node-01
located in node-01liferay-portal-6.1.1-ce-ga2 tomcat-7.0.27conf
, and add the jvmRoute
attribute to the <Engine>
tag as given here:<Engine defaultHost="localhost" name="Catalina" jvmRoute="node-01">
jvmRoute
parameter in server.xml
of liferay-node-02
. Here the value of jvmRoute
will be node-02
.http://<Apache Web Server IP>
URL.To connect the Apache Web Server with the Liferay Portal Tomcat server, we installed the mod_jk
module in the Apache Web Server. We then configured the Apache Web Server to load the mod_jk
module and provided the mod_jk
configuration parameters. We defined the logfile and shared memory file locations and logfile formats for the mod_jk
module. The most important configuration is to add worker nodes on which we want to distribute the load. We defined this by providing the worker
configuration file. In the worker
configuration file, we defined two Liferay Portal nodes. We then configured the load balancer and added Liferay Portal nodes to it. We configured the load balancer method to Busyness (B) which means, the load balancer will distribute the requests depending upon the load on Liferay Portal Tomcat servers. Other possible load balancer methods include By Requests (distributes the load based on the number of requests and load factor of the worker) and By Traffic (distributes load based on the traffic in bytes and load factor). Finally, we enabled session stickiness. Session stickiness is used to distribute all the requests for a specific session to a specific Liferay Portal Server node. Only in case of failure of the specific node, subsequent requests will be served by the other node. It is very important to use the sticky session feature to save resources. In order to make sure the sticky session functionality works fine, we configured jvmRoute
in both the Tomcat nodes with unique values. The Apache Web Server appends jvmRoute
in the session ID and based on the jvmRoute
value, the Apache Web Server can ensure sending requests to the right Liferay Portal Tomcat node.
Another way to configure the software load balancer using Apache Web Server is through the mod_proxy_ajp
and mod_proxy_balancer
modules. This is a newer approach introduced in Apache Web Server 2.2. It uses the mod_proxy
module and connects the Liferay Portal server using the AJP protocol. Let's understand how to configure the software load balancer using this option.
mod_proxy_ajp.conf
in the <APACHE_HOME>/conf
directory, and add the following content:LoadModuleproxy_modulemodules/mod_proxy.so LoadModule proxy_ajp_module modules/mod_proxy_ajp.so LoadModule proxy_balancer_module /modules/mod_proxy_balancer.so
<VirtualHost *:80> ServerName localhost.localdomain ErrorLog /var/log/apache2/ajp.error.log CustomLog /var/log/apache2/ajp.log combined <Proxy *> AddDefaultCharSet Off Order deny,allow Allow from all </Proxy> ProxyPass / balancer://ajpCluster/ stickysession=JSESSIONID ProxyPassReverse / balancer://ajpCluster/ stickysession=JSESSIONID <Proxy balancer://ajpCluster> BalancerMember ajp://<IP of liferay-node-01>:8009 route=node-01 BalancerMember ajp:// <IP of liferay-node-02>:8009 route=node-02 ProxySet lbmethod=byrequests </Proxy> </VirtualHost>
httpd.conf
file located in the <APACHE_HOME>/conf
directory, and add the following lines at the bottom:Include mod_proxy_ajp.conf
server.xml
file of liferay-node-01
located in node-01liferay-portal-6.1.1-ce-ga2 tomcat-7.0.27conf
, and add the jvmRoute
attribute to the <Engine>
tag as shown here:<Engine defaultHost="localhost" name="Catalina" jvmRoute="node-01">
jvmRoute
parameter in server.xml
of liferay-node-02
. Here the value of jvmRoute
will be node-02
.http://<Apache Web Server IP>
URL.This approach requires the mod_proxy
, mod_proxy_ajp
and mod_proxy_balancer
modules. These modules, by default, ship with the Apache Web Server binary. We enabled them by using the LoadModule
command. We then configured the virtual host for our local instance. In the virtual host configuration, we provided the locations of the logfiles. We added the load balancer using the <Proxy balancer>
tag. Again in the load balancer configuration, we provided the hostname and port of both the Liferay Portal Servers. We also provided the jvmRoute
value using the route
parameter. This parameter must match with jvmRoute
configured in steps 4 and 5. We also configured the load balancing method to By Requests (byrequests
). This load balancing method distributes the load on both the Liferay Portal servers in a round robin manner. We also configured the virtual host to route all the requests to the load balancer using the mod_proxy
configuration. We configured to use session stickiness through the mod_proxy
configuration.
This method is very similar to mod_proxy_ajp
. The only difference here is the load balancer configuration. Here the Apache Web Server and the Liferay Portal Tomcat server will connect using the HTTP or HTTPS protocol. So let's configure the load balancer using this option.
mod_proxy_http.conf
in the <APACHE_HOME>/conf
directory and add the following content:LoadModuleproxy_modulemodules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_balancer_module /modules/mod_proxy_balancer.so
<VirtualHost *:80> ServerName localhost.localdomain ErrorLog /var/log/apache2/http.error.log CustomLog /var/log/apache2/http.log combined <Proxy *> AddDefaultCharSet Off Order deny,allow Allow from all </Proxy> ProxyPass / balancer://httpCluster/ stickysession=JSESSIONID ProxyPassReverse / balancer://httpCluster/ stickysession=JSESSIONID <Proxy balancer://httpCluster> BalancerMember http:// <IP of liferay-node-01>:8080 route=node-01 BalancerMember http:// <IP of liferay-node-02>:8080 route=node-02 ProxySet lbmethod=byrequests </Proxy> </VirtualHost>
httpd.conf
file located in the <APACHE_HOME>/conf
directory and add the following line at the bottom:Include mod_proxy_http.conf
server.xml
file of liferay-node-01
located in node-01liferay-portal-6.1.1-ce-ga2 tomcat-7.0.27conf
, and add the jvmRoute
attribute to the <Engine>
tag as follows:<Engine defaultHost="localhost" name="Catalina" jvmRoute="node-01">
jvmRoute
parameter in server.xml
of liferay-node-02
. Here the value of jvmRoute
will be node-02
.http://<IP of Apache Web Server>
URL.These steps are very similar to the previous option. The only difference is that we are using the HTTP protocol. This connector allows us to establish an encrypted connection between the web server and the Liferay Portal application server using the HTTPS protocol.
We have learned three different methods of configuring the software load balancer using the Apache Web Server. Now let's learn some of the best practices associated with these options:
mod_jk
is most recommended because mod_jk
is a reliable and error free module compared to other options. From the performance point of view it gives the best performance. The mod_proxy_ajp
module is similar to mod_jk
but it is relatively new. If there is a need to use a secured connection between the Apache Web Server and Liferay Portal Tomcat server, we can consider using the mod_proxy_http
module. It provides easy configuration to implement this scenario.<Connector>
tag from the server.xml
file of the Liferay Portal Tomcat server.mod_jk
connector, it is recommended to use the Busyness load balancer method. This will help in distributing requests on Liferay Portal servers with respect to their current load.3.15.137.213