Are you looking for scalability (MongoDB) and high availability (oak clustering with replica set)? If so, read on. This post is a first step towards achieving a minimal set-up of an AEM 6.0 cluster with MongoDB in real-life scenarios.
To get the greatest benefit from this blog post, here’s what you’ll need :
With the release of AEM 6.0, clustering has been rethought—resulting in the introduction of “Oak” and the concept of microkernels. Here I'll provide a working example of a minimal AEM 6 (Oak) cluster, similar to the image below. This example implies multiple Oak instances accessing one MongoDB instance. A secondary MongoDB is provided for failover within the same data center.
How Does Oak Clustering Work?
An Oak cluster is formed by two AEM 6.0 instances and a MongoDB for persistence. All these instances are linked together to ensure that if one node fails, the other nodes are active and accessible for your application, with no system interruption. This enables you to easily recover and re-start failed nodes.
Why Do You Need It?
MongoDB offers high availability with replicaSets and scalability with sharding, to support deployments with very large data sets and high throughput operations.
Advantages and Disadvantages
- The ability to scale AEM instances
- Acceptable complexity
- Lesser performance than TarMK
First, set up three instances of MongoDB with replicaSet. For help creating a replicaSet, please refer to this MongoDB tutorial.
After successfully creating the three-node replica set, check the status, either using the rs.status () command in the command line, or using your native browser.
As you can see in this example, a three-node replica set has been configured. This same process can be applied to configuring any number of nodes in a replica set.
Set up the AEM 6.0 servers.
- Take two new AEM 6.0 instances (since we are creating an Oak cluster with two AEM 6.0 instances and one MongoDB).
- Run each of the AEM instances with the following commands.
Note: Make sure that all of the MongoDB instances are up and running. Also check to make sure the replica set status (replicaSet) is active and running with PRIMARY, SECONDARY and arbiter.
java -jar <aem instance jar name> -r crx3,crx3mongo -Doak.mongo.uri=mongodb://<primaryhost>:<port>,<secondaryhost>:<port>/?replicaSet=<replicaSet name>
The actual command would look like this:
java -jar aem-author-4512.jar -r crx3,crx3mongo -Doak.mongo.uri=mongodb://localhost:27017,localhost:27018/?replicaSet=oak-cluster
java -jar aem-author-4513.jar -r crx3,crx3mongo -Doak.mongo.uri=mongodb://localhost:27017,localhost:27018/?replicaSet=oak-cluster
In the above command, two hosts are given in the mongo URI—the first being the PRIMARY and the second being the SECONDARY MongoDB instance for automatic failover.
Note:Initial startup takes some time, so please be patient and monitor the log files of both AEM and MongoDB.
- Once the AEM servers are up, log onto the servers and open the Geometrixx outdoors website for testing.
- Open any of the two AEM servers and open the Geometrixx outdoors website. Try adding/modifying/deleting some content on the pages. These changes will get reflected in the other AEM server instantaneously.
Test the automatic failover
- Shut down the primary MongoDB server (ctl+c).
- Open the Mongo shell of the secondary Mongo instance.
- Now check the replSet status using the rs.status() command or in your native browser.
- The PRIMARY server will shut down and the SECONDARY server will get elected as PRIMARY.
- Open the AEM instance and Geometrixx outdoors website, which should still be working. You should be able to add/modify/delete content.