Sunday, July 4, 2021

Liferay Portal Apache Webserver Integration

Install Apache webserver

Enable mod_jk apache module

Install Liferay

Modify Liferay tomcat server configuration

Configure mod_jk and worker properties

Verify Integration

 

Objective of this article to demonstrate integration of Apache webserver and Liferay Portal server. It will provide complete information on enable load balance among Liferay portal servers from apache webserver. We will use mod_jk apache tomcat connector to enable communication and load balance between apache webserver and Liferay portal tomcat server.


To replicate environment in single machine, I will run two Liferay portal instances on two different http and AJP ports. AJP ports will be used for communicate with apache webserver.

 

Software’s and Tools


Apache 2.4

Windows 10

Liferay 7.4

 

 







Install Apache webserver



Download latest Apache webserver from Apache Haus website and install in machine.

Follow below article to install Apache webserver in windows 10 machine.

http://www.liferaysavvy.com/2021/07/install-apache-webserver-in-windows.html

 

Enable mod_jk apache module

 

We will use mod_jk module to communicate between apache webserver and application server through AJP protocol.


Follow below article to enable mod_jk module in Apache webserver.


http://www.liferaysavvy.com/2021/07/enable-modjk-module-in-apache-webserver.html

 

Install Liferay


Download latest Liferay portal community edition from following Liferay website.


Liferay and tomcat server comes with bundle so we can download Liferay tomcat portal bundle from below link.


https://www.liferay.com/downloads-community





 

Download Liferay 7.4 CE tomcat bundle from above download page.


We are going start two instances, so we have to extract the bundle two different directories.


Extract the 7z file rename directory name to “liferay-ce-portal-7.4.1-ga2-node1


Extract one more time and rename directory to “liferay-ce-portal-7.4.1-ga2-node2





 

 

Modify Liferay tomcat server configuration



It’s required to change http connector port, Server port, Redirect ports and AJP connector port in tomcat server.xml file as we are running both instances in same machine. In the real-world case, we run only portal server instance per machine most of the times.


Liferay Node1 Configuration


Server.xml


Open Liferay portal node1 server.xml file and update ports.




Server port













 

<Server port="8006" shutdown="SHUTDOWN">

 

 

Http connector





 

<Connector port="8090" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" URIEncoding="UTF-8" />

 

 


AJP Connector









 

<!-- Define an AJP 1.3 Connector on port 8009 -->

   

    <Connector protocol="AJP/1.3"

               address="0.0.0.0"

               port="8009"

               redirectPort="8443" URIEncoding="UTF-8" secretRequired="false"/>

 

 


Update “jvmRoute” value in server.xml and it should be unique value.

 







Context.xml


Update Node1 conext.xml file and add “sessionCookieName” for context. This will distinguish node values when you access in browser. We can identify which node request is serving. Default value is JSESSIONID but I have changed to LRSESSIONID.

 


 









liferay-ce-portal-7.4.1-ga2-node1



 

AJP port: 8009

HTTP Port: 8090

Server Port: 8006

Redirect Port: 8443

jvmRoute: liferay-node1

sessionCookieName: LRSESSIONID

 

 

 

Liferay Node2 Configuration


Server.xml


Open Liferay portal node2 server.xml file and update ports.


 



 

Server port





 

<Server port="8005" shutdown="SHUTDOWN">

 

 


Http connector





 

<Connector port="8091" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="7443" URIEncoding="UTF-8" />

 

 

AJP Connector







 

<!-- Define an AJP 1.3 Connector on port 7009 -->

   

    <Connector protocol="AJP/1.3"

               address="0.0.0.0"

               port="7009"

               redirectPort="7443" URIEncoding="UTF-8" secretRequired="false"/>

 

 

Update “jvmRoute” value in Node2 server.xml and it should be unique value.

 




Context.xml


Update Node2 conext.xml file and add “sessionCookieName” for context. This will distinguish node values when you access in browser. We can identify which node request is serving. Default value is JSESSIONID but I have changed to LRSESSIONID.

 








liferay-ce-portal-7.4.1-ga2-node2


 

AJP port: 7009

HTTP Port: 8091

Server Port: 8005

Redirect Port: 7443

jvmRoute: liferay-node2

sessionCookieName: LRSESSIONID

 

 

 

Configure mod_jk and worker properties


Apache used the mod_jk module to connect with tomcat server through AJP ports.


Its required to create worker.properties file in the apache configuration and need to defined two workers. We are running two tomcat servers so its required two worker properties. We use the mod_jk load balancer to traffic requests between two tomcat servers.


Create worker.properties file in Apache conf directory.





 

Add following worker properties in worker.properties file.

 

 

 

#Define the list of workers you have

worker.list=jkstatus,loadbalancer

 

# Set LOADBALANCER

worker.loadbalancer.type=lb

worker.jkstatus.type=status

 

# List Liferay Tomcat Server's in the cluster

worker.loadbalancer.balance_workers=liferay-node1,liferay-node2

worker.loadbalancer.sticky_session=1

 

# Set Worker

 

# Liferay Portal Server Node1

worker.liferay-node1.port=8009

worker.liferay-node1.host=localhost

worker.liferay-node1.type=ajp13

worker.liferay-node1.lbfactor=1

 

# Liferay Portal Server Node2

 

worker.liferay-node2.port=7009

worker.liferay-node2.host=localhost

worker.liferay-node2.type=ajp13

worker.liferay-node2.lbfactor=1

 

 

 


We have defined two workers “liferay-node1 and liferay-node2” and these names should match with “jvmroute” attribute value in tomcat server.xml file.


Ports should match with AJP port value in tomcat server.xml and host name are server host names in our case its localhost


sticky_session value 1 make sure its always go to same node when application need session management.


Update mod_jk configuration in Apache. We already enabled mod_jk module and open mod_jk.conf and update with below configuration.




Mod_jk.conf configuration



Its required to load worker.properites and JkMount /* value should match with “worker.list” value “loadbalancer” in worker.properties.

 


 

 

LoadModule jk_module "${SRVROOT}/modules/mod_jk.so"

 

<IfModule jk_module>

    JkWorkersFile ${SRVROOT}/conf/workers.properties

    JkLogFile "${SRVROOT}/logs/mod_jk.log

    JkLogStampFormat "[%b %d %Y - %H:%M:%S] "

    JkRequestLogFormat "%w %V %T"

    JkLogLevel info

    JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

    JkMount /* loadbalancer

</IfModule>

 

 

 

 

Verify Integration


Start Apache Server


Open window command prompt locates to Apache24 bin directory and run httpd.exe

 





Start Liferay Portal Servers



Open command prompt locates the Liferay Portal tomcat bin directory and run startup.bat and it will launch server console.

 

Liferay Node1 Startup


 

 

C:\Liferay\Liferay74\liferay-ce-portal-7.4.1-ga2-node1\tomcat-9.0.43\bin>startup.bat

 

 

 

Liferay Node2 Startup



 

 

C:\Liferay\Liferay74\liferay-ce-portal-7.4.1-ga2-node2\tomcat-9.0.43\bin>startup.bat

 

 

 




Access below URL and make sure Liferay Portal Node1 started successfully.


http://localhost:8090/

 

Access below URL and make sure Liferay Portal Node2 started successfully.


http://localhost:8091/


Access Liferay portal with below URLs in browser and LRSESSIONID specify the node name. Browser inspect element can see the LRSESSIONID. If we observer the URL does not have port number so it confirms that configuration is working as expected.

 

http://localhost/;LRSESSIONID=abc.liferay-node1




 

http://localhost/;LRSESSIONID=abc.liferay-node2

 



 

References

 

https://tomcat.apache.org/connectors-doc-archive/jk2/jk/workershowto.html

 

 

Notes


When you access portal first time it will ask you to complete basic configuration and follow the steps.


Objective of this article showing mod_jk connecting to Liferay portal servers and each instance start with default HSQL database. Ideally all instances should connect with same database.


We are running two Liferay Portal instances same machine so we may see embedded elastic server port issue in one of the instance logs. Ideally, we will use remote elastic search instead of embedded elastic search.


Static content is still serving from Portal Tomcat server but real work application all static content is serving from Apache webserver.


There are many mod_jk properties existed and refer apache or tomcat documentations for more information.


Author

Enable mod_jk module in Apache Webserver

Apache mod_jk module uses for communication between Apache webserver and tomcat application server.


Most of the real-world applications are multi-tier applications and application server always behind the web servers. It will improve application performance and better way of handle load balance between application servers.


Generally, all static content requests serve by webserver and if any dynamic request, then only it will go to application servers such a way it will improve application performance.

 

OS: Windows 10

Webserver: Apache2.4

 

Pre-Requisite


Install Apache server


http://www.liferaysavvy.com/2021/07/install-apache-webserver-in-windows.html

 

Download mod_jk module

 

Apache is providing tomcat connectors that is mod_jk from following website. Download binary version of mod_jk module. We can also build mod_jk from source. All apache modules have extension *.so. Apache Haus is also proving binary version of apache modules.


http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/windows/





Download “tomcat-connectors-1.2.40-windows-x86_64-httpd-2.4.x.zip” from above download page or use direct link below.


http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/windows/tomcat-connectors-1.2.40-windows-x86_64-httpd-2.4.x.zip


Extract “tomcat-connectors-1.2.40-windows-x86_64-httpd-2.4.x.zip” it contains “mod_jk.so” file.





 

 

 

Copy “mod_jk.so” file to Apache24 module directory





 

Load Module

 

Create mod_jk configuration file in apache conf extra directory “C:\Apache2441\conf\extra” and add load module configurations as follows. Configuration also covered log location and its format.



LoadModule jk_module "${SRVROOT}/modules/mod_jk.so"

<IfModule jk_module>

    JkLogFile ${SRVROOT}/logs/mod_jk.log

    JkLogStampFormat "[%b %d %Y - %H:%M:%S] "

    JkRequestLogFormat "%w %V %T"

    JkLogLevel info

    JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

</IfModule>


 



Include “mod_jk” configuration in httpd.conf


Open “httpd.conf” file in the apache conf directory and include “mod_jk” configuration as follows.





 

# mod_jk configurations

Include conf/extra/mod_jk.conf

 

 

Start Apache


Once enabled the mod_jk module, start/restart server. Access default page in browser.


http://localhost/

 




Verify mod_jk loading


Once apache is started successfully you can see mod_jk.log file in the apache logs directory. If you open the logs we can see below message for successful loading of module or we can see error information.

mod_jk/1.2.40 initialized




 

Author

 

 

 

 

Install Apache Webserver in Windows

 

Download Apache for windows


Apache Haus is providing windows version of webserver binaries and its required modules.

Following is Apache Haus website download page and can download apache webserver for windows.

https://www.apachehaus.com/cgi-bin/download.plx






OS: Windows 10

Current installation demonstrated for Windows 10 OS. Download “httpd-2.4.48-o111k-x64-vs16.zip” from above download page.

Direct Link is below

https://www.apachehaus.com/downloads/httpd-2.4.48-o111k-x64-vs16.zip

 

Extract


Once downloaded binary version of Apache web server for windows 10 extract in your local machine. It contains root directory Aapche24.

Copy Apache24 directory to your system C:/ Drive




Start Apache


Open window command prompt locates to Apache24 bin directory and run httpd.exe




 

Verify installation


Access localhost form the browser and it render “Apache Haus” default webpage and it confirms that you have successfully installed Apache Web server in your local windows machine.


http://localhost/




 

Notes:


Apache installation is required Visual Studio 2017 (VC15) or Visual Studio 2019 (VS16).

Visual Studio 2019 (VS16) compatible Apache version is “httpd-2.4.48-o111k-x64-vs16.zip

Visual Studio 2017 (VC15) compatible Apache version is “httpd-2.4.48-o111k-x64-vc15.zip


References


https://www.apachehaus.com/cgi-bin/download.plx


Author

Recent Posts

Recent Posts Widget

Popular Posts