我刚为mongodb实现了auth,有一个用户'admin' db“管理员”和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.
在启用身份验证的mongoldb中执行mongostat的最佳方法是什么?请帮我解决问题或建议最佳身份验证设置。 注意:我的mongodb版本3.0.6
答案 0 :(得分:5)
最后我得到了解决方案,我为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,修复问题