代码改变世界

【MongoDB】日志报错not authorized on admin to execute command

  abce  阅读(2457)  评论(0编辑  收藏  举报

安装mongodb exporter监控之后,mongodb的日志一直报错:

1
{"t":{"$date":"2022-09-08T10:36:50.708+08:00"},"s":"I""c":"ACCESS",   "id":20736,   "ctx":"conn32068","msg":"Checking authorization failed","attr":{"error":{"code":13,"codeName":"Unauthorized","errmsg":"not authorized on admin to execute command { find: \"system.version\", filter: { _id: \"shardIdentity\" }, limit: 1, singleBatch: true, lsid: { id: UUID(\"c0161773-77bc-7da2-828b-ad730c188a55\") }, $clusterTime: { clusterTime: Timestamp(1662607605, 1), signature: { hash: BinData(0, 379A5DE7CGB83EC220EDBC59070EA7BA5178B97C), keyId: 7138260557136744207 } }, $db: \"admin\", $readPreference: { mode: \"primaryPreferred\" } }"}}}

  

后台登录数据库查看

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
> db.system.version.find( {"_id" : "shardIdentity" } )
Error: error: {
        "ok" : 0,
        "errmsg" : "not authorized on admin to execute command { find: \"system.version\", filter: { _id: \"shardIdentity\" }, lsid: { id: UUID(\"db3f050d-1c97-712d-8ad3-9c9df27d6c67\") }, $clusterTime: { clusterTime: Timestamp(1662603775, 1), signature: { hash: BinData(0, 1B730731E36DB0D3DA5E27D67C55DDF532D0E73C), keyId: 7138260557136744207 } }, $db: \"admin\" }",
        "code" : 13,
        "codeName" : "Unauthorized",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1662603795, 1),
                "signature" : {
                        "hash" : BinData(0,"t6CLGusPe6gT6S7lpzwIF88hfK7="),
                        "keyId" : NumberLong("7138260557136744207")
                }
        },
        "operationTime" : Timestamp(1662603795, 1)
}
>

  

此错误是因为没有授权给监控用户对system.version表执行命令的权限,解决方法如下:

1
> db.grantRolesToUser ( "my_exporter", [ { role: "__system", db: "admin" } ] )

  

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-09-08 MySQL中的比较操作符<=>
2019-09-08 Python中的args和kwargs
点击右上角即可分享
微信分享提示