我有两个虚拟机,两个虚拟机上都运行着mongodb。我已经创建了一个用户和角色,并添加了数据进行测试。在我尝试设置 Replica 集之前,一切都正常。当我运行rs.initiate()时,我得到了"...replSetHeartbeat requires authentication... "的错误,如下所示。"错误,见下图。我可以通过传递--host "nodeserver-hulk:27017",从 "hawkeye "手动连接到 "hulk "服务器。有什么好办法吗?
系统
Ubuntu Server 18.04.4 LTS
Mongod v.4.2.3
rs.启动命令
rs.initiate(
{
_id: "r1",
version: 1,
members: [
{ _id: 0, host : "nodeserver-hulk:27017"},
{ _id: 1, host : "nodeserver-hawkeye:27017"}
]
}
)
rs.启动错误
{
"ok" : 0,
"errmsg" : "replSetInitiate quorum check failed because not all proposed set members responded affirmatively: nodeserver-hawkeye:27017 failed with command replSetHeartbeat requires authentication",
"code" : 74,
"codeName" : "NodeNotFound"
}
mongod.conf文件(两台服务器相同)
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /mnt/mongo/data
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
security:
authorization: 'enabled'
#operationProfiling:
#replication:
replication:
replSetName: 'r1'
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
显示用户命令
> show users
{
"_id" : "admin.james",
"userId" : UUID("3ed97f2e-de49-4b98-84c8-566b34805863"),
"user" : "james",
"db" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "dbOwner",
"db" : "admin"
},
{
"role" : "clusterAdmin",
"db" : "admin"
},
{
"role" : "readWriteAnyDatabase",
"db" : "admin"
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}
用以下方式登录
mongo -u <yourUsername> -p
它将要求输入密码 - 输入密码,你应该准备好了。
你需要添加一个 keyFile
的安全配置中,这样每个节点都可以对其他节点进行验证。
https:/docs.mongodb.commanualtutorialenforce-keyfile-access-control-in-existing-replica-set。
security:
keyFile: <path-to-keyfile>