How to configure a replica set using MongoDB

I have this problem that I cannot solve. Partly because I cannot explain this with the right conditions. I'm new to this, so sorry for this awkward question.

Below you can see an overview of my goal.

I want to configure replication set in MongoDB so that I tried like this

use local
db.dropDatabase()

config = { _id: "rs0", members:[
{_id: 0, host: 'localhost:27017'}]
}

rs.initiate(config)

I hope everything is correct only, but the following error message is displayed here

{ "errmsg" : "server is not running with --replSet", "ok" : 0 }

Is there something wrong I did here?

Any ideas?

+4
source share
2 answers

In fact, you can follow the MongoDB Handbook to set up a replica set. This is pretty clear. Below are some critical steps described below:

  • . master/slave, master/slave. , , master/slave, .

    replSet = [set name]
    
  • mongod:

    systemctl restart mongodb
    // or
    service mongod restart
    
  • . initiate, mongodb . , , , , . , , .

    use local
    rs.initiate()
    

. . , , 1/2 :

rs.add("hostname:port")

, :

var conf = rs.conf();
// change your conf here
rs.reconfig(conf);

, . , .

+5

MongoDB.

? , node , . , - , , , . , , .

mongod mongo, , . , - . . , , . . , , , . , . , 3, 2, , . , - , - . . .

, , . 3 - , 3, , , . , . , , , .

0

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


All Articles