Initiate the Sharded Cluster
Initiate the sharded cluster of your sharded MongoDB deployment that will host the MATRIXX event-object data set in your MongoDB system.
Before you begin
- Each shard replica set has been initiated.
- The config server replica set has been initiated.
- All
mongod
instances (config servers and shards) andmongos
instances on each of the MongoDB host servers are started.
About this task
In MongoDB, a sharded cluster is a group of replica sets, mongod
instances
that host the same data set, that include config-server replica sets and shard
replica sets. These instructions initiate a single config-server replica set (with
three mongod
instances) and two shard replica sets (each with three
mongod
instances). The following table shows an example of a
group of replica sets in a sharded cluster.
MongoDB Instance | Host Server | Default
Port Number |
replication.
replSetName |
sharding.
clusterRole |
---|---|---|---|---|
Config Server | Server1 (192.168.1.1) | 27019 | MtxConfigReplSet | configsvr |
Config Server | Server2 (192.168.1.2) | 27019 | MtxConfigReplSet | configsvr |
Config Server | Server3 (192.168.1.3) | 27019 | MtxConfigReplSet | configsvr |
Shard for Shard 1 | Server4 (192.168.1.4) | 27018 | MtxShard1ReplSet | shardsvr |
Shard for Shard 1 | Server5 (192.168.1.5) | 27018 | MtxShard1ReplSet | shardsvr |
Shard for Shard 1 | Server6 (192.168.1.6) | 27018 | MtxShard1ReplSet | shardsvr |
Shard for Shard 2 | Server7 (192.168.1.7) | 27018 | MtxShard2ReplSet | shardsvr |
Shard for Shard 2 | Server8 (192.168.1.8) | 27018 | MtxShard2ReplSet | shardsvr |
Shard for Shard 2 | Server9 (192.168.1.9) | 27018 | MtxShard2ReplSet | shardsvr |
Procedure
-
Connect to one of the
mongos
instances and initialize the sharded cluster by typing the following command for each replica set:sh.addShard("replica_set_name/host:port,host:port,...")where:
- replica_set_name is the name of the replica set
- host is the IP
address or host name of the host server on which a
mongod
instance for that replica set is running - port is the port on
which a
mongod
instance for that replica set is running on its host server
For a sharded cluster that has two shards and a setup as shown in the preceding table, the initialization commands would look like this:
sh.addShard("MtxShard1ReplSet/192.168.1.4:27018,192.168.1.5:27018,192.168.1.6:27018")
sh.addShard("MtxShard2ReplSet/192.168.1.7:27018,192.168.1.8:27018,192.168.1.9:27018")
-
Verify the sharded cluster is initialized using the
status
command:sh.status()
What to do next
After you initiate the sharded cluster, create sharded cluster users.