【发布时间】:2017-01-09 02:27:32
【问题描述】:
这里还有另一个答案:Can't connect to MongoDB with authentication enabled。我试过了,但仍然无法弄清楚我的配置有什么问题。
我使用作为服务安装的 Ubuntu 14.04、Mongo 3.4.1(最新)
安装后我首先运行这个命令,就像它的文档here:
mongo --port 27017
use admin
db.createUser({user: "adminUser",pwd: "abc123",roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]})
它返回Successfully added user。然后我重新配置/etc/mongod.conf
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
net:
port: 27017
bindIp: 127.0.0.1
security:
authorization: enabled
保存并重启 mongod 服务器:sudo service mongod restart
尝试联系:mongo -u "adminUser" -p "abc123" --authenticationDatabase "admin"
成功了,那么如果我用命令use testDatabase切换到另一个数据库,我就不能对其进行任何操作了。
use testDatabase
db.createCollection("people")
结果:
{
"ok" : 0,
"errmsg" : "not authorized on testDatabase to execute command { create: \"people\" }",
"code" : 13,
"codeName" : "Unauthorized"
}
这是我数据库中的注册用户
use admin
db.system.users.find()
{ "_id" : "admin.adminUser",
"user" : "adminUser",
"db" : "admin",
"credentials" : { "SCRAM-SHA-1" : {....} },
"roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ]
}
userAdminAnyDatabase 角色似乎不再起作用或者我的设置有什么问题?
【问题讨论】:
标签: mongodb