gpt4 book ai didi

mongodb - 为启用身份验证的 mongodb 运行 mongostat 时出现问题

转载 作者:IT老高 更新时间:2023-10-28 13:36:01 24 4
gpt4 key购买 nike

我刚刚为mongodb实现了auth,有一个用户'admin'在 db 'admin' 和 db 'mydb' 中的 'appadmin' 中一切正常。以下是我的数据库身份验证设置:

use admin
db.auth(‘’, ‘’)
db.getUsers()
[
{
"_id" : "admin.admin",
"user" : "admin",
"db" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "clusterMonitor",
"db" : "admin"
}
]
}
]


use mydb
db.auth()
db.getUsers()

{
"_id" : "mydb.appadmin",
"user" : "mydb",
"db" : "mydb",
"roles" : [
{
"role" : "readWrite",
"db" : "mydb"
},
{
"role" : "userAdmin",
"db" : "mydb"
}
]
}
].

如果我运行以下命令,

mongostat --username=admin --password=mypassword  --authenticationDatabase=admin
insert query update delete getmore command flushes mapped vsize res faults qr|qw ar|aw netIn netOut conn time
*0 *0 *0 *0 0 1|0 0 240.0M 678.0M 91.0M 0 0|0 0|0 79b 10k 1 11:49:18
*0 *0 *0 *0 0 1|0 0 240.0M 678.0M 91.0M 0 0|0 0|0 79b 10k 1 11:49:19
*0 *0 *0 *0 0 1|0 0 240.0M 678.0M 91.0M 0 0|0 0|0 79b 10k 1 11:49:20

但是当我运行时

* mongostat --username=appadmin --password=mypassword  --authenticationDatabase=mydb

Failed: not authorized on admin to execute command { serverStatus: 1, recordStats: 0 },

所以我尝试在 mydb 中添加角色“clusterMonitor”。

db.updateUser(“appadmin”, {roles: [{role: "readWrite", db: “mydb”}, {role: "userAdmin", db: “mydb”}, {role: "clusterMonitor", db: “mydb”}]})
E QUERY Error: Updating user failed: No role named clusterMonitor@mydb.

在启用了身份验证的 mongodb 中执行 mongostat 的最佳方法是什么?请帮助我解决问题或建议最佳身份验证设置。注意:我的 mongodb 版本 3.0.6

最佳答案

我终于找到了解决方案,我在 admin db 中添加了更多角色,

use admin
db.getUsers()

{
"_id" : "admin.admin",
"user" : "admin",
"db" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "readWriteAnyDatabase",
"db" : "admin"
},
{
"role" : "dbAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "clusterAdmin",
"db" : "admin"
},
{
"role" : "clusterMonitor",
"db" : "admin"
}
]
}
]

并运行 mongostat --username=admin --password=mypassword --authenticationDatabase=admin,修复问题

关于mongodb - 为启用身份验证的 mongodb 运行 mongostat 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32991747/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com