No CentOS 7.
Versão do MongoDB: 3.2.15
Existem dois nós:
- nó1
- nó2
nó1
/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:
nó2
/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:
Execute o comando mongo no node1
mongo
rs.initiate()
use admin
db.createUser(...)
db.auth('admin', '...')
rs.add('node2')
Erro causado:
{
"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
}
É não pode se conectar ao node2 do node1? Existe um guia oficial sobre como fazer o conjunto de replicação mongodb?
A resposta é simples. Você não abriu seu firewall para a porta 27017, isso deve ser feito em ambos os nós.
E a documentação solicitada pode ser encontrada aqui!