Created
August 19, 2013 06:59
-
-
Save jiangzhuo/6266351 to your computer and use it in GitHub Desktop.
HOWTO create mongoDB Sharding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create config database | |
E:\MongoDB\bin\mongod.exe -dbpath "E:\MongoDB\dbs\config" -port 20000 -logpath "E:\MongoDB\logs\config" --serviceName "MongoDBConfig" --serviceDisplayName "MongoDBConfig" --configsvr --install | |
//create shard1 database | |
E:\MongoDB\bin\mongod.exe -dbpath "E:\MongoDB\dbs\shard1" -port 27018 -logpath "E:\MongoDB\logs\shard1" --serviceName "MongoDBShard1" --serviceDisplayName "MongoDBShard1" --shardsvr --install | |
//create shard2 database | |
E:\MongoDB\bin\mongod.exe -dbpath "E:\MongoDB\dbs\shard2" -port 27019 -logpath "E:\MongoDB\logs\shard2" --serviceName "MongoDBShard2" --serviceDisplayName "MongoDBShard2" --shardsvr --install | |
//create mongos | |
E:\MongoDB\bin\mongos.exe -port 30000 -configdb localhost:20000 -logpath "E:\MongoDB\logs\mongos" -serviceName "MongoDBRouter" --install | |
//start service | |
net start MongoDBConfig | |
net start MongoDBShard1 | |
net start MongoDBShard2 | |
net start MongoDBRouter | |
//config mongos | |
E:\MongoDB\bin\mongo -port 30000 | |
mongos>sh.addShard("127.0.0.1:27018") | |
mongos>sh.addShard("127.0.0.1:27018") | |
//add admin | |
mongos>use admin | |
mongos>db.addUser("UserName","Password") | |
//create a database you will use | |
//enable sharding for DB | |
mongos>sh.enableSharding("yourDBName") | |
//enable sharding for Collection | |
mongos>sh.shardCollection("yourDBName.youCollectionName"{"KeyName":1}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment