Why do two sets of heavy lifting ??? Let MongoDB do it.
For this example, suppose IP of
10.30.50.70 with hostname
STEP 01 : Enable Replica Set on the PRIMARY only
Make the following changes in
/etc/mongodb.conf on the PRIMARY
- enable authorization in
authorization: enabled under the security YAML tag (MongoDB 2.6+)
auth=true (if you are using MongoDB 2.4)
- Enable replication (suppose your name the replica set
replSetName: myreplica under replication YAML tag (MongoDB 2.6+)
replSet = myreplica (MongoDB 2.4)
STEP 02 : Restart MongoDB on the
service mongod restart
STEP 03 : Initiate Replica Set on the
NOTE: At this point your have a one-node Replica Set
STEP 04 : Perform Steps 01 and 02 on your SECONDARY
NOTE: At this point, the
SECONDARY is replica set enabled but not replicating
STEP 05 : NOW, add the
SECONDARY to the
Goto the PRIMARY and run
STEP 06 : Check status of Replica Set
Run this repeatedly
If this command ever freezes, don't worry. It rebuilding all the indexes.
You can open another ssh session on the
tail -f on the
mongodb.log file and see the index rebuild progression.
WHY DO IT THIS WAY ???
MongoDB will do essentially start replication, copy the data, and rebuild indexes in a single operation. As shown, this process is in no way automatic when building an initial replica set. Doing it this way, is less error-prone.