@ -25,13 +25,20 @@ The way Ansible configures the three nodes is as follows:
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:
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 the new shard to the mongos service pointing to the new replication set.
3) Adds a new shard to the mongos service pointing to the new replication set.
#### Pre-Requesites
1) Update the group_vars/all file which contains site specific parmaters, especially the section which contains the mapping of the hostname's and the ports that it should use for the mongod process. Please do make sure the ansible hostname matches the same. Also dont forget to add the variable when adding a new node.
2) The default directory for storing data is /data, please do change it if requried, also make sure it has sufficient space 10G recommended.
###The following example deploys a three node MongoDB Cluster
@ -41,19 +48,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
#The list of servers where replication should happen, including the master server.
[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]
@ -115,53 +122,17 @@ 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:
###We can also make sure the Sharding works by creating a database,collection and populate it with documents and check if the chunks of the collection are balanced equally across nodes.
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.
The above mentioned steps can be tested with an automated playbook.
Issue the following command to run the test. In variable passed make sure the servername is one of any mongos server.
mongos> db.addUser('admin','123456')
{
"user" : "admin",
"readOnly" : false,
"pwd" : "95ec4261124ba5951720b199908d892b",
"_id" : ObjectId("51519f349cd3a93ca7e17909")
}
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.
4) In the above example we can see the chunks being balanced across nodes. After a few minutes if we excute the same command 'sh.status()'
we will see the below output, which shows all the chunks being balanced across the three nodes.
Once the playbook completes, we check if the shadring has succeded by logging on to any mongos server and issuing the following command. The output display the number of chunks spread across the shards.
mongos> sh.status()
--- Sharding Status ---
@ -191,20 +162,20 @@ To add a new node to the configured MongoDb Cluster, setup the inventory file as
[mongoservers]
mongo1
mongo2
mongo3
mongo3
mongo4
#The list of servers where replication should happen, by default include all servers
#The list of servers where replication should happen, make sure the new node is listed here.
[replicationservers]
mongo4
mongo1
mongo2
mongo2
#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.