Skip to content

Basic Distributed Setting

Jaewook Byun edited this page May 26, 2016 · 8 revisions

Basic Distributed Setting

It is a minimal distributed setting for MongoDB.

Also, it is just for reference, since each user or developer may have one's event management strategy. (e.g. indexing on timestamp or sharding-key on Mongo object id)

Prepare a sharding

Make a directory for logging as [l]

Make three directories for three mongo daemons as [d1] [d2] [d3]

Make a directory for configuration server as [c]

Run distributed MongoDB

  • [l] : /home/oliot/log

  • [d1] : /home/oliot/MongoRepo/sdb01

  • [d2] : /home/oliot/MongoRepo/sdb02

  • [d3] : /home/oliot/MongoRepo/sdb03

  • [c] : /home/oliot/MongoRepo/sdb04c

# In [Mongo/Bin] folder


./mongod --fork --logpath /home/oliot/log/mongodb1.log --shardsvr --dbpath /home/oliot/MongoRepo/sdb01 --port 10000
./mongod --fork --logpath /home/oliot/log/mongodb2.log --shardsvr --dbpath /home/oliot/MongoRepo/sdb02 --port 20000
./mongod --fork --logpath /home/oliot/log/mongodb3.log --shardsvr --dbpath /home/oliot/MongoRepo/sdb03 --port 30000
./mongod --fork --logpath /home/oliot/log/mongodbc.log --configsvr --dbpath /home/oliot/MongoRepo/sdb04c --port 40000
./mongos --fork --logpath /home/oliot/log/mongodbs.log --configdb localhost:40000 --chunkSize 1

then, you successfully run Mongo Server, you can access Mongo console as follows

>./mongo

Set up Sharding in Mongo console

# In [MongoConsole]
mongos> use admin

# Add 3 Shards

mongos> db.runCommand({addshard:'localhost:10000'});
mongos> db.runCommand({addshard:'localhost:20000'});
mongos> db.runCommand({addshard:'localhost:30000'});

# Make 'epcis' database become sharding-enabled

mongos> db.runCommand({enablesharding:'epcis'});

# Make each collection in 'epcis' database become shard-ed-collection
# In this script, I use sharding-key as Mongo object id

mongos> db.runCommand({shardcollection:'epcis.EventData', key:{_id:1}});
mongos> db.runCommand({shardcollection:'epcis.MasterData', key:{_id:1}});