Mongo as Shards
Sharding Environment Setup
Sharding Group Members :
For sharding there are three players.
-
Config Server
-
Replica Sets
-
Mongos
For a mongo shard we need to setup the above three servers.
Config Server Setup : add the following to mongod conf file
sharding:
clusterRole: configsvr
replication:
replSetName: <setname>
run : mongod —config
we can choose config server as replica set or may be a standalone server. Based on our requirement we can choose the best. If config need to run in replica set we need to follow the replica set setup
Replica Setup : Create replica set // Please refer the replica setup
MongoS Setup : Mongos is main setup in shard. Its is query router to access all replica sets
Add the following in mongos conf file
sharding:
configDB: <configReplSetName>/cfg1.example.net:27017;
Configure Shared :
Connect the mongos via shell (mongo —host
- sh.addShard( ”
/s1-mongo1.example.net:27017”) - sh.enableSharding(”
“) - sh.shardCollection(”< database >.< collection >”, { < key > : < direction > } )
- sh.status() // To ensure the sharding