OpenSource For You

It’s Easy to Scale Out a Mongo DB Deployment

MongoDB is a unique NoSQL open source database, which is scalable and adaptable. It is an applicatio­n of choice for many Fortune 500 companies and start-ups alike. In this, our second article in the series on MongoDB, discover how to scale out a MongoDB d

-

MongoDB is a big name among NoSQL databases. One of its most significan­t features is that you can scale out your deployment­s quite easily, i.e., additional nodes can easily be added to the deployment to distribute data between them so that all data needn’t be stored in one node. This concept is known as sharding, which when combined with replicatio­n, offers great protection against failover. So let’s take a closer look at sharding and how it can be implemente­d.

I assume that you have MongoDB installed on your system. Well, just in case I am wrong, you can get it from http://www.mongodb.org/downloads. Download the zip file as per your operating system and extract the files once the download is completed. For this article, I am using MongoDB on a 32-bit Windows 7 system. Under the extracted directory, you will see a number of binary files. Among them, mongod is the server daemon and mongo is the client process.

Let’s start the process by creating a lot of data directorie­s that will be used to store data files. Now switch to the MongoDB directory that you extracted earlier. I have put that directory on my desktop ( Desktop\mongodb-win32-i386-2.6.0\ bin). So I’ll open a command prompt and type:

cd Desktop\mongodb-win32-i386-2.6.0\bin.

Let’s create the required directorie­s, as follows: mkdir .\data\shard_1 .\data\shard_2 mkdir .\data\shard_1\rs0 .\data\shard_1\rs1 .\data\shard_1\rs2 mkdir .\data\shard_2\rs0 .\data\shard_2\rs1 .\data\shard_2\rs2

Here we’ve created directorie­s for two shards, with each having a replica set consisting of three nodes. Let’s move on to creating the replica sets. Open another command prompt and type the following code: mongod --port 38020 --dbpath .\data\shard_1\rs0 --replSet rs_1 --shardsvr

This creates the first node of the first replica set rs_1, which will be using port 38020 and .\data\shard_1\rs0 as data directory. The --shardsvr option indicates that sharding will be implemente­d for this node. Since we’ll be deploying all the nodes in a single system, let’s just change the port number for additional nodes. Our first node is now ready and it’s time to

Newspapers in English

Newspapers from India