MongoDB Cluster Architecture

Welcome to the blog! Kicking off, here is a short post on setting up a mongoDB sharded cluster:

mongo

In order to set this up you’ll have to perform the following steps:

1. Get mongoDB – http://www.mongodb.org/downloads
2. Untar to some directory e.g. “~/mongoDB”
3. Create data directories:
      mkdir "~/mongoDB/data/"
      mkdir “~/mongoDB/data/configdb1”
      mkdir “~/mongoDB/data/configdb2”
      mkdir “~/mongoDB/data/configdb3”
4. Create mongod config files… (for replicasets 1 conf per node i.e. 3 per set):
      vi ~/mongoDB/etc/mongod1.conf mongod2.conf mongod3.conf
    # Add the following lines to all files – specify different ports:
      port = 27017 #(unique per conf)
#bind_ip = 10.8.0.10 #(default bind on all)
    dbpath = /Users/pondix/mongoDB/data/data1 #(is a unique dir)
    logpath = /Users/pondix/mongoDB/logs/logs1 #(is a unique filename)
    fork = true
    # replSet = rs0  # configure foreach replicaset
Now that you have your mongoDB installed and configured, time to fire up the servers:
1. Add the mongo bin dir to path e.g. export PATH=$PATH:~/mongoDB/current/bin
2. Start config servers:
mongod --fork --configsvr --dbpath ~/mongoDB/data/configdb1/ --port 27001
mongod --fork --configsvr --dbpath ~/mongoDB/data/configdb2/ --port 27002
mongod --fork --configsvr --dbpath ~/mongoDB/data/configdb3/ --port 27003

3. Start mongos (even on app nodes) will run on default port 27017:
mongos --fork --configdb localhost:27001,localhost:27002,localhost:27003
4. Start mongod instances from “~/mongoDB/etc/” (standalone or replicaset):
mongod --fork --config mongod1.conf
mongod --fork --config mongod2.conf
mongod --fork --config mongod3.conf
5. Connect to mongos and add shards:
run “~/mongoDB/bin/mongo”
mongos> sh.addShard(“localhost:27011”)
{ “shardAdded” : “shard0000”, “ok” : 1 }
mongos> sh.addShard(“localhost:27012”)
{ “shardAdded” : “shard0001”, “ok” : 1 }
mongos> sh.addShard(“localhost:27013”)
{ “shardAdded” : “shard0002”, “ok” : 1 }
mongos>
~~~~~~~~
And your mongoDB sharded cluster is ready – note, instead of adding standalone shards as I have, you can setup 3 node replicasets and add these as individual shards.
Advertisements

One comment

  1. pondix82 · December 8, 2013

    And a little script to start up the all the servers:

    #!/bin/bash
    export PATH=$PATH:/home/vyzas/mongoDB/bin

    mongod –fork –configsvr –dbpath /home/vyzas/mongoDB/data/configdb1/ –port 27001
    mongod –fork –configsvr –dbpath /home/vyzas/mongoDB/data/configdb2/ –port 27002
    mongod –fork –configsvr –dbpath /home/vyzas/mongoDB/data/configdb3/ –port 27003

    sleep 3;

    mongos –fork –configdb localhost:27001,localhost:27002,localhost:27003

    sleep 3;

    mongod –fork –shardsvr –config /home/vyzas/mongoDB/etc/mongod1.conf
    mongod –fork –shardsvr –config /home/vyzas/mongoDB/etc/mongod2.conf
    mongod –fork –shardsvr –config /home/vyzas/mongoDB/etc/mongod3.conf

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s