Liferay Clustering

Liferay Portal is one of the most widely used Content Management Systems for Java. It is highly suitable for the Jelastic scaling capabilities as it supports both vertical and horizontal scaling (i.e. working in vertical and horizontal clusters) and even their mix.

In the scheme below you can see the Liferay clustering architecture with Jelastic platform hosting:

As you can see in the picture, for creating a Liferay cluster we use two Tomcat application servers with two replicated databases (MySQL in our case). The NGINX-balancer node will be added automatically in front of our cluster in order to handle and distribute all incoming requests between the nodes.

So, let's examine how to set up our own Liferay clustered environment. Just come through the steps of the following instruction.

A. Liferay Portal deployment

Follow this instruction in order to create a new environment and deploy the Liferay Portal to it.

B. Database configuration

There are to database modes, which you can use for your clustered Liferay environment. The first is master-slave configuration. And the second one is database sharding. We'll inspect both of them.

Master-slave configuration of the database

Using this database mode means that you have two different database instances i.e. the database infrastructure is splitted into two blocks. For this example we will use the MySQL database replication, as it provides some additional benefits, such as quick response to the requests, fail-over capabilities and system administration. The only small disadvantage of this mode is that using two databases means increasing of the resources consumption.

To enable and configure database master-slave replication just follow the next steps:

  1. Set up two new similar environments (for example, liferayread and liferaywrite) withMySQL node in each of them. Perform a few simple configurations described in theMySQL/MariaDB master-slave replication document.

  2. When both of your databases are configured, log in to the admin panel of the master database (named liferaywrite) and create a new user and database with liferayname.

  3. Then navigate back to the Jelastic platform dashboard and open the configuration manager for Tomcat application server by clicking the Config button next to it.

  4. Create the new file in the home folder. Enter the following line there:

  5. resource.repositories.root=${user.home}/liferay

  6. Then configure two data sources for Liferay in the same file using the following strings. In such a way you'll enable the read-writer database.

  7. jdbc.default.driverClassName=com.mysql.jdbc.ReplicationDriver

  8. Finally, save the changes you've made and restart the Tomcat server.

Database sharding configuration

With the database sharding you can divide DB by different types of data, which can be stored in it. Using this mode decreases the amount of data, which should be handled by the application. The only disadvantage you can meet that this method can't ensure adequate fail-over capabilities.

To configure database sharding for Liferay use the next instruction:

  1. Set up several (two or more) new similar environments with MySQL database in each of them, like we performed for master-slave mode.

  2. When the databases are configured, create the new users (e.g. liferayone andliferaytwo) and databases with the same name for each of shards.

  3. Navigate to the Tomcat home folder in the configuration manager (to open it press the Config button next to the Tomcat instance) and create there a new file. Add the following string to this new file:

  4. shard.selector=com.liferay.portal.dao.shard.RoundRobinShardSelector

    This will allow you to use the round robin shard selector, which is the default sharding algorithm in Liferay. 4. In the same file set your different database shards:{your_first_database_environment_name}.{hoster's_domain}/lportalone?useUnicode=true&characterEncoding=UTF-8{your_database_user_name}{your_database_password}

  5. To apply the performed configurations save the changes and click the Restart nodebutton for Tomcat.

C. Run Liferay

Press the Open in browser button for your Liferay environment and go throughout the opened installation wizard.

D. Cluster configuration

Finally, let's configure the cluster, just a few steps remained.

  1. Press Change environment topology button next to your Liferay cluster environment.

  2. In the opened wizard enable the High Availability. Set up the amount of resources for automatically added NGINX-balancer node (as it was mentioned above, it will handle and distribute all the requests in front of your cluster).

  3. Note: HA was enabled after the Liferay installation have been completed in order to automatically copy the created file (home/liferay path) to the second instance and in such a way avoid the double installation.

    That's all! Now you have your own Liferay clustered environment with fail-over capabilities (if the first node fails, the second one perform the further processing) and great performance. Enjoy!