简体   繁体   中英

How to edit MongoDB configuration file to include replica set?

I have a Linux Mint/Ubuntu machine with a mongodb installed from ubuntu package manager (APT-GET). I try to edit /etc/mongod.conf using

sudo nano /etc/mongod.conf

activate the replySet field so that it reads:

# Replication Options
# in replicated mongo databases, specify the replica set name here
replSet=rs0

# maximum size in megabytes for replication operation log
#oplogSize=1024
# path to a key file storing authentication info for connections
# between replica set members
#keyFile=/path/to/keyfile

succesfully restarted mongod instance with: sudo service mongod restart But, whenever I run rs.initiate() , it resulted in error that suggests mongod can't find it's config file

{
  "info2" : "no configuration explicitly specified -- making one",
  "me" : "Leony:27017",
  "ok" : 0,
  "errmsg" : "No host described in new configuration 
  1 for replica set rs0 maps to this node",
  "code" : 93
}

Any suggestion ?

I believe the problem is in mismatch of host name being resolved by rs.initiate() call and the bindIp specified in the configuration. Have you tried supplying a json argument to the rs.initiate() call ? Like below ?

rs.initiate({_id: "rs0", members: [{_id: 0,host: "hostname:port"}]})

Also please see the JIRA ticket in Mongodb, where Mongo engineer says, it is not actually a bug, but works as designed. So one need to have consistency in host name in net.bindIp as well as the host name in replica sets configuration.

Also, in a production setup, it is better to have DNS names or entries in /etc/hosts to easily manage cluster. It is not impossible to do without DNS names or resolvable host names, but it is easier this way.

Also see this answer regarding configuration file option regarding bindIp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM