Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB server is not running with replset

Tags:

mongodb

I do a MongoDB homework and follow the steps, but I faced the problem " server is not running with replset"

I do the step is :

`"start mongod --replSet m101 --logpath 1.log --dbpath \data\rs1 --port 27017 --smallfiles --oplogSize 64
start mongod --replSet m101 --logpath 2.log --dbpath \data\rs2 --port 27018 --smallfiles --oplogSize 64
start mongod --replSet m101 --logpath 3.log --dbpath \data\rs3 --port 27019 --smallfiles --oplogSize 64

Now connect to a mongo shell and make sure it comes up.

mongo --port 27017

Now you will create the replica set. Type the following commands into the mongo shell:

config = { _id: "m101", members:[`
          { _id : 0, host : "localhost:27017"},
          { _id : 1, host : "localhost:27018"},
          { _id : 2, host : "localhost:27019"} ]
};
rs.initiate(config);"

I do not know where is the problem, someone said the problem maybe is another mongod is running. But I have not any other mongod running in the same time.

Thank you!

like image 230
user3645188 Avatar asked Sep 15 '14 01:09

user3645188


1 Answers

It happened the same to me as well. The problem was that I have runned mongod without any parameters before I started launching the nodes. First kill all the mongo, mongod and mongos instances to guarantee the environment is clear.

ps -ef | grep -i 'mongo'
sudo service mongod stop

The problem cause is simple. The default port for mongod and mongos is 27017. So, what happened to me was that the first replica node was never created. The following command was connecting me to a default mongod instance:

mongo --port 27017

I hope this solves your problem. ;)

like image 99
Jayme Tosi Neto Avatar answered Oct 02 '22 23:10

Jayme Tosi Neto