Unable to start MongoDB with –replSet [closed]

Posted on

Question :

I have been trying to install Rocket.chat which requires MongoDB, the instruction for configuring MongoDB is here: https://rocket.chat/docs/installation/manual-installation/ubuntu/index.html#install.

I have MongoDB 2.4.10, I appended replSet=001-rs to the end of /etc/mongod.conf and restarted MongoDB with systemctl restart mongodb. However, when I run rs.initiate() I get error server is not running with --replSet

$ mongo
MongoDB shell version: 2.4.10
connecting to: test
> rs.initiate()
{ "ok" : 0, "errmsg" : "server is not running with --replSet" }
> 

Rocket.chat requires MongoDB to run with replSet, I should get a result with "ok": 1, similar to this:

{
  "info2" : "no configuration explicitly specified -- making one",
  "me" : "localhost:27017",
  "info" : "Config now saved locally.  Should come online in about a minute.",
  "ok" : 1
}

How can I start MongoDB 2.4.10 with --replSet? Thank you for your time!

Answer :

After checking my /etc/mongod.conf I noticed that it was the configuration for MongoDB 2.6 and newer, that was why replSet=001-rs did nothing. Reinstalling didn’t help so I decided to install MongoDB 3.6 from MongoDB’s repository, followed the instruction of Rocket.chat and everything worked as expected.

I appended replSet=001-rs to the end of /etc/mongod.conf and restarted
MongoDB with systemctl restart mongodb. However, when I run
rs.initiate() I get error server is not running with –replSet.

As per rocket.chat BOL documentation Here

To restart Mongo :

service mongod restart

As you have said that after appended replSet=001-rs to the end of /etc/mongod.conf and restarted MongoDB with systemctl restart mongodb.

As per BOL documented Here and Here systemctl may be used to introspect and control the state of the
systemd system and service manager.

To start a systemd service, executing instructions in the service’s unit file, use the start command. If you are running as a non-root user, you will have to use sudo since this will affect the state of the operating system:

For example

 sudo systemctl start application.service

In case of MongoDB, to enable mongodb on startup

sudo systemctl enable mongodb.service

As systemd knows to look for *.service files for service management commands, so the command could just as easily be typed like this:

For Example

sudo systemctl start application

to start mongodb

sudo systemctl start mongodb

There is troubleshooting trics after making any configuration changes in mongod.conf file.

1) First killed all mongod with sudo sudo killall mongod

2) Now to start mongodb sudo systemctl start mongodb

Hope this will help out to you.

For further your ref Here, Here

Leave a Reply

Your email address will not be published. Required fields are marked *