Wednesday, April 25, 2018

Sharded Cluser – Basic Outline - MongoDB


Sharded Cluser – Basic Outline

This Outline is based on MongoDB documentation

Basic Components
  • Mongod
  • Mongos
  • Config servers

Deploy Sharded Cluster

1. Create the Config Server Replica Set

Start each member of the config server replica set

Configuration File

sharding:
  clusterRole: configsvr
replication:
  replSetName: <setname>

# mongod -f <path-to-config-file>

Connect to one of the config servers

# mongo --host <hostname> --port <port>

Initiate and add members to the replica set

# rs.initiate()
# rs.add("cfg2.example.net:27019")
# rs.add(“cfg3.example.net:27019”)

Once the config server replica set (CSRS) is initiated and up, proceed to creating the shard replica sets.

2. Create the Shard Replica Sets

Start each member of the shard replica set.

Configuration File

sharding:
  clusterRole: shardsvr
replication:
  replSetName: <replSetName>

# mongod -f <path-to-config-file>

Connect to a member of the shard replica set.

# mongo --host <hostname> --port <port>

Initiate and add members to the replica set

# rs.initiate()
# rs.add"s1-mongo2.example.net:27018")
# rs.add"s1-mongo3.example.net:27018")

3. Connect a mongos to the Sharded Cluster

Connect a mongos to the cluster

Configuration File

sharding:
  configDB: <configReplSetName>/cfg1.example.net:27019,cfg2.example.net:27019,...

# mongos -f <path-to-config>

Connect to the mongos.

# mongo --host <hostname> --port <port>

4. Add Shards to the Cluster

Use the sh.addShard() method to add each shard to the cluster
 If the shard is a replica set, specify the name of the replica set and specify a member of the set.

# sh.addShard( "<replSetName>/s1-mongo1.example.net:27017")

To check the status

sh.status()

No comments:

Post a Comment