Liferay Portal Clustering

Liferay Portal can serve everything from the smallest to the largest web sites. Out of the box, it’s configured optimally for a single server environment. If one server isn’t sufficient to serve the high traffic needs of your site, Liferay Portal scales to the size you need.


Liferay Portal works well in clusters of multiple machines (horizontal cluster) or in clusters of multiple VMs on a single machine (vertical cluster), or any mixture of the two. Once you have Liferay Portal installed in more than one application server node, there are several optimizations that need to be made. At a minimum, Liferay Portal should be configured in the following way for a clustered environment:

  1. (Liferay Portal CE only) Build and deploy the cluster modules to all cluster nodes.

  2. All nodes should point to the same Liferay Portal database or database cluster.

  3. Documents and Media repositories must have the same configuration and be accessible to all nodes of the cluster.

  4. Search should be on a separate search server that is optionally clustered.

  5. Cluster Link must be enabled so the cache replicates across all nodes of the cluster.

  6. Hot deploy applications to each node individually.

If you haven’t configured your application server to use farms for deployment, the hot deploy folder should be a separate folder for all the nodes, and plugins will have to be deployed to all of the nodes individually. This can be done via a script. If you do have farms configured, you can deploy normally to any node’s deploy folder, and your farm configuration should take care of syncing the deployment to all nodes.

Many of these configuration changes can be made by adding or modifying properties in your file. Remember that this file overrides the defaults in the file. You can also browse its contents here. It’s a best practice to copy the relevant section you want to modify from into your file, and then modify the values there.

Each step defined above is covered below to give you a step by step process for creating your cluster.

1. All Nodes Should Point to the Same Liferay Portal Database

Each node should have a data source that points to one Liferay Portal database (or a database cluster) that all the nodes will share. This means, of course, Liferay Portal cannot (and should not) use the embedded HSQL database that is shipped with the bundles (but you already knew that, right?). And, of course, the database server should be on a separate system from the server which is running Liferay Portal.

You can also use a read-writer database configuration to optimize your database configuration.

Read-Writer Database Configuration

Liferay Portal allows you to use two different data sources for reading and writing. This enables you to split your database infrastructure into two sets: one optimized for reading and one optimized for writing. Since all Liferay Portal’s supported databases support replication, you can use your database vendor’s replication mechanism to keep the database nodes in sync.

Enabling a read-writer database is simple. In your file:

  1. Set the default database connection pool provider to dbcp, tomcat, or c3po. Note, provider HikariCP does not support read/write splitting. Here’s an example setting:


    All the portal JDBC configuration properties are documented here.

  2. Configure two different data sources for Liferay Portal to use, one for reading, and one for writing:**your user name****your password**
    jdbc.write.username=**your user name**
    jdbc.write.password=**your password**

    To use the JNDI instead of the JDBC data sources, set the *.username and *.password properties above to your JNDI user name and password and set these additional properties:**your read JNDI name****your read-write JNDI name**
  3. Avoid using the default data source, by setting this:


    And if you’re using a dbcp or tomcat database connection pool provider, set these:

    jdbc.default.validationQuery= releaseId FROM Release_
    jdbc.write.validationQuery=SELECT releaseId FROM Release_

    These settings are related to issue LPS-64624.

  4. Enable the read-writer database configuration by uncommenting the following Spring configuration files from the spring.configs and spring.infrastructure.configs properties:


    The Spring configuration portal properties are documented here.

The next time you start Liferay Portal, it uses the two data sources you have defined. Make sure to correctly set up your two databases for replication before starting Liferay Portal.

2. Documents and Media Library Clustering

Liferay Portal’s Documents and Media Library can mount several repositories at a time while presenting a unified interface to the user. By default, users can use the Liferay Portal repository, which is already mounted. This repository is built into Liferay Portal and can use one of several different store implementations as its back-end. In addition to this, users can mount many different kinds of third party repositories. In a cluster, Documents and Media must have the exact same configuration on all nodes. If you have a separate repository you’ve mounted, all nodes of the cluster must point to this repository. Your avenue for improving performance at this point is to cluster your third party repository, using the documentation for the repository you have chosen. If you don’t have a third party repository, you can configure the Liferay Portal repository to perform well in a clustered configuration.

The main thing to keep in mind is you need to make sure that every node of the cluster has the same access to the file store as every other node. For this reason, you must look at your store configuration.

Note that the file systems used by the File System or Advanced File System stores must support concurrent requests and file locking.

3. Clustering Search

Search should always run on a separate environment from your Liferay Portal server. Liferay Portal supports Elasticsearch or Solr, and either of those environments can also be clustered.

For more information on how to cluster Elasticsearch, see Elasticsearch’s distributed cluster setup.

Once Liferay Portal servers have been properly configured as a cluster and the same for Elasticsearch, change Liferay Portal from embedded mode to remote mode. On the first connection, the two sets of clustered servers communicate with each other the list of all IP addresses; in case of a node going down, the proper failover protocols will enable. Queries and indices can continue to be sent for all nodes.

For more information on how to cluster Solr, see Apache Solr Cloud documentation.

Once Liferay Portal servers have been properly configured as a cluster, deploy the Liferay Solr 5 Adapter on all nodes. (This app is available for download from Liferay Marketplace here.) Create a Solr Cloud (cluster) managed by Apache Solr Zookeeper. Connect the Liferay Portal cluster to Zookeeper and finish the final configurations to connect the two clusters.

4. Enable Cluster Link

Enabling Cluster Link automatically activates distributed caching. Distributed caching enables some RMI (Remote Method Invocation) cache listeners that are designed to replicate the cache across a cluster. Cluster Link uses Ehcache, which has robust distributed caching support. The cache is distributed across multiple Liferay Portal nodes running concurrently. The Ehcache global settings are in the file.

By default Liferay does not copy cached entities between nodes. If an entity is deleted or changed, for example, Cluster Link sends an remove message to the other nodes to invalidate this entity in their local cache. Requesting that entity on another node results in a cache miss; the entity is then retrieved from the database and put into the local cache. Entities added to one node’s local cache are not copied to local caches of the other nodes. An attempt to retrieve a new entity on a node which doesn’t have that entity cached results in a cache miss. The miss triggers the node to retrieve the entity from the database and store it in its local cache.

To enable Cluster Link, add this property to

Modifying the Cache Configuration with a Module

It’s recommended to test your system under a load that best simulates the kind of traffic your system needs to handle. If you’ll be serving up a lot of message board messages, your script should reflect that. If web content is the core of your site, your script should reflect that too.

As a result of a load test, you may find that the default distributed cache settings aren’t optimized for your site. In this case, you should tweak the settings yourself. You can modify the Liferay Portal installation directly or you can use a module to do it. Either way, the settings you change are the same. A benefit of working with modules is that you can install a module on each node and change the settings without taking down the cluster. Modifying the Ehcache settings with a module is recommended over modifying the Ehcache settings directly.

We’ve made this as easy as possible by creating the project for you. Download the project and unzip it into a Liferay Workspace, in the workspace’s modules folder. To override your cache settings, you only have to modify one Ehcache configuration file, which you’ll find in this folder structure:

  • src
    • main
      • java
        • resources
          • ehcache
            • override-liferay-multi-vm-clustered.xml

In the sample project, this file contains a configuration for Liferay Portal’s GroupImpl object which handles sites. You may wish to add other objects to the cache; in fact, the default file caches many other objects. For example, if you have a vibrant community, a large portion of your traffic may be directed at the message boards portlet, as in the example above. To cache the threads on the message boards, configure a block with the MBMessageImpl class:


If you’re overriding these properties, it’s because you want to customize the configuration for your own site. A good way to start with this is to extract Liferay’s cluster configuration file and then customize it. You’ll find it in the Liferay Foundation application suite’s com.liferay.portal.cache.ehcache-[version].jar file. You can get this JAR from the Liferay Foundation.lpkg file in the osgi/marketplace folder. The file you want is liferay-multi-vm-clustered.xml, in the /ehcache folder inside the com.liferay.portal.cache.ehcache-[version].jar file. Once you have the file, replace the contents of the override-liferay-multi-vm-clustered.xml file above with the contents of this file. Now you’ll be using the default configuration as a starting point.

Once you’ve made your changes to the cache, save the file, build, and deploy the module, and your settings override the default settings. In this way, you can tweak your cache settings so that your cache performs optimally for the type of traffic generated by your site. You don’t have restart your server to change the cache settings. This is a great benefit, but beware: since Ehcache doesn’t allow for changes to cache settings while the cache is alive, reconfiguring a cache while the server is running flushes the cache.

5. Hot Deploy to All Nodes

If you want to deploy any module or WAR file onto the cluster, it must be deployed to all nodes of the cluster. Because Liferay Portal now installs applications as OSGi bundles, this means you cannot rely on your application server’s means of installing WAR files (even if you only intend to install WAR files) to deploy an application to the entire cluster. Instead, the application must be placed in Liferay Portal’s deploy folder on each node.

This, as you might imagine, can be done with a script. Write a shell script that uploads applications to each node using sftp or some other service. This way, when you deploy an application, it is uploaded to each node’s deploy folder and installed by each running Liferay Portal installation.


Setting up Liferay Portal on a cluster takes five steps:

  1. Point all nodes at the same database or database cluster.

  2. Make sure the Documents and Media repository is accessible to all nodes.

  3. Install Elasticsearch or Solr on a separate system or cluster.

  4. Enable Cluster Link for cache replication.

  5. Hot deploy applications to each node individually.

+1 (1 Vote)
Document Repository Configuration Previous