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:
- 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.
- 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.
- 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.
- Create the new portal-ext.properties file in the home folder. Enter the following line there:
- 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.
- 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:
- Set up several (two or more) new similar environments with MySQL database in each of them, like we performed for master-slave mode.
- When the databases are configured, create the new users (e.g. liferayone andliferaytwo) and databases with the same name for each of shards.
- 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 portal-ext.properties file. Add the following string to this new file:
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:jdbc.one.driverClassName=com.mysql.jdbc.Driver
- To apply the performed configurations save the changes and click the Restart nodebutton for Tomcat.