@ -5,22 +5,32 @@ In this example we demonstrate how we can orchestrate the deployment of a produc
1) Deploying a N node MongoDB cluster, which has N shards and N replication nodes.
2) Scale out capability. Expand the Cluster by adding nodes to the cluster.
3) Security, All the mongodb process are secured using the best practices.
###Deployment Architecture.
To better explain the deployment architecture let's take an example where we are deploying a 3 node MongoDB cluster ( Minimum recommended by MongoDB).
The way Ansible configures the three nodes is as follows:
1) Install the mongodb software on all nodes.
2) Creates 3 replication sets, with one primary on each node and the rest two acting as secondaries.
3) Configures MongodDB configuration servers as listed in the inventory section[mongocservers]. Recommended number is 3, so it can be the same three servers as the datanodes.
3) Configures MongodDB configuration DB servers as listed in the inventory section[mongocservers]. Recommended number is 3, so it can be the same three servers as the datanodes.
4) Configures a Mongos server as listed in the inventory file [mongosservers].
5) Adds 3 Shards each belonging to individual relocation sets.
5) Adds 3 Shards each belonging to individual replication sets.
6) All the processes, mongod,mogos are secured using the keyfiles.
Once the cluster is deployed, if we want to scale the cluster, Ansible configures it as follows:
1) Install the MongoDB application on the new node.
2) Configure the replication set with primary as the new node and the secondaries as listed in the inventory file [replicationservers]. ( don't forget to add the new node also in the replicationservers section]
3) Adds a new shard to the mongos service pointing to the new replication set.
###The following example deploys a three node MongoDB Cluster
@ -31,19 +41,19 @@ The inventory file looks as follows:
[mongoservers]
mongo1
mongo2
mongo3
mongo3
#The list of servers where replication should happen, by default include all servers
[replicationservers]
mongo1
mongo2
mongo3
mongo3
#The list of mongodb configuration servers, make sure it is 1 or 3
[mongocservers]
mongo1
mongo2
mongo3
mongo3
#The list of servers where mongos servers would run.
[mongosservers]
@ -53,7 +63,7 @@ Build the site with the following command:
ansible-playbook -i hosts site.yml
##Verification
###Verifying the deployed MongoDB Cluster
Once completed we can check replication set availibitly by connecting to individual primary replication set nodes, 'mongo --host <iphost> --port <portnumber>
and issue the command to query the status of replication set, we should get a similar output.
@ -105,10 +115,74 @@ and issue the following command to get the status of the Shards.
We can also make sure the Sharding works by creating a database and collection and populate it with documents and check if the chunks of the collection are balanced equally across nodes.
The above mentioned steps can be tested as follows:
1) Once the Sharded cluster is ready, create a new database and an admin user for the database. This is done from the mongos machine.
2) Once the DB and the user is created, create a collection and poplulate documents, This deployment add a script to the /tmp location of the mongos server which adds a new collection and 100,000 documents.