MongoDB: dbclient_rs replSetGetStatus failed{ ok: 0.0, errmsg: ‘unauthorized’ }
當我在副本集上使用 mongodump 或 mongorestore 時,這些消息會出現在詳細輸出中:
dbclient_rs replSetGetStatus failed{ ok: 0.0, errmsg: "unauthorized" }
副本集配置為進行身份驗證,並且我連接的使用者帳戶具有 clusterAdmin 角色集,這讓我想知道為什麼客戶端(mongodump/restore)無權執行 replSetGetStatus。
連接使用者在 admin 數據庫上具有userAdminAnyDatabase、readWriteAnyDatabase、dbAdminAnyDatabase和clusterAdmin角色。
這是一個範例性的 mongodump 命令:
mongodump --host rs0/host0.example.org,host1.example.org,host2.example.org \ --port 27017 \ --ssl \ --ipv6 \ --verbose \ --authenticationDatabase admin \ --username *user* \ --password *password* \ --out bakdir \ --db admin
mongod、mongodump 和 mongorestore 是 2.4.10 版,從 Debian Jessie (stable) 儲存庫安裝。
我想知道它為什麼會失敗,這些失敗的影響是什麼以及我可以做些什麼(除了關閉身份驗證;-)。除了這個怪癖 mongodump/restore 似乎做得很好。
這是來自 mongodump 的詳細日誌輸出(時間戳被截斷和主機名被替換):
[Timestamp.381] starting new replica set monitor for replica set rs0 with seed of host0.example.org:27017,host1.example.org:27017,host2.example.org:27017 [Timestamp.381] creating new connection to:host0.example.org:27017 [Timestamp.383] BackgroundJob starting: ConnectBG [Timestamp.412] connected connection! [Timestamp.412] successfully connected to seed host0.example.org:27017 for replica set rs0 [Timestamp.413] ReplicaSetMonitor::_checkConnection: host0.example.org:27017 { setName: "rs0", ismaster: true, secondary: false, hosts: [ "host0.example.org:27017", "host2.example.org:27017", "host1.example.org:27017" ], primary: "host0.example.org:27017", me: "host0.example.org:27017", maxBsonObjectSize: 16777216, maxMessageSizeBytes: 48000000, localTime: new Date(1437578036410), ok: 1.0 } [Timestamp.413] changing hosts to { 0: "host0.example.org:27017", 1: "host2.example.org:27017", 2: "host1.example.org:27017" } from rs0/ [Timestamp.413] trying to add new host host0.example.org:27017 to replica set rs0 [Timestamp.413] creating new connection to:host0.example.org:27017 [Timestamp.415] BackgroundJob starting: ConnectBG [Timestamp.439] connected connection! [Timestamp.439] successfully connected to new host host0.example.org:27017 in replica set rs0 [Timestamp.439] trying to add new host host1.example.org:27017 to replica set rs0 [Timestamp.439] creating new connection to:host1.example.org:27017 [Timestamp.440] BackgroundJob starting: ConnectBG [Timestamp.448] connected connection! [Timestamp.448] successfully connected to new host host1.example.org:27017 in replica set rs0 [Timestamp.448] trying to add new host host2.example.org:27017 to replica set rs0 [Timestamp.448] creating new connection to:host2.example.org:27017 [Timestamp.448] BackgroundJob starting: ConnectBG [Timestamp.477] connected connection! [Timestamp.477] successfully connected to new host host2.example.org:27017 in replica set rs0 [Timestamp.477] creating new connection to:host0.example.org:27017 [Timestamp.478] BackgroundJob starting: ConnectBG [Timestamp.500] connected connection! [Timestamp.501] dbclient_rs replSetGetStatus failed{ ok: 0.0, errmsg: "unauthorized" } [Timestamp.501] _check : rs0/host0.example.org:27017,host1.example.org:27017,host2.example.org:27017 [Timestamp.501] ReplicaSetMonitor::_checkConnection: host0.example.org:27017 { setName: "rs0", ismaster: true, secondary: false, hosts: [ "host0.example.org:27017", "host2.example.org:27017", "host1.example.org:27017" ], primary: "host0.example.org:27017", me: "host0.example.org:27017", maxBsonObjectSize: 16777216, maxMessageSizeBytes: 48000000, localTime: new Date(1437578036498), ok: 1.0 } [Timestamp.502] dbclient_rs replSetGetStatus failed{ ok: 0.0, errmsg: "unauthorized" } [Timestamp.502] Primary for replica set rs0 changed to host0.example.org:27017 [Timestamp.503] ReplicaSetMonitor::_checkConnection: host0.example.org:27017 { setName: "rs0", ismaster: true, secondary: false, hosts: [ "host0.example.org:27017", "host2.example.org:27017", "host1.example.org:27017" ], primary: "host0.example.org:27017", me: "host0.example.org:27017", maxBsonObjectSize: 16777216, maxMessageSizeBytes: 48000000, localTime: new Date(1437578036500), ok: 1.0 } [Timestamp.503] dbclient_rs replSetGetStatus failed{ ok: 0.0, errmsg: "unauthorized" } [Timestamp.504] ReplicaSetMonitor::_checkConnection: host1.example.org:27017 { setName: "rs0", ismaster: false, secondary: true, hosts: [ "host1.example.org:27017", "host2.example.org:27017", "host0.example.org:27017" ], primary: "host0.example.org:27017", me: "host1.example.org:27017", maxBsonObjectSize: 16777216, maxMessageSizeBytes: 48000000, localTime: new Date(1437578036504), ok: 1.0 } [Timestamp.505] creating new connection to:host1.example.org:27017 [Timestamp.506] BackgroundJob starting: ConnectBG [Timestamp.514] connected connection! [Timestamp.515] dbclient_rs replSetGetStatus failed{ ok: 0.0, errmsg: "unauthorized" } [Timestamp.516] ReplicaSetMonitor::_checkConnection: host2.example.org:27017 { setName: "rs0", ismaster: false, secondary: true, hosts: [ "host2.example.org:27017", "host1.example.org:27017", "host0.example.org:27017" ], primary: "host0.example.org:27017", me: "host2.example.org:27017", maxBsonObjectSize: 16777216, maxMessageSizeBytes: 48000000, localTime: new Date(1437578036516), ok: 1.0 } [Timestamp.516] creating new connection to:host2.example.org:27017 [Timestamp.516] BackgroundJob starting: ConnectBG [Timestamp.544] connected connection! [Timestamp.544] dbclient_rs replSetGetStatus failed{ ok: 0.0, errmsg: "unauthorized" } [Timestamp.544] replica set monitor for replica set rs0 started, address is rs0/host0.example.org:27017,host1.example.org:27017,host2.example.org:27017 connected to: rs0/host0.example.org,host1.example.org,host2.example.org:27017 [Timestamp.545] creating new connection to:host0.example.org:27017 [Timestamp.545] BackgroundJob starting: ReplicaSetMonitorWatcher [Timestamp.545] [ReplicaSetMonitorWatcher] starting [Timestamp.546] BackgroundJob starting: ConnectBG [Timestamp.571] connected connection! [Timestamp.573] creating new connection to:host1.example.org:27017 [Timestamp.574] BackgroundJob starting: ConnectBG [Timestamp.582] connected connection! [Timestamp.585] DATABASE: admin to ./admin [Timestamp.589] admin.system.indexes to ./admin/system.indexes.bson [Timestamp.591] 2 objects [Timestamp.591] skipping collection: admin.system.users.$user_1_userSource_1 [Timestamp.591] skipping collection: admin.system.users.$_id_ [Timestamp.591] admin.system.users to ./admin/system.users.bson [Timestamp.593] 2 objects [Timestamp.593] Metadata for admin.system.users to ./admin/system.users.metadata.json [Timestamp.593] admin.system.profile to ./admin/system.profile.bson [Timestamp.646] 2612 objects [Timestamp.646] Metadata for admin.system.profile to ./admin/system.profile.metadata.json
這裡是副本集伺服器對應的 mongodb.log 文件。替換了主機地址和使用者憑據。除毫秒外的時間戳被截斷。Mongodump 在 host2 上執行。從 host1 獲取備份。伺服器日誌中的
SocketException
s 可能值得注意。host0.example.org(主要):
[Timestamp.381] [initandlisten] connection accepted from <backup.client.ipv4.addr>:40668 #46757 (8 connections now open) [Timestamp.410] [conn46757] runQuery called admin.$cmd { ismaster: 1 } [Timestamp.410] [conn46757] run command admin.$cmd { ismaster: 1 } [Timestamp.410] [conn46757] command admin.$cmd command: { ismaster: 1 } ntoreturn:1 keyUpdates:0 reslen:341 0ms [Timestamp.413] [initandlisten] connection accepted from <backup.client.ipv4.addr>:40669 #46758 (9 connections now open) [Timestamp.416] [journal] journal WRITETODATAFILES 0.144ms [Timestamp.476] [initandlisten] connection accepted from <backup.client.ipv4.addr>:40672 #46759 (10 connections now open) [Timestamp.497] [conn46759] runQuery called admin.$cmd { replSetGetStatus: 1 } [Timestamp.497] [conn46759] run command admin.$cmd { replSetGetStatus: 1 } [Timestamp.497] [conn46759] command denied: { replSetGetStatus: 1 } [Timestamp.497] [conn46759] command admin.$cmd command: { replSetGetStatus: 1 } ntoreturn:1 keyUpdates:0 reslen:62 0ms [Timestamp.498] [conn46757] SocketException: remote: <backup.client.ipv4.addr>:40668 error: 9001 socket exception [CLOSED] server [<backup.client.ipv4.addr>:40668] [Timestamp.498] [conn46757] end connection <backup.client.ipv4.addr>:40668 (9 connections now open) [Timestamp.498] [conn46758] runQuery called admin.$cmd { ismaster: 1 } [Timestamp.498] [conn46758] run command admin.$cmd { ismaster: 1 } [Timestamp.498] [conn46758] command admin.$cmd command: { ismaster: 1 } ntoreturn:1 keyUpdates:0 reslen:341 0ms [Timestamp.499] [conn46759] runQuery called admin.$cmd { replSetGetStatus: 1 } [Timestamp.499] [conn46759] run command admin.$cmd { replSetGetStatus: 1 } [Timestamp.499] [conn46759] command denied: { replSetGetStatus: 1 } [Timestamp.499] [conn46759] command admin.$cmd command: { replSetGetStatus: 1 } ntoreturn:1 keyUpdates:0 reslen:62 0ms [Timestamp.500] [conn46758] runQuery called admin.$cmd { ismaster: 1 } [Timestamp.500] [conn46758] run command admin.$cmd { ismaster: 1 } [Timestamp.500] [conn46758] command admin.$cmd command: { ismaster: 1 } ntoreturn:1 keyUpdates:0 reslen:341 0ms [Timestamp.500] [conn46759] runQuery called admin.$cmd { replSetGetStatus: 1 } [Timestamp.500] [conn46759] run command admin.$cmd { replSetGetStatus: 1 } [Timestamp.500] [conn46759] command denied: { replSetGetStatus: 1 } [Timestamp.501] [conn46759] command admin.$cmd command: { replSetGetStatus: 1 } ntoreturn:1 keyUpdates:0 reslen:62 0ms [Timestamp.544] [initandlisten] connection accepted from <backup.client.ipv6.addr>:56132 #46760 (10 connections now open) [Timestamp.569] [conn46760] runQuery called admin.$cmd { getnonce: 1 } [Timestamp.569] [conn46760] run command admin.$cmd { getnonce: 1 } [Timestamp.569] [conn46760] command admin.$cmd command: { getnonce: 1 } ntoreturn:1 keyUpdates:0 reslen:65 0ms [Timestamp.569] [conn46760] runQuery called admin.$cmd { authenticate: 1, nonce: "**nonce**", user: "**user**", key: "**key**" } [Timestamp.569] [conn46760] run command admin.$cmd { authenticate: 1, nonce: "**nonce**", user: "**user**", key: "**key**" } [Timestamp.569] [conn46760] authenticate db: admin { authenticate: 1, nonce: "**nonce**", user: "**user**", key: "**key**" } [Timestamp.570] [conn46760] user:**user**@admin command admin.$cmd command: { authenticate: 1, nonce: "**nonce**", user: "**user**", key: "**key**" } ntoreturn:1 keyUpdates:0 locks(micros) r:235 reslen:79 0ms [Timestamp.623] [journal] journal WRITETODATAFILES 0.073ms [Timestamp.648] [conn46758] SocketException: remote: <backup.client.ipv4.addr>:40669 error: 9001 socket exception [CLOSED] server [<backup.client.ipv4.addr>:40669] [Timestamp.648] [conn46758] end connection <backup.client.ipv4.addr>:40669 (9 connections now open) [Timestamp.649] [conn46759] SocketException: remote: <backup.client.ipv4.addr>:40672 error: 9001 socket exception [CLOSED] server [<backup.client.ipv4.addr>:40672] [Timestamp.649] [conn46759] end connection <backup.client.ipv4.addr>:40672 (8 connections now open) [Timestamp.649] [conn46760] user:**user**@admin SocketException: remote: <backup.client.ipv6.addr>:56132 error: 9001 socket exception [CLOSED] server [<backup.client.ipv6.addr>:56132] [Timestamp.649] [conn46760] user:**user**@admin end connection <backup.client.ipv6.addr>:56132 (7 connections now open) [Timestamp.677] [conn46756] user:**user**@admin SocketException: remote: <backup.client.ipv6.addr>:56124 error: 9001 socket exception [CLOSED] server [<backup.client.ipv6.addr>:56124] [Timestamp.677] [conn46756] user:**user**@admin end connection <backup.client.ipv6.addr>:56124 (6 connections now open)
host1.example.org(從中獲取備份的輔助和主機):
[Timestamp.442] [initandlisten] connection accepted from <backup.client.ipv4.addr>:33206 #46856 (3 connections now open) [Timestamp.504] [conn46856] runQuery called admin.$cmd { ismaster: 1 } [Timestamp.504] [conn46856] run command admin.$cmd { ismaster: 1 } [Timestamp.504] [conn46856] command admin.$cmd command: { ismaster: 1 } ntoreturn:1 keyUpdates:0 reslen:341 0ms [Timestamp.507] [initandlisten] connection accepted from <backup.client.ipv4.addr>:33209 #46857 (4 connections now open) [Timestamp.515] [conn46857] runQuery called admin.$cmd { replSetGetStatus: 1 } [Timestamp.515] [conn46857] run command admin.$cmd { replSetGetStatus: 1 } [Timestamp.515] [conn46857] command denied: { replSetGetStatus: 1 } [Timestamp.515] [conn46857] command admin.$cmd command: { replSetGetStatus: 1 } ntoreturn:1 keyUpdates:0 reslen:62 0ms [Timestamp.575] [initandlisten] connection accepted from <backup.client.ipv6.addr>:60931 #46858 (5 connections now open) [Timestamp.582] [conn46858] runQuery called admin.$cmd { getnonce: 1 } [Timestamp.582] [conn46858] run command admin.$cmd { getnonce: 1 } [Timestamp.582] [conn46858] command admin.$cmd command: { getnonce: 1 } ntoreturn:1 keyUpdates:0 reslen:65 0ms [Timestamp.583] [conn46858] runQuery called admin.$cmd { authenticate: 1, nonce: "**nonce**", user: "**user**", key: "**key**" } [Timestamp.583] [conn46858] run command admin.$cmd { authenticate: 1, nonce: "**nonce**", user: "**user**", key: "**key**" } [Timestamp.583] [conn46858] authenticate db: admin { authenticate: 1, nonce: "**nonce**", user: "**user**", key: "**key**" } [Timestamp.584] [conn46858] user:**user**@admin command admin.$cmd command: { authenticate: 1, nonce: "**nonce**", user: "**user**", key: "**key**" } ntoreturn:1 keyUpdates:0 locks(micros) r:393 reslen:79 0ms [Timestamp.585] [conn46858] user:**user**@admin runQuery called admin.$cmd { isdbgrid: 1 } [Timestamp.585] [conn46858] user:**user**@admin run command admin.$cmd { isdbgrid: 1 } [Timestamp.585] [conn46858] user:**user**@admin command admin.$cmd command: { isdbgrid: 1 } ntoreturn:1 keyUpdates:0 reslen:99 0ms [Timestamp.586] [conn46858] user:**user**@admin runQuery called admin.system.indexes {} [Timestamp.586] [conn46858] user:**user**@admin query admin.system.indexes ntoreturn:0 ntoskip:0 nscanned:2 keyUpdates:0 locks(micros) r:49 nreturned:2 reslen:207 0ms [Timestamp.587] [conn46858] user:**user**@admin runQuery called admin.system.namespaces {} [Timestamp.587] [conn46858] user:**user**@admin query admin.system.namespaces ntoreturn:0 ntoskip:0 nscanned:5 keyUpdates:0 locks(micros) r:39 nreturned:5 reslen:254 0ms [Timestamp.589] [conn46858] user:**user**@admin runQuery called admin.$cmd { count: "system.indexes", query: {} } [Timestamp.589] [conn46858] user:**user**@admin run command admin.$cmd { count: "system.indexes", query: {} } [Timestamp.589] [conn46858] user:**user**@admin command admin.$cmd command: { count: "system.indexes", query: {} } ntoreturn:1 keyUpdates:0 locks(micros) r:17 reslen:48 0ms [Timestamp.590] [conn46858] user:**user**@admin runQuery called admin.$cmd { availablequeryoptions: 1 } [Timestamp.590] [conn46858] user:**user**@admin run command admin.$cmd { availablequeryoptions: 1 } [Timestamp.590] [conn46858] user:**user**@admin command admin.$cmd command: { availablequeryoptions: 1 } ntoreturn:1 keyUpdates:0 reslen:50 0ms [Timestamp.591] [conn46858] user:**user**@admin runQuery called admin.system.indexes { query: {}, $snapshot: true } [Timestamp.591] [conn46858] user:**user**@admin query admin.system.indexes query: { query: {}, $snapshot: true } ntoreturn:0 ntoskip:0 nscanned:2 keyUpdates:0 locks(micros) r:25 nreturned:2 reslen:207 0ms [Timestamp.592] [conn46858] user:**user**@admin runQuery called admin.$cmd { count: "system.users", query: {} } [Timestamp.592] [conn46858] user:**user**@admin run command admin.$cmd { count: "system.users", query: {} } [Timestamp.592] [conn46858] user:**user**@admin command admin.$cmd command: { count: "system.users", query: {} } ntoreturn:1 keyUpdates:0 locks(micros) r:13 reslen:48 0ms [Timestamp.593] [conn46858] user:**user**@admin runQuery called admin.system.users { query: {}, $snapshot: true } [Timestamp.593] [conn46858] user:**user**@admin query admin.system.users query: { query: {}, $snapshot: true } ntoreturn:0 ntoskip:0 nscanned:2 keyUpdates:0 locks(micros) r:79 nreturned:2 reslen:350 0ms [Timestamp.594] [conn46858] user:**user**@admin runQuery called admin.$cmd { count: "system.profile", query: {} } [Timestamp.594] [conn46858] user:**user**@admin run command admin.$cmd { count: "system.profile", query: {} } [Timestamp.594] [conn46858] user:**user**@admin command admin.$cmd command: { count: "system.profile", query: {} } ntoreturn:1 keyUpdates:0 locks(micros) r:14 reslen:48 0ms [Timestamp.595] [conn46858] user:**user**@admin runQuery called admin.system.profile { query: {}, $snapshot: true } [Timestamp.595] [conn46858] user:**user**@admin query admin.system.profile query: { query: {}, $snapshot: true } cursorid:**cursorid** ntoreturn:0 ntoskip:0 exhaust:1 nscanned:102 keyUpdates:0 locks(micros) r:163 nreturned:101 reslen:38501 0ms [Timestamp.597] [conn46858] user:**user**@admin getmore admin.system.profile query: { query: {}, $snapshot: true } cursorid:**cursorid** ntoreturn:0 keyUpdates:0 locks(micros) r:1739 nreturned:2511 reslen:960456 1ms [Timestamp.651] [conn46857] SocketException: remote: <backup.client.ipv4.addr>:33209 error: 9001 socket exception [CLOSED] server [<backup.client.ipv4.addr>:33209] [Timestamp.651] [conn46857] end connection <backup.client.ipv4.addr>:33209 (4 connections now open) [Timestamp.651] [conn46856] SocketException: remote: <backup.client.ipv4.addr>:33206 error: 9001 socket exception [CLOSED] server [<backup.client.ipv4.addr>:33206] [Timestamp.651] [conn46856] end connection <backup.client.ipv4.addr>:33206 (3 connections now open) [Timestamp.652] [conn46858] user:**user**@admin SocketException: remote: <backup.client.ipv6.addr>:60931 error: 9001 socket exception [CLOSED] server [<backup.client.ipv6.addr>:60931] [Timestamp.652] [conn46858] user:**user**@admin end connection <backup.client.ipv6.addr>:60931 (2 connections now open)
host2.example.org(輔助和備份客戶端):
[Timestamp.449] [initandlisten] connection accepted from <backup.client.ipv4.addr>:58052 #46602 (4 connections now open) [Timestamp.474] [conn46601] user:__system@local runQuery called admin.$cmd { replSetHeartbeat: "rs0", v: 4, pv: 1, checkEmpty: false, from: "host1.example.org:27017" } [Timestamp.475] [conn46601] user:__system@local run command admin.$cmd { replSetHeartbeat: "rs0", v: 4, pv: 1, checkEmpty: false, from: "host1.example.org:27017" } [Timestamp.475] [conn46601] user:__system@local command: { replSetHeartbeat: "rs0", v: 4, pv: 1, checkEmpty: false, from: "host1.example.org:27017" } [Timestamp.475] [conn46601] user:__system@local command admin.$cmd command: { replSetHeartbeat: "rs0", v: 4, pv: 1, checkEmpty: false, from: "host1.example.org:27017" } ntoreturn:1 keyUpdates:0 reslen:164 0ms [Timestamp.516] [conn46602] runQuery called admin.$cmd { ismaster: 1 } [Timestamp.516] [conn46602] run command admin.$cmd { ismaster: 1 } [Timestamp.516] [conn46602] command admin.$cmd command: { ismaster: 1 } ntoreturn:1 keyUpdates:0 reslen:334 0ms [Timestamp.516] [initandlisten] connection accepted from <backup.client.ipv4.addr>:58055 #46603 (5 connections now open) [Timestamp.544] [conn46603] runQuery called admin.$cmd { replSetGetStatus: 1 } [Timestamp.544] [conn46603] run command admin.$cmd { replSetGetStatus: 1 } [Timestamp.544] [conn46603] command denied: { replSetGetStatus: 1 } [Timestamp.544] [conn46603] command admin.$cmd command: { replSetGetStatus: 1 } ntoreturn:1 keyUpdates:0 reslen:62 0ms [Timestamp.650] [conn46602] SocketException: remote: <backup.client.ipv4.addr>:58052 error: 9001 socket exception [CLOSED] server [<backup.client.ipv4.addr>:58052] [Timestamp.651] [conn46602] end connection <backup.client.ipv4.addr>:58052 (4 connections now open) [Timestamp.651] [conn46603] SocketException: remote: <backup.client.ipv4.addr>:58055 error: 9001 socket exception [CLOSED] server [<backup.client.ipv4.addr>:58055] [Timestamp.651] [conn46603] end connection <backup.client.ipv4.addr>:58055 (3 connections now open)
原始答案(由於簡單的解釋,留給可能遇到此問題的人):
該
clusterAdmin
角色僅在您對admin
數據庫進行身份驗證時適用,因此除非您指定--authenticationDatabase
選項是admin
在執行時,否則mongodump/mongorestore
我懷疑您在對正在轉儲/恢復的數據庫進行身份驗證時獲得的權限較小,因此會看到錯誤。跟進:
這個問題看起來像一個錯誤,但除了一些無關緊要的問題外,我在這裡找不到與修復相對應的問題。在撰寫本文時,自 2.4.10(2014 年 4 月發布)以來已經有 2 個主要版本,甚至 2.4 也有幾個後續更新(2.4.15 是 2015 年 4 月發布的)。通常我會建議送出一個錯誤,但 2.4 已經達到 EOL,所以除非你可以用 2.6 或 3.0 重現它,否則它不會被執行。
此外,工具(轉儲、恢復等)已經完全重構(甚至有自己的 repo和project),現在甚至用不同的語言編寫。
我不認為這些錯誤會影響您的數據轉儲,因此取決於您要為此付出多少努力,但至少我建議升級到非 EOL 版本的 MongoDB 並重試您的過程。