MongoDB server not working with replacement

I am doing MongoDB homework and following the steps, but I ran into a problem: "server is not working with change"

I take the next step:

`"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 the mongo shell and make sure it appears.

 mongo --port 27017 

You will now create a replica set. Enter the following commands in the mongo command:

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

I don’t know where the problem is, someone said that the problem may be that another mongod is working. But at the same time, I have no other mongods.

Thanks!

+5
source share
2 answers

The same thing happened to me. The problem was that I started mongod without any parameters before I started to start the nodes. First destroy all instances of mongo, mongod, and mongo to ensure that the environment is clean.

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

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

 mongo --port 27017 

Hope this solves your problem .;)

+6
source

Check which command line options mongod supports in the shell:

 > use admin switched to db admin > db.runCommand("getCmdLineOpts") { "argv" : [ "mongod", "--dbpath", "/data/db", "--replSet", "rs0" ], "parsed" : { "replication" : { "replSet" : "rs0" }, "storage" : { "dbPath" : "/data/db" } }, "ok" : 1 } 

Do you see the replSet parameter?

You can also try another way to initiate a replica set. Instead of entering the configuration and passing it to rs.initiate() , just run rs.initiate() . It will configure the default configuration with one member - the server to which you are connected in the shell. Then you can add two other servers. See the tutorial for more details.

+3
source

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


All Articles