I have 3 "CentOs 7" VM's in AWS environment in which I have setup MongoDB Repication Set using below command.

mongod --fork --logpath "/var/rs1/1.log" --replSet yogi --dbpath "/var/rs1/" --port 27017

Replication works fine, but when I restart any one of VM. Restarted VM comes out of replication group(I observed that mongo started without --replSet)

I placed above command in /etc/rc.local after giving +x permission and restarted the VM, I got the same issue.

If I run the same command after killing mongodb process it works fine.

What can be the issue here, how can I get VM to get added in Replica Set automatically after restart?

When I add the command in rs.local file I get below messages in logs

 Nov 17 10:20:09 13 rc.local: forked process: 889
 Nov 17 10:20:09 13 rc.local: ERROR: child process failed, exited with error number 1

I fixed the issue by adding below lines in /etc/mongod.conf

   replSetName: yogi
  • Of course, if you start your mongod with different parameters at command line what you do with config file, then result is what it was. ;-) – JJussi Nov 18 '17 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.