Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Stop all of the Data Repositories you want to become part of the replica set.
  2. Create the key file each member of the replica set will use to authenticate servers to each other.
    To generate pseudo-random data to use for a keyfile, issue the following openssl command:

    Code Block
    openssl rand -base64 741 > mongodb-keyfile 
    chmod 600 mongodb-keyfile

    You may generate a key file using any method you choose. Always ensure that the password stored in the key file is long and contains a high amount of entropy. Using openssl in this manner helps generate such a key.

  3. Copy the mongodb-keyfile key file to each member of the replica set. Set the permissions of these files to 600 so that only the owner of the file can read or write this file to prevent other users on the system from accessing the shared secret.
  4. Beginning with your primary data repository, start each member of the replica set with the –keyFile and –replSet command-line options (to specify the key file and the name of the replica set, respectively). To add these options, edit the Data Repository's server.sh or server.bat script file (at the line that calls mongodb).  For example:

    Code Block
    mongod --keyFile /mysecretdirectory/mongodb-keyfile --replSet "rs0"
  5. Connect to the primary Data Repository and authenticate as the admin user, created by the M_USER variable in the server.sh or server.bat script:

    Code Block
    "rs.add("mongodb1.example.net:2424")
  6. (Optional) If you want to increase the write safety of the replica set, modify the primary data repository's write concerns. With the default setting, the client returns when one member acknowledges the write; you can change this so that a majority must acknowledge the write. See the MongoDB documentation for details.
  7. On the primary data repository, initiate the replica set using rs.initiate():

    Code Block
    rs.initiate()

    This initiates a set that consists of the current member and that uses the default replica set configuration.

  8. On the primary data repository, verify the initial replica set configuration by using rs.conf() to display the replica set configuration object:

    Code Block
    rs.conf() 

    The replica set configuration object should resemble the following:

    Code Block
    {
        "_id" : "rs0",
        "version" : 1,
        "members" : [
           {
               "_id" : 1,
               "host" : "mongodb0.example.net:27017"
           }
         ]
    }
  9. Add the remaining replica set members to the replica set with the rs.add() method. You must be connected to the primary data repository to add members to a replica set.
    rs.add() can, in some cases, trigger an election. If the Data Repository you are connected to becomes a secondary, you need to connect the mongo shell to the new primary to continue adding new replica set members. Use rs.status() to identify the primary in the replica set.
    The following example adds two members:

    Code Block
    rs.add("mongodb1.example.net")
    rs.add("mongodb2.example.net")

    When complete, you have a fully functional replica set. The new replica set will elect a primary.

  10. Check the status of the replica set using the rs.status() operation:

    Code Block
    rs.status()

...