Thursday, April 3, 2014

MongoDB 2.4 - sharding

- killall mongod
- killall mongos
- cd
- mkdir a0, b0, cfg0
- mongod --shardsvr --dbpath a0 --logpath log.a0 --fork --logappend --smallfiles --oplogSize 50
- Note that with --shardsvr specified the default port for mongod becomes 27018
- mongod --configsvr --dbpath cfg0 --fork --logpath log.cfg0 --logappend
- Note with --configsvr specified the default port for listening becomes 27019 and the default data directory /data/configdb. Wherever your data directory is, it is suggested that you verify that the directory is empty before you begin.
- mongos --configdb your_host_name:27019 --fork --logappend --logpath log.mongos0
- mongo
- sh.addShard('your_host_name:27018')
- sh.enableSharding('databaseName')
- db.collectionName.ensureIndex({a:1,b:1})
- sh.shardCollection('databaseName.collectionName',{a:1,b:1})
- use config
- db.chunks.find()
- db.chunks.find({}, {min:1,max:1,shard:1,_id:0,ns:1})
- exit
- mongod --shardsvr --dbpath b0 --logpath log.b0 --fork --logappend --smallfiles --oplogSize 50 --port 27000
- mongo
- sh.addShard('your_host_name:27000')
- sh.status()
- db.getSisterDB("config").shards.count()

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.