Mongodb – Issue with MongoDB Replication Set

centoscentos-7mongodbmongodb-3.4replication

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

Best Answer

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

replication:
   replSetName: yogi