- Config Server (3 member replica set):
cfgsvr1, cfgsvr2, cfgsvr3
- 3 Shards (each a 3 member replica set):
shard1svr1, shard1svr2, shard1svr3
shard2svr1, shard2svr2, shard2svr3
shard3svr1, shard3svr2, shard3svr3
- Router (mongos):
router
-
Cloud Server 1
docker-compose -f docker-compose1.yml -d
-
Cloud Server 2
docker-compose -f docker-compose2.yml -d
-
Cloud Server 3
docker-compose -f docker-compose3.yml -d
-
Cloud Router (Application Cloud)
docker-compose -f docker-router.yml -d
- Config Server
docker exec -it cfgsvr1
mongo < /scripts/init-configserver.js
- Shard1
docker exec -it shard1svr1
mongo < /scripts/init-shard1.js
- Shard2
docker exec -it shard2svr1
mongo < /scripts/init-shard2.js
- Shard3
docker exec -it shard3svr1
mongo < /scripts/init-shard3.js
- Router
docker exec -it router
mongo < /scripts/init-router.js
docker exec -it router
mongo
- Check status
router> sh.status()
sh.enableSharding("dbName")
sh.shardCollection( "dbName.myCollections", {"field": 1, ...} )
sh.shardCollection( "dbName.myCollections", {"field": "hashed", ...} )
Ex:
sh.shardCollection( "dbName.users", { _id: "hashed" } )
sh.shardCollection( "dbName.invoices", { tranType: "hashed", tranDate: "hashed" } )
- Create Collection Index
db.myCollections.createIndex({"field": "hashed"})
- Sharding Collection
sh.shardCollection( "dbName.myCollections", {"field": "hashed"} )
db.myCollections.getShardDistribution()