Add Secondary replica set in the same machine?

匿名 (未验证) 提交于 2019-12-03 08:59:04

问题:

I'm new at mongodb so this replication is kinda confusing for me. I follow the tutorial here. I have set up 2 mongod instance in my machine:

localhost:27018 localhost:27019 

with this command:

mongod --dbpath /home/db2 --port 27019 --replSet "rs1" mongod --dbpath /data/db1 --port 27018 --replSet "rs1" 

When I try to connect and set up replication using this set of command

mongo --port 27019 rs1:PRIMARY> rs.add("localhost:27018") 

It always says:

{ "ok" : 0, "errmsg" : "Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2", "code" : 103 } 

Any help, please ?

回答1:

It would be better if you choose the machine name (available in terminal right after your username like user01@10gen.local) instead of localhost,

Like rs1:PRIMARY> rs.add("10gen.local:27018")

as the best practice always use a logical name to define the replicaset.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!