在 CentOS 7 上。
MongoDB 版本:3.2.15
有两个节点:
- 节点1
- 节点2
节点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:
节点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:
在 node1 上运行 mongo 命令
mongo
rs.initiate()
use admin
db.createUser(...)
db.auth('admin', '...')
rs.add('node2')
导致错误:
{
"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
}
它不能从node1连接到node2吗?有没有关于如何做 mongodb 复制集的官方指南?
答案很简单。您还没有为端口 27017 打开防火墙,必须在两个节点上完成。
并且可以在此处找到要求的文档!