Deploy Liferay DXP on google cloud

 




In this article we will see how to deploy a Liferay DXP cluster in google cloud platform. The reference architecture will look like below. Here I have created a global https load balancer which will distribute the traffic to 2 liferay node in the cluster. I have created an unmanaged instance group for this purpose. I have created 2 Compute engine virtual machine for deploying Liferay DXP. We have used cloud SQL service from gcloud for Liferay schema. Filestore service used for document repository and a separate virtual machine with elastic search installed used as an elastic server.

Lets create these services in google cloud platform. Login to  https://console.cloud.google.com/
with your Gmail account. Google will provide free trial credit worth $300 for 3 month for gcloud which you can play around. Lets create all the gcloud services one by one
  • Create Liferay database using Cloud SQL service :-

Cloud SQL is the managed database services provided by gcloud. you can select MySQL or PostgreSQL or MsSQL for creating the database. Here I am going to select MySQL 8.0 for this exercise.


Provide the below details.
    Instance ID : liferaydb
    Password    : password
    Database version : MySQL 8
    Region : us-central1
    Zonal availability : Single zone
    Specify Zone : us-central1-b (we will create 1 Liferay DXP node on the same zone to minimize the latency)
Under show configuration Options -> Connections -> Instance Ip assignment select private IP checkbox and uncheck public IP checkbox. This will ensure that your DB cannot be exposed outside google VPC network.

Now click on create instance button which will create your Database. Once the database service created click on that liferaydb link and create a liferay schema.


Click on Create Database link and provide below information.
    Database Name : lportal74
    keep the other field default value and create the database. Once the database created you can see it in the list.

  • Create Compute Engine VM instances and deploy Liferay DXP

Now we are going to create 2 virtual machines and deploy liferay DXP on that. 
    Under Compute Engine -> VM instances -> Create instance



provide the following information.
    Name : lrinstance-1
    Region : us-central1
    Zone : us-central1-b (we created vm instance on the same zone where we created databse)
    Machine Configuration
    Series - N1
    Machine-type - n1-standard-4 (this is a machine with 4 vcpu and 15gb memory)

 keep the other fields default value and create instance. Now you have created 1 node, do the same process and create another virtual instance with below information.
    Name : lrinstance-2
    Region : us-central1
    Zone : us-central1-c (this time we created instance in another zone which will ensure high availability)
    Machine Configuration
    Series - N1
    Machine-type - n1-standard-4 (this is a machine with 4 vcpu and 15gb memory)

Now we have completed VM instance setup, now we can deploy liferay dxp on each node.
Connect to one instance using SSH

Install JDK
    sudo apt update
    sudo apt install default-jdk
    java -version

Create a folder named liferay under /opt using below command.
    cd /opt
    mkdir liferay
    cd /liferay

Download Liferay 7.4 CE (here I am downloading CE verison, but clusering to work properly you need to use EE version)
    wget https://github.com/liferay/liferay-portal/releases/download/7.4.3.14-ga14/liferay-ce-portal-tomcat-7.4.3.14-ga14-20220302152058124.tar.gz

Unzip the downloaded tar.gz file
    tar -xvf liferay-ce-portal-tomcat-7.4.3.14-ga14-20220302152058124.tar.gz
    cd liferay-ce-portal-7.4.3.13-ga13

Create a file called portal-ext.properties under liferay home
    touch portal-ext.properties

Add the database connection entries and enable cluster link.
    jdbc.default.driverClassName=com.mysql.cj.jdbc.Driver
    jdbc.default.url=jdbc:mysql://10.95.64.5/lportal74?characterEncoding=
   UTF-8&dontTrackOpenResources=true&holdResultsOpenOverStatementClose=true&
   serverTimezone=GMT&useFastDateParsing=false&useUnicode=true
    jdbc.default.username=root
    jdbc.default.password=password
   cluster.link.enabled=true

IP address highlighted will be the private IP address of your database server created in the first step.
Now you can start the liferay node using the below command.
    tomcat-9.0.56/bin/startup.sh

Open the logs and see the liferay started successfully without issue.
    tail -f logs/liferay.2022-03-05.log

Once the server started successfully you can verify the tables are created under database lrportal74.
For that connect to your DB services from VM using below command.

Install mysql client
    sudo apt install mariadb-client

Connect to your db
    mysql -h 10.95.64.5 -u root -p lportal74
    show tables;

This will list all the liferay generated tables;
Now you can access the liferay instance of this node using external IP address of the virtual machine.
    Eg : http://34.72.227.81:8080

For accessing external request to your VM using external IP address, you have to create a firewall rule to allow request to the port 8080.
Time being create a general firewall rule to access all port from all source IP.
    Under VPC Network -> Firewall Rules -> Create a Firewall Rule


Provide below information to the fields.
    Name : liferay-request-ingress
    Target : All instances in this network
    Source IP V4 ranges : 0.0.0.0/0
    Protocol and Ports : Allow all

Keep the other fields default values and create the firewall rule. Now you can access the liferay node using the external IP address.
We have completed the liferay setup in one node, do the same setup in the second node as well.

  • Create a Document repository using Google File store :-

For clustering to work your two liferay node should be configured to point  a common file location to access and write the files. Google cloud provide a service called Filestore for this.
    Under Storage -> Filestore -> Create instance


Provide the following information
    Instance-id : lr-filestore
    Region : us-central1
    Zone : us-central1-b (select region and zone same as VM instance to minimize the latency)
    Filesharename : lrdata

keep the other fields default value and create the filestore instance.
Once created you have to mount the filestore to your VM instance. Please follow the below command for that.

Install NFS on Debian or Ubuntu
    sudo apt-get -y update && sudo apt-get install nfs-common

Make a local directory to map to the Filestore file share:
    sudo mkdir -p lrfilestore

Open the /etc/fstab file:
    sudo vim /etc/fstab

Add the following line in the /etc/fstab file:
    10.95.65.2:/lrdata /lrfilestore nfs defaults,_netdev 0 0
    (highlighted address is the ip address of the filestore)

Mount everything in /etc/fstab:
    sudo mount -a

For detailed step follow the below link

Now filestore is mounted to our lrfilestore directory in VM instance. Do the same exercise for Node 2 as well.
Now you have to point our both liferay node to lrfilestore. For that login to liferay as admin and navigate to Control panel -> Systemsetting -> File Storage and update Simple File System Store config to /lrfilestore
Restart both liferay nodes, now our liferay nodes are successfully connected to filestore.

  • Configure Elastic Search Server
By default liferay use an embedded elastic server. But when configuring cluster environment
we should configure a remote elastic server instance and point both node to it.

Now we are going to create 1 virtual machines and deploy elastic server on that.
    Under Compute Engine -> VM instances -> Create instance


Provide the following information.
    Name : elastic-search-server
    Region : us-central1
    Zone : us-central1-b 
    Machine Configuration
        Series - N1
        Machine-type - n1-standard-2 (this is a machine with 2 vcpu and 7.5gb memory)

keep the other fields default value and create instance. 

Install JDK
    sudo apt update
    sudo apt install default-jdk
    java -version

Now we have to identify the existing embedded elastic search version used by liferay
and download and install the same version here.

To identify the embedded elastic search version connect to the liferay VM instance and execute
the below command.

    curl 127.0.0.1:9200



Here we got 7.10.2 version. Connect to elastic search server VM instance created and download the elastic-search using below command.
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.2-linux-x86_64.tar.gz

Extract the file
    tar -xvf elasticsearch-7.10.2-linux-x86_64.tar.gz

Move the folder under /opt.

Give permission to your user
    sudo chown <nonrootuser> <unzipped-es-folder> -R

Move to [Elastic Search Home]/bin folder and install below plugins.
    ./elasticsearch-plugin install analysis-icu 
    ./elasticsearch-plugin install analysis-kuromoji 
    ./elasticsearch-plugin install analysis-smartcn 
    ./elasticsearch-plugin install analysis-stempel

Specify cluster name in the [elasticsearch]/config/elasticsearch.yml file.
    cluster.name: LiferayElasticSearch
    network.host: 127.0.0.1 
    http.host: 0.0.0.0

Now we can start the server by executing this command under bin folder.
   ./elasticsearch

Once the server came up you can access the elastic search home page using VM external IP.
For eg : http://34.139.152.158:9200/. The page will look like below.


Now configure our liferay node to point to this remote elastic server instead of the
embedded one. For that login to liferay administration

Under Control Panel -> System settings -> Search -> Elasticsearch7 provide below
information.




    Operation Mode -> REMOTE
    Production Mode Enabled -> Check
    Network Host Addresses -> http://10.142.0.2:9200 (internal address of the elastic search         searver VM)
    Cluster Name : LiferayElasticSearch

Keep the other fields default value and save the settings. Now you can reindex the search indexes.

  • Load Balancer Configuration :-

The last step is to configure a load balancer to handle the incoming request and put your virtual instances behind that. For that we have to create instance group. Here I am going to create two unmanaged instance group and assign our liferay node in that.

Under Compute Engine -> Instance group -> Create Instance Group -> Select New unmanaged instance group


Provide the below information.
    Name : lr-instance-group1
    Region : us-central1
    Zone : us-central1-b
    VM Intances : Select your VM created on us-central1-b location

Create the instance group.

Now create another instance group by providing below information. this time select the other VM.
    Name : lr-instance-group2
    Region : us-central1
    Zone : us-central1-c
    VM Instances : Select your VM created on us-central1-c location

Now you have to create a Load Balancer service.
Under Networking -> Network Services -> Load Balancing -> Create Load Balancer.

Select HTTP(S) Load Balancing






Create a backend service


Provide below information
    Name : lr-backend
    New backend
        Instance group : lr-instance-group-1
        Port numbers : 8080
    Add another backend
        Instance group : lr-instance-group-1
        Port numbers : 8080
    Check Enable Cloud CDN
    Health Check :
    Create Health Check
           Name : lr-instance-health-check
           Protocol : http
           Port : 8080
        Keep other field default value and create health check.
    
    Under Advance configuration
        Session affinity : Client IP
    Keep other fields default value and create the backend.

    Host and path rules 
        Keep default values.

    Frontend Configuration:-
        New Frontend IP and port
            Name : lr-front-end    

        Network Service Tier
            IP address : Create IP address
            Name : lrfrontendip
            and Reserve it.

Now create the load balancer.
Now you can click on the load balancer just created and see the IP address in the Front End section.

Hit on the IP address and your liferay home page will be loaded. Welldone ! we completed and successfully deployed Liferay cluser in Google cloud platform. 

About Author:

I am Deepak Poilil, working as a Liferay Consultant. Having 12 plus year of experience as a software developer, I love design, development and architecture enterprise application using JAVA and JavaScript technologies. Our primary focus to deliver enterprise application with best user experience using the latest technologies and skills currently available in the Market. I always focus on 4 parameters while developing web and system applications, robustness, scalability, reusability and performance.Read More...

Comments

Post a Comment

Popular posts from this blog

React development in Liferay - Overview

Liferay React with Webpack