Finally ensure that each member of a replica set is accessible by way of resolvable DNS or hostnames. You should either configure your DNS names appropriately or set up your systems’ /etc/hosts file to reflect this configuration. 

Configuration Specify the run time configuration on each system in a configuration file stored in /etc/mongod.conf or a related location. Create the directory where MongoDB stores data files before deploying MongoDB. 

For more information about the run time options used above and other configuration options, see http://docs.mongodb.org/manual/reference/configuration-options . 

## Procedure 

This procedure deploys a replica set in which all members use the same key file. 

Step 1: Start one member of the replica set. This mongod should not enable auth . 

Step 2: Create administrative users. The following operations will create two users: a user administrator that will be able to create and modify users ( siteUserAdmin ), and a root (page 413) user ( siteRootAdmin ) that you will use to complete the remainder of the tutorial: use admin 

db.createUser( { user: "siteUserAdmin", pwd: "<password>", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] }); db.createUser( { user: "siteRootAdmin", pwd: "<password>", roles: [ { role: "root", db: "admin" } ] }); 

## Step 3: Stop the mongod instance. 

Step 4: Create the key file to be used by each member of the replica set. Create the key file your deployment will use to authenticate servers to each other. 

To generate pseudo-random data to use for a keyfile , issue the following openssl command: 

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 both long and contains a high amount of entropy. Using openssl in this manner helps generate such a key. 

Step 5: Copy the key file to each member of the replica set. Copy the mongodb-keyfile to all hosts where components of a MongoDB deployment run. 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. 

