Mongo DB issues with replSet

I am trying to do this:

mongod --replSet mySet --dbpath / data / r1 --port 27017 --oplogSize 700

mongod --replSet mySet --dbpath / data / r2 --port 27018 --oplogSize 700

mongod --replSet mySet --dbpath / data / r3 --port 27019 --oplogSize 700

then in the new terminal:

/mongo --port 27017 MongoDB shell version: 2.0.2 connecting to: 127.0.0.1:27017/test > cfg = { _id : "mySet", members : [ { _id : 0, host : "localhost:27017" }, { _id : 1, host : "localhost:27018" }, { _id : 2, host : "localhost:27019" } ] } 

And when I run

rs.initiate (CFG)

I get this error:

{"errmsg": "server does not work with --replSet", "ok": 0}

Why am I getting this error?

from the log file:

 Fri Jun 01 15:05:11 [initandlisten] MongoDB starting : pid=5236 port=27017 dbpath=c:\mongodb\data 64-bit host=mami Fri Jun 01 15:05:11 [initandlisten] db version v2.0.4, pdfile version 4.5 Fri Jun 01 15:05:11 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebf Fri Jun 01 15:05:11 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_42 Fri Jun 01 15:05:11 [initandlisten] options: { dbpath: "c:\mongodb\data", logappend: true, logpath: "c:\mongodb\logs\logfilename.log", service: true } Fri Jun 01 15:05:11 [initandlisten] journal dir=c:/mongodb/data/journal Fri Jun 01 15:05:11 [initandlisten] recover : no journal files present, no recovery needed Fri Jun 01 15:05:12 [initandlisten] waiting for connections on port 27017 Fri Jun 01 15:05:12 [websvr] admin web console waiting for connections on port 28017 Fri Jun 01 15:05:12 [initandlisten] connection accepted from 127.0.0.1:49663 #1 Fri Jun 01 15:05:56 [conn1] end connection 127.0.0.1:49663 Fri Jun 01 15:06:02 [initandlisten] connection accepted from 127.0.0.1:49669 #2 Fri Jun 01 15:06:11 [clientcursormon] mem (MB) res:22 virt:67 mapped:0 Fri Jun 01 15:06:19 [conn2] terminating, shutdown command received Fri Jun 01 15:06:19 dbexit: shutdown called Fri Jun 01 15:06:19 [conn2] shutdown: going to close listening sockets... Fri Jun 01 15:06:19 [conn2] closing listening socket: 488 Fri Jun 01 15:06:19 [conn2] closing listening socket: 492 Fri Jun 01 15:06:19 [conn2] shutdown: going to flush diaglog... Fri Jun 01 15:06:19 [conn2] shutdown: going to close sockets... Fri Jun 01 15:06:19 [conn2] shutdown: waiting for fs preallocator... Fri Jun 01 15:06:19 [conn2] shutdown: lock for final commit... Fri Jun 01 15:06:19 [conn2] shutdown: final commit... Fri Jun 01 15:06:19 [conn2] shutdown: closing all files... Fri Jun 01 15:06:19 [conn2] closeAllFiles() finished Fri Jun 01 15:06:19 [conn2] journalCleanup... Fri Jun 01 15:06:19 [conn2] removeJournalFiles Fri Jun 01 15:06:19 [conn2] shutdown: removing fs lock... Fri Jun 01 15:06:19 dbexit: really exiting now ***** SERVER RESTARTED ***** Fri Jun 01 15:06:19 [initandlisten] MongoDB starting : pid=6980 port=27017 dbpath=c:\mongodb\data 64-bit host=mami Fri Jun 01 15:06:19 [initandlisten] db version v2.0.4, pdfile version 4.5 Fri Jun 01 15:06:19 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebf Fri Jun 01 15:06:19 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_42 Fri Jun 01 15:06:19 [initandlisten] options: { dbpath: "c:\mongodb\data", logappend: true, logpath: "c:\mongodb\logs\logfilename.log", service: true } Fri Jun 01 15:06:19 [initandlisten] journal dir=c:/mongodb/data/journal Fri Jun 01 15:06:19 [initandlisten] recover : no journal files present, no recovery needed Fri Jun 01 15:06:19 [initandlisten] waiting for connections on port 27017 Fri Jun 01 15:06:20 [websvr] admin web console waiting for connections on port 28017 Fri Jun 01 15:06:20 [initandlisten] connection accepted from 127.0.0.1:49678 #1 Fri Jun 01 15:06:22 [conn1] end connection 127.0.0.1:49678 Fri Jun 01 15:06:30 [initandlisten] connection accepted from 127.0.0.1:49679 #2 Fri Jun 01 15:06:36 [conn2] terminating, shutdown command received Fri Jun 01 15:06:36 dbexit: shutdown called Fri Jun 01 15:06:36 [conn2] shutdown: going to close listening sockets... Fri Jun 01 15:06:36 [conn2] closing listening socket: 488 Fri Jun 01 15:06:36 [conn2] closing listening socket: 492 Fri Jun 01 15:06:36 [conn2] shutdown: going to flush diaglog... Fri Jun 01 15:06:36 [conn2] shutdown: going to close sockets... Fri Jun 01 15:06:36 [conn2] shutdown: waiting for fs preallocator... Fri Jun 01 15:06:36 [conn2] shutdown: lock for final commit... Fri Jun 01 15:06:36 [conn2] shutdown: final commit... Fri Jun 01 15:06:36 [conn2] shutdown: closing all files... Fri Jun 01 15:06:36 [conn2] closeAllFiles() finished Fri Jun 01 15:06:36 [conn2] journalCleanup... Fri Jun 01 15:06:37 [conn2] removeJournalFiles Fri Jun 01 15:06:37 [conn2] shutdown: removing fs lock... Fri Jun 01 15:06:37 dbexit: really exiting now ***** SERVER RESTARTED ***** Fri Jun 01 15:06:37 [initandlisten] MongoDB starting : pid=7076 port=27017 dbpath=c:\mongodb\data 64-bit host=mami Fri Jun 01 15:06:37 [initandlisten] db version v2.0.4, pdfile version 4.5 Fri Jun 01 15:06:37 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebf Fri Jun 01 15:06:37 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_42 Fri Jun 01 15:06:37 [initandlisten] options: { dbpath: "c:\mongodb\data", logappend: true, logpath: "c:\mongodb\logs\logfilename.log", service: true } Fri Jun 01 15:06:37 [initandlisten] journal dir=c:/mongodb/data/journal Fri Jun 01 15:06:37 [initandlisten] recover : no journal files present, no recovery needed Fri Jun 01 15:06:37 [initandlisten] waiting for connections on port 27017 Fri Jun 01 15:06:37 [websvr] admin web console waiting for connections on port 28017 Fri Jun 01 15:06:37 [initandlisten] connection accepted from 127.0.0.1:49680 #1 Fri Jun 01 15:06:39 [conn1] end connection 127.0.0.1:49680 Fri Jun 01 15:07:37 [clientcursormon] mem (MB) res:22 virt:66 mapped:0 Fri Jun 01 15:53:55 [clientcursormon] mem (MB) res:0 virt:64 mapped:0 Fri Jun 01 15:58:55 [clientcursormon] mem (MB) res:1 virt:64 mapped:0 Fri Jun 01 15:59:24 [initandlisten] connection accepted from 127.0.0.1:50087 #2 Fri Jun 01 15:59:55 [clientcursormon] mem (MB) res:2 virt:65 mapped:0 Fri Jun 01 16:04:55 [clientcursormon] mem (MB) res:2 virt:65 mapped:0 Fri Jun 01 16:06:07 [conn2] replSet replSetInitiate admin command received from client 

I tried this replSet tutorial but still nothing

+4
source share
7 answers

One of the reasons I can think of is because you already had a mongod running on port 27017 without the --replSet argument before you try to run it. Make sure mongod is not working ( ps aux |grep mongod ) before trying to do this. I would also check the log file, since it is likely that it makes it clear why it did not start in replica mode.

+16
source

The simple solution I discovered was to specify a subargument for -replSet.

I configure my Mongo Server as a ReplicaSet with only one node, since it acts like PRYMARY, there will be no other node to read the paging.

This helped me when starting the mongod service.

/ "> sudo mongod --replSet myReplSet

As soon as I logged in with mongo, then the prompt was changed, after which I can configure rs correctly:

/ myReplSet: PRIMARY> cfg = {_id: "mySet", members: [{_id: 0, host: "localhost: 27017"}]}

/ myReplSet: PRIMARY> rs.initiate (cfg)

And it did the trick !!

I hope this helps someone.

+2
source

I noticed a linux resolution issue, as I suggest the post above. To fix this, you need to set permissions on the data directory command, this is sudo chown -R $USER /data . I had the same problem with npm.

+1
source

I had exactly the same problem when I was doing mongodb replication and fined my homework. After executing the following command:

 ./mongod --replSet m101 --logpath "1.log" --dbpath /data/rs1 --port 27017 --smallfiles --oplogSize 64 --fork 

and then doing ps aux | grep mongo ps aux | grep mongo , I realized that nothing started. What I did to make it work was to simply run this command as the system root, so finally I run the mongod process, for example:

 sudo ./mongod --replSet m101 --logpath "1.log" --dbpath /data/rs1 --port 27017 --smallfiles --oplogSize 64 --fork 

That's all!:)

Hope this helps.

0
source

I managed to get around this.

  • I first deleted mongodb: sudo apt-get remove mongodb

  • I followed the MongoDB tutorial:

  • However, after step ...: Updating sudo apt-get

  • ... I decided to reinstall mongodb: sudo apt-get to remove mongodb (In this step, I may have specified "mongodb-server").

And, by magic, the name replSet was downloaded from mongodb.conf. I stayed on rs.initiate () - and that is it.

Note. I started with 2.4.9 and ended with the same 2.4.9 - just working.

0
source

It had the same problem, so in my case, there was another mongod process on the system (which, of course, worked without the --replSet flag on the default port, which is why I had this error).

execute the command:

 $ ps aux | grep mongod 

in my case it produces:

 root 63434 0.3 0.1 2621328 12228 ?? S 5:53PM 0:03.44 mongod --replSet m101 --logpath 1.log --dbpath /data/rs1 --port 27017 --smallfiles --oplogSize 64 --fork root 63442 0.2 0.1 2622352 12220 ?? S 5:54PM 0:03.37 mongod --replSet m101 --logpath 2.log --dbpath /data/rs2 --port 27018 --smallfiles --oplogSize 64 --fork root 63448 0.2 0.1 2621312 12208 ?? S 5:54PM 0:03.35 mongod --replSet m101 --logpath 3.log --dbpath /data/rs3 --port 27019 --smallfiles --oplogSize 64 --fork pavlo 683 0.0 0.0 3082276 6628 ?? S 31Aug14 11:27.70 /usr/local/opt/mongodb/bin/mongod --config /usr/local/etc/mongod.conf pavlo 63522 0.0 0.0 2432784 624 s002 S+ 6:06PM 0:00.00 grep mongod 

So, the process with id 683 was on the way, so after I killed it, everything works:

 $ kill 683 
0
source

yup, also here on my ubuntu 15.04. And the permit port solved this. Also, check the log so that the execution status lets us know how it works.

0
source

Source: https://habr.com/ru/post/1415102/


All Articles