Deploy Liferay DXP on google cloud
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 :-
- 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.
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.
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 environmentwe 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-serverRegion : us-central1Zone : us-central1-bMachine ConfigurationSeries - N1Machine-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 JDKsudo apt updatesudo apt install default-jdkjava -versionNow we have to identify the existing embedded elastic search version used by liferayand download and install the same version here.To identify the embedded elastic search version connect to the liferay VM instance and executethe below command.curl 127.0.0.1:9200Here 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.gzExtract the filetar -xvf elasticsearch-7.10.2-linux-x86_64.tar.gzMove the folder under /opt.Give permission to your usersudo chown <nonrootuser> <unzipped-es-folder> -RMove 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-stempelSpecify cluster name in the [elasticsearch]/config/elasticsearch.yml file.cluster.name: LiferayElasticSearchnetwork.host: 127.0.0.1http.host: 0.0.0.0Now we can start the server by executing this command under bin folder../elasticsearchOnce 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 theembedded one. For that login to liferay administrationUnder Control Panel -> System settings -> Search -> Elasticsearch7 provide belowinformation.Operation Mode -> REMOTEProduction Mode Enabled -> CheckNetwork Host Addresses -> http://10.142.0.2:9200 (internal address of the elastic search searver VM)Cluster Name : LiferayElasticSearchKeep 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 groupName : lr-instance-group1Region : us-central1Zone : us-central1-bVM Intances : Select your VM created on us-central1-b locationCreate the instance group.Now create another instance group by providing below information. this time select the other VM.Name : lr-instance-group2Region : us-central1Zone : us-central1-cVM Instances : Select your VM created on us-central1-c locationNow you have to create a Load Balancer service.Under Networking -> Network Services -> Load Balancing -> Create Load Balancer.Select HTTP(S) Load BalancingCreate a backend serviceName : lr-backendNew backendInstance group : lr-instance-group-1Port numbers : 8080Add another backendInstance group : lr-instance-group-1Port numbers : 8080Check Enable Cloud CDNHealth Check :Create Health CheckName : lr-instance-health-checkProtocol : httpPort : 8080Keep other field default value and create health check.Under Advance configurationSession affinity : Client IPKeep other fields default value and create the backend.Host and path rulesKeep default values.Frontend Configuration:-New Frontend IP and portName : lr-front-endNetwork Service TierIP address : Create IP addressName : lrfrontendipand 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.
Wow..Amazing Deepak..Dedicated Person as always..
ReplyDelete