Error when setting up replica set on Mongodb


I’m trying to set up a replica set on my Mongodb so that I can use oplog tailing.

I’m using these instructions:

I’ve added this code to /etc/mongod.conf:

  replSetName: rs0
  oplogSizeMB: 100

Then run the mongo shell:


In the shell:

use local

I see this error in the mongo console:

	"ok" : 0,
	"errmsg" : "This node was not started with the replSet option",
	"code" : 76,
	"codeName" : "NoReplicationEnabled"

Any idea what might be wrong? My mongo.conf shows:

  port: 27017

so I’m running the expected port, I think. I have tried restarting mongodb with sudo service mongod start. What have I missed? Thanks!


In your config files at startup, you pass to mongod the replSet (e.g. “rs0”) and the keyfile (read mongo docs)
On master, in mongo shell, you add all the replica nodes, it takes care of communicating with the slaves
Make sure slaves are blank otherwise replication fails


I’m not sure about the configuration file, but a correct command line will look like, for example:

mongod --dbpath=/var/db --bind_ip_all --replSet replSetName --smallfiles --oplogSize 100

That seems consistent. However, what it seems that you do differently is use local. I would run the replSetInitiate command against admin, not local, which I think is your issue.


Agreed, not sure why you need use local there


Thank you for the comments guys. I think I have figured it out, a combination of something not specified in the docs and a mistake on my part. Here are my full steps to get it working for a Meteor app deployed with Phusion Passenger on a Digital Ocean droplet.

  1. Set up replica set

SSH to the server and in the terminal, type:

sudo nano /etc/mongod.conf

In this doc, add:

  replSetName: rs0
  oplogSizeMB: 100

Now add your hostname as an alias. First identify your hostname by typing:


This returns, say, ‘myhostname’. Now type:

nano /etc/hosts

And to this file add: myhostname

Restart mongodb:

sudo service mongod stop
sudo service mongod start

Initiate the replica set:

Then in the mongo shell:

use local
  1. Configure Meteor (through Passenger)

Exit mongo shell. Type:

sudo nano /etc/nginx/sites-enabled/myappname.conf

(Whatever is your Passenger configuration file)

Add this to the file below MONGO_URL

passenger_env_var MONGO_OPLOG_URL mongodb://localhost:27017/local;

Restart nginx for the Passenger changes to take effect:

sudo service nginx restart

Your friends in the wilderness are the mongo and nginx logs:

nano /var/log/mongodb/mongod.log
nano /var/log/nginx/error.log