Using MongoDB | Sharding | Adding Two More Config Servers | Part 2

Posted By : Amit Kumar | 25-Feb-2014

Setup Sharding in MongoDB in Ubuntu With One Shard(3 Mongo Instance as Replica Set),One Router and Three Config Server

Continue from the previous blog “Sharding Part 1” (http://www.oodlestechnologies.com/blogs/Using-MongoDB-%7C-Sharding-%7C-One-Query-Router%2C-One-Config-Server-And-One-Shard-%7C-Part-1) , now in this blog we will add two new config servers.


Initials :

1.)First You must go through the previous blog of this series (http://www.oodlestechnologies.com/blogs/Using-MongoDB-%7C-Sharding-%7C-One-Query-Router%2C-One-Config-Server-And-One-Shard-%7C-Part-1)

2.) In my previous blog i have used only one config server, so we need total three config server(config-1,config-2,config-3)

3.) Make sure you can access each mongo console server from other mongo servers


Configuration for Three Config Server (config-1,config-2,config-3)

In this section i will discuss configuration for three or more Config Server.


Step 1:

First you need to shutdown all mongod processes and mongos i.e close all mongo process from all server. And if don't do this, configuration takes its previous state i.e it cached its old information.


Step 2:

Create directory structure for database in both config-2 and config-3 server.Now issue the following commands on config-2 and config-3 server.

Code Snippet :-

mkdir -p /home/ubuntu/data/configdb


Step 3:

Now generate ssh key of main config server i.e. Config-1 and add its entry into other servers i.e. config-2 and config-3 server. Follow below code to do the same.

Command to be execute in config-1 server.

Code Snippet :-

ssh-keygen 
// and press enter untill it create the ssh key.
cat /home/ubuntu/.ssh/id_rsa.pub
// And after that copy the key code using 

Commands to be execute in both config-2 and config-3 server.

Code Snippet :-

vim /home/ubuntu/.ssh/authorized_keys
// append the copied code in this file in both servers


Step 3:

Now synchronize the database diretory structure or copy the database of config-1 server to config-2 and config-3 server.This command should be execute from config-1 server.

Code Snippet :-

sudo rsync -azvl -e "ssh -l ubuntu -i /home/ubuntu/.ssh/id_rsa" /home/ubuntu/data/configdb/* username@ip-address-of-config-2-machine:/home/ubuntu/data/configdb
sudo rsync -azvl -e "ssh -l ubuntu -i /home/ubuntu/.ssh/id_rsa" /home/ubuntu/data/configdb/* username@ip-address-of-config-3-machine:/home/ubuntu/data/configdb

The above will copy the all database of config-1 server into config-2 and config-3 server. And now they will use same configuration.


Step 4:

Start each mongod instance on Shard i.e(on mongo-1,mongo-2,mongo3 server)

Code Snippet :-

sudo mongod --config /etc/mongodb.conf


Step 5:

Now start all of mongod instance in each config server. Issue the following commands on each config server.

Code Snippet :-

sudo mongod --logpath "config-server.log" --dbpath /home/ubuntu/data/configdb --port 27017 --fork --configsvr


Step 6:

Now Its time to setup query router i.e. mongos server. Issue below command on router-1 and Start the mongos with three config servers.

Code Snippet :-

sudo mongos --logpath "mongo-1.log" --configdb ip-address-of-config-1:27017,ip-address-of-config-2:27017,ip-address-of-config-3:27017 --fork

For more information you can see this MongoDB tutorial for Sharding.

http://docs.mongodb.org/manual/core/sharding/

Thanks

Amit

About Author

Author Image
Amit Kumar

Amit is a bright Groovy and Grails developer and has worked on development of various SaaS applications using Grails framework.

Request for Proposal

Name is required

Comment is required

Sending message..