Setting Up Clustering for the Liferay Service
Because Delectable Bonsai’s website draws millions of views, it must be clustered to handle the traffic. Here, you’ll learn how to configure a two-node cluster of the production environment.
You must have an extra Liferay DXP instance provisioned as an add-on for your Liferay Cloud project so that you can cluster your Liferay service and add another node to it. Contact your Liferay account manager for details.
Set the Clustering Properties in LCP.json
Enable clustering and set the scale value in your Liferay service’s configuration.
-
In your project repository, navigate to the
liferay/
directory and open theLCP.json
file. -
Add the
LCP_PROJECT_LIFERAY_CLUSTER_ENABLED
environment variable if it is not present. Set the value totrue
.{ "env": { "LCP_PROJECT_LIFERAY_CLUSTER_ENABLED": "true" } }
-
Add the
scale
property with a value of1
. This sets the number of nodes, which you’ll update later.{ "kind": "Deployment", "id": "liferay", "scale": 1 }
-
Run the Gradle task to create the custom Dockerfile for your Liferay service.
./gradlew clean createDockerfile deploy
-
Copy the
LCP.json
file into the newly createdbuild/docker
folder before deploying the build.cp LCP.json build/docker
cd build/docker
-
Use the CLI tool’s
lcp deploy
command to deploy only the Liferay service.lcp deploy --project=[project-name] --environment=prd
The Liferay service restarts with clustering enabled and the scale
variable initialized. However, the scale is still set to one node only. Continue to update the scale to the desired two nodes.
Update the Clustering Scale
Now that you have initialized the clustering scale, update it to two nodes and create a new build to deploy it.
-
In your project repository, navigate to the
liferay/
folder and open theLCP.json
file. -
Update the value of the
scale
property to2
.{ "kind": "Deployment", "id": "liferay", "scale": 2 }
-
Commit and push the changes to your Git repository.
git add liferay/LCP.json
git commit -m "Enable clustering and set the clustering scale to 2."
git push origin [branch_name]
The updated clustering configuration is now committed, and the Liferay Cloud infrastructure automatically creates a build with it.
Deploy the Configuration
Now that you have the necessary configuration for clustering, deploy the configuration to your environment.
-
Log into the Liferay Cloud console.
-
Click Builds at the top-right of the screen to access the Builds page.
-
Click the Actions menu for the build corresponding to the commit with your new changes, and select Deploy build to…
-
Select your production environment in the Environment drop-down menu.
-
Check the boxes acknowledging the impacts of the deployment.
-
Click Deploy Build.
Once your services restart, clustering is enabled, and you have two nodes of the Liferay service.
Next: configure the Liferay service to auto-scale for even more instances when they are needed.