Initiate the Config-Server Replica Set

Initiate the config-server mongod instances (three-member replica set) that will host the configuration data of your sharded MongoDB deployment.

Before you begin

Before initiating the config server replica set, verify the following in the MongoDB configuration file:
  • Verify that the replication option is set to MtxEventReplSet.
  • Verify that the authorization option is set to enabled.
  • Verify that all mongod instances on each of the MongoDB host servers are started.
Important: Starting in MongoDB 4.0, you cannot specify the --nojournal option or storage.journal.enabled: false for replica set members that use the WiredTiger storage engine. Refer to the MongoDB product documentation for compatibility changes in MongoDB 4.0.

About this task

The instructions in this procedure initiate a single replica set with three mongod instances.

Procedure

  1. Connect to one of the mongod instances locally.
  2. Using the MongoDB mongo shell CLI, enter the rs.initiate() command to initiate the config server replica set.
    mongo –port 27019 
    rs.initiate({ 
     "_id": "MtxConfigReplSet", 
     configsvr: true, 
     "members": [ 
    {"_id": 0, "host": "ip1:27019"}, 
    {"_id": 1, "host": "ip2:27019"}, 
    {"_id": 2, "host": "ip3:27019"} 
    where:
    • ip1, ip2, and ip3 are the hostnames (or IP addresses) and port numbers of the host servers where mongod instances of the config servers are to run. The port number is required only if the port number is not the default (27017).
  3. Identify the replica set primary (mongod primary) by issuing the mongo shell CLI command rs.status() on any server.

    A few seconds after the replica set is initialized, one mongod instance is elected as the primary of the replica set. All changes to the replica set must be done when connected to the primary from this point in the setup instructions.

What to do next

After you initiate the config-server replica set, start all mongos instances in your deployment in preparation for creating users for each shard replica set.