comiventor
comiventor

Reputation: 4122

Setup one member MongoDB replica set

I want to convert a standalone machine into one member replica set by configuring the same in /etc/init.d/mongodb.

I came across the below command to do the same:

sudo mongod --port 27017 --dbpath /srv/mongodb/db0 --replSet rs0

But it's not working out. My mongo is configured to run on autostart. I ran the following command to stop the running instance before running with the --replSet option.

sudo service mongod stop

Both commands above run without any output/error but when I run rs.initiate(), I get the error below:

{
    "ok" : 0,
    "errmsg" : "not authorized on admin to execute command { replSetInitiate: undefined }",
    "code" : 13
}

From the error message it looks like the issue seems to be of access. Can anybody give any pointers?

Also, if I succeed with above command, will I need to make any changes to /etc/mongod.conf or /etc/init.d/mongodb so that the instance continues to run as a one node replica?

Upvotes: 0

Views: 2942

Answers (1)

Vince Bowdren
Vince Bowdren

Reputation: 9198

Firstly: There are two ways of setting a mongod process's configuration; either (as in the command you found) as parameters on the command line, or in a configuration file mongod.conf. Your setup seems to be using a configuration file, so you need to put the replica set settings in the mongod.conf file, not on the command line.

Secondly: to run the rs.initiate() command on a system where authentication is enabled, as yours is, you must be authenticated as a user who has permission to run this command

Upvotes: 2

Related Questions