運行 rs.initiate() 後 mongodb 副本集錯誤“...replSetHeartbeat 需要身份驗證...” (mongodb replica set error "...replSetHeartbeat requires authentication..." after running rs.initiate())


問題描述

運行 rs.initiate() 後 mongodb 副本集錯誤“...replSetHeartbeat 需要身份驗證...” (mongodb replica set error "...replSetHeartbeat requires authentication..." after running rs.initiate())

我有 2 台運行 mongodb 的虛擬機。我創建了一個用戶和角色並添加了測試數據。在我嘗試設置副本集之前一切正常。當我運行 rs.initiate() 時,我得到“...replSetHeartbeat 需要身份驗證...”錯誤如下所示。我可以通過傳遞 ‑‑host "nodeserver‑hulk:27017" 手動從“hawkeye”連接到“hulk”服務器。有什麼想法嗎?

system

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


參考解法

方法 1:

You need to add a keyFile in your security config so that each node can authenticate against the others.

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

security:
  keyFile: <path‑to‑keyfile>

(by James Morrisjames)

參考文件

  1. mongodb replica set error "...replSetHeartbeat requires authentication..." after running rs.initiate() (CC BY‑SA 2.5/3.0/4.0)

#mongo-shell #replication #mongoDB






相關問題

Windows 是否有任何 mongo shell 擴展? (Is there any mongo shell extensions for windows?)

獲取查詢中所有文檔的大小 (Get the size of all the documents in a query)

如何從 java 程序運行 mongo 查詢? (How to run a mongo query from java program?)

MongoDB 更新 ObjectId 字段 (MongoDB update ObjectId field)

MongoDB - 將簡單字段更改為對象 (MongoDB - change simple field into an object)

mongoDB aggregate() 在電子郵件對象集合中查找電子郵件時間 (mongoDB aggregate() finding email times in a collection of email objects)

指定在 mongodb .js 腳本中使用哪個數據庫 (Specify which database to use in mongodb .js script)

命令失敗:MongoError:CMD_NOT_ALLOWED:配置文件 (command failed: MongoError: CMD_NOT_ALLOWED: profile)

有沒有辦法在 MongoDB 的一個語句中添加遞增的 id? (Is there a way to add an incrementing id in one statement in MongoDB?)

運行 rs.initiate() 後 mongodb 副本集錯誤“...replSetHeartbeat 需要身份驗證...” (mongodb replica set error "...replSetHeartbeat requires authentication..." after running rs.initiate())

將 mongo shell 連接到受限的 MongoDB Atlas 數據庫? (Connect mongo shell to restricted MongoDB Atlas Database?)

[MongoDB]:更改所有數組字段中的值類型 ([MongoDB]: Changing the type of values in all array fields)







留言討論