Skip to content

Instantly share code, notes, and snippets.

@sushilshah
Forked from daniel-roberts-10gen/shardsetuptest
Created January 10, 2013 07:32
Show Gist options
  • Save sushilshah/4500205 to your computer and use it in GitHub Desktop.
Save sushilshah/4500205 to your computer and use it in GitHub Desktop.
//Setup directories
mkdir r1
mkdir r2
mkdir r3
mkdir r4
mkdir r5
mkdir r6
mkdir config
//create replicasets
//First Set (shard 1)
./mongod --port 27017 --dbpath ../data/r1 --replSet dmr
./mongod --port 27018 --dbpath ../data/r2 --replSet dmr
./mongod --port 27019 --dbpath ../data/r3 --replSet dmr
//mongo shell
./mongo --port 27017
cfg = {
"_id" : "dmr",
"version" : 1,
"members" : [
{
"_id" : 0,
"host" : "localhost:27017"
},
{
"_id" : 1,
"host" : "localhost:27018"
},
{
"_id" : 2,
"host" : "localhost:27019"
}
]
}
rs.initiate(cfg)
rs.status();
//insert test data.
db.stuff.insert({data:’xxxxxxxxxxxxxxxxx’});
//Second Set (shard 2)
./mongod --port 27027 --dbpath ../data/r4 --replSet dmr2
./mongod --port 27028 --dbpath ../data/r5 --replSet dmr2
./mongod --port 27029 --dbpath ../data/r6 --replSet dmr2
./mongo --port 27027
cfg = {
"_id" : "dmr2",
"version" : 1,
"members" : [
{
"_id" : 0,
"host" : "localhost:27027"
},
{
"_id" : 1,
"host" : "localhost:27028"
},
{
"_id" : 2,
"host" : "localhost:27029"
}
]
}
rs.initiate(cfg);
rs.status();
//Start the config server
./mongod --configsvr --port 10000 --dbpath ../data/config/
//Start mongos
./mongos --port 20000 --configdb localhost:10000
//from the mongos shell
use admin
sh.addShard('dmr/localhost:27017');
sh.addShard('dmr2/localhost:27027');
sh.enableSharding(‘test’);
sh.shardCollection('test.stuff',{'_id':1}); //Default ObjectId() _id values are generally a bad idea for shard keys.
mongos> use config
switched to db config
mongos> db.settings.find()
{ "_id" : "chunksize", "value" : 64 }
mongos> db.settings.save({"_id" : "chunksize", "value" : 1 }) //Only set to one for testing.
mongos> db.settings.find()
{ "_id" : "chunksize", "value" : 1 }
mongos>
//Make sure you are pointing at the correct database.
use test
//Insert lots of data
for(i=0;i<100000;i++) {
db.stuff.insert({data:'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment