Cd /home/tiansign/fanr/mongodb/Shard
mkdir configdb1 configdb2 configdb3
mkdir shard1 shard2 shard3
mkdir mongos
dbpath=/home/tiansign/fanr/mongodb/Shard/configdb1
fork = true
logpath=/home/tiansign/fanr/mongodb/Shard/configdb1/config.log
dbpath=/home/tiansign/fanr/mongodb/Shard/shard1
fork = true
logpath=/home/tiansign/fanr/mongodb/Shard/shard1/shard.log
port=27018
dbpath=/home/tiansign/fanr/mongodb/Shard/shard2
fork = true
logpath=/home/tiansign/fanr/mongodb/Shard/shard2/shard.log
port=27021
dbpath=/home/tiansign/fanr/mongodb/Shard/shard3
fork = true
logpath=/home/tiansign/fanr/mongodb/Shard/shard3/shard.log
port=27020
mongod --config /home/tiansign/fanr/mongodb/Shard/configdb1/config.cfg --configsvr
#mongos -f /home/tiansign/fanr/mongodb/Shard/mongos/mongos.cfg
mongos –configdb 127.0.0.1:27019
mongod --config /home/tiansign/fanr/mongodb/Shard/shard1/shard.cfg
mongod --config /home/tiansign/fanr/mongodb/Shard/shard2/shard.cfg
mongod --config /home/tiansign/fanr/mongodb/Shard/shard3/shard.cfg
Mongo
sh.addShard("127.0.0.1:27018")
sh.addShard("127.0.0.1:27021")
sh.addShard("127.0.0.1:27020")
db.settings.save( { _id:"chunksize", value: 1} )
sh.enableSharding("test")
sh.shardCollection("test.joker", {jokes:1});
for (var i=0; i<100000; i++) { db.joker.insert({jokes: Math.random(), count: i, time: new Date()}); }
use config
db.chunks.find({ns: "test.joker"}, {shard:1, _id:0}).sort({shard:1})
{ "shard" : "shard0000" }
{ "shard" : "shard0000" }
{ "shard" : "shard0000" }
{ "shard" : "shard0000" }
{ "shard" : "shard0001" }
{ "shard" : "shard0001" }
{ "shard" : "shard0001" }
{ "shard" : "shard0002" }
{ "shard" : "shard0002" }
{ "shard" : "shard0002" }
sh.addShardTag("shard0000", "mr. j")
sh.addTagRange("test.joker", {jokes:MinKey}, {jokes:MaxKey}, "mr. j")
db.locks.find( { _id : "balancer" } ).pretty()
use config
db.chunks.find({ns: "test.joker"}, {shard:1, _id:0}).sort({shard:1})
{ "shard" : "shard0000" }
{ "shard" : "shard0000" }
{ "shard" : "shard0000" }
{ "shard" : "shard0000" }
{ "shard" : "shard0000" }
{ "shard" : "shard0000" }
{ "shard" : "shard0000" }
{ "shard" : "shard0000" }
{ "shard" : "shard0000" }
{ "shard" : "shard0000" }