【问题标题】:mongodb replica set error "...replSetHeartbeat requires authentication..." after running rs.initiate()运行 rs.initiate() 后 mongodb 副本集错误“...replSetHeartbeat 需要身份验证...”
【发布时间】:2020-06-01 19:18:48
【问题描述】:

我有 2 台运行 mongodb 的虚拟机。我创建了一个用户和角色并添加了测试数据。在我尝试设置副本集之前一切正常。当我运行 rs.initiate() 时,我得到“...replSetHeartbeat 需要身份验证...”错误如下所示。我可以通过传递 --host "nodeserver-hulk:27017" 手动从“hawkeye”连接到“hulk”服务器。有什么想法吗?

系统

Ubuntu Server 18.04.4 LTS
Mongod v.4.2.3

rs.initiate 命令

rs.initiate(
   {
      _id: "r1",
      version: 1,
      members: [
         { _id: 0, host : "nodeserver-hulk:27017"},
         { _id: 1, host : "nodeserver-hawkeye:27017"}
      ]
   }
)

rs.initiate 错误

{
        "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"
        ]
}

【问题讨论】:

    标签: mongodb replication mongo-shell


    【解决方案1】:

    您需要在安全配置中添加keyFile,以便每个节点都可以针对其他节点进行身份验证。

    https://docs.mongodb.com/manual/tutorial/enforce-keyfile-access-control-in-existing-replica-set/

    security:
      keyFile: <path-to-keyfile>
    

    【讨论】:

    • 这解决了问题!。我只补充一点,它仅对密钥文件身份验证有效:如果您想使用 x509 证书而不是密钥文件进行内部身份验证(这是另一种可能性),您需要以这种方式配置它:docs.mongodb.com/manual/tutorial/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-12
    • 2020-11-26
    • 2017-11-14
    • 2015-07-09
    • 1970-01-01
    相关资源
    最近更新 更多