On CentOS 7.
MongoDB version: 3.2.15
There are two nodes:
- node1
- node2
node1
/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 node1
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.100 node1
192.168.0.101 node2
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /mongo-metadata
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1 192.168.0.100 # Listen to local interface only, comment to listen on all interfaces.
security:
keyFile: /root/keyfile
#operationProfiling:
replication:
replSetName: rs0
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
node2
/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 node2
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.100 node1
192.168.0.101 node2
/etc/mongod.conf
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /mongo-metadata
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1 192.168.0.101 # Listen to local interface only, comment to listen on all interfaces.
security:
keyFile: /root/keyfile
#operationProfiling:
replication:
replSetName: rs0
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
Run mongo command on node1
mongo
rs.initiate()
use admin
db.createUser(...)
db.auth('admin', '...')
rs.add('node2')
Caused error:
{
"ok" : 0,
"errmsg" : "Quorum check failed because not enough voting nodes responded; required 2 but only the following 1 voting nodes responded: node1:27017; the following nodes did not respond affirmatively: node2:27017 failed with No route to host",
"code" : 74
}
Is it can't connect to node2 from node1? Is there a official guide about how to do mongodb replication set?
Best Answer
Answer is simple. You have not open your firewall for port 27017, is must be done on both nodes.
And asked documentation can be found here!