MongoDB的3.2身份验证失败 [英] MongoDB 3.2 authentication failed

查看:2537
本文介绍了MongoDB的3.2身份验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了以下一组命令的用户。这应该创建一个用户在两个管理​​分贝,以及我的目标分贝( C2D 的):

 #蒙戈127.0.0.1:27017
MongoDB的外壳版本:3.2.6-29-g5c19788
连接:127.0.0.1:27017/test
>使用admin
切换到数据库管理员
>藏品展
system.users
system.version
> db.system.users.find()
> db.createUser({用户:CD2,密码:CD2的角色:[{角色:的dbownerDB:C2D}]})
成功添加用户:{
    用户:CD2
    角色:[
        {
            角色:的dbowner
            DB:C2D
        }
    ]
}
> db.system.users.find()
{_id:admin.cd2,用户:CD2,DB:管理,凭证:{SCRAM-SHA-1:{iterationCount:10000,盐 4g6t9kC + godz7k6QQOfD + A ==,storedKey:m3tDZBQDU2Tlb1lIjLGyTHmr2QQ =,serverKey:GSA4OXSod1s8mBuZBtfmXq2tlTo =},角色:[{角色:的dbowner,DB: C2D}]}
>采用C2D
切换到DB C2D
> db.createUser({用户:CD2,密码:CD2的角色:[{角色:的dbownerDB:C2D}]})
成功添加用户:{
    用户:CD2
    角色:[
        {
            角色:的dbowner
            DB:C2D
        }
    ]
}
>使用admin
切换到数据库管理员
> db.system.users.find()
{_id:admin.cd2,用户:CD2,DB:管理,凭证:{SCRAM-SHA-1:{iterationCount:10000,盐 4g6t9kC + godz7k6QQOfD + A ==,storedKey:m3tDZBQDU2Tlb1lIjLGyTHmr2QQ =,serverKey:GSA4OXSod1s8mBuZBtfmXq2tlTo =},角色:[{角色:的dbowner,DB: C2D}]}
{_id:c2d.cd2,用户:CD2,数据库:C2D,凭证:{SCRAM-SHA-1:{iterationCount:10000,盐 :vnMjnjfykVQS8ujQXeWaYw ==,storedKey:OYXivkmIwuTavlwTGfjrspT6j2E =,serverKey:lw8xqzAaW8V4IQ9wOmQrG2VSp88 =}},角色:[{角色:的dbowner,数据库:C2D}] }

如果我尝试登录,我欢迎与一条错误消息:

 #蒙戈127.0.0.1:27017/c2d -u C2D C2D -p
MongoDB的外壳版本:3.2.6-29-g5c19788
连接:127.0.0.1:27017/c2d
2016-05-22T10:35:41.862 + 0100ÉQUERY [线程1]错误:验证失败。 :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1441:20
@(AUTH):6:1
@(AUTH):1:2例外:登录失败

然后我能够在conf文件的安全功能并重新启动服务器:

 安全性:
  授权:启用

错误仍然是相同的:

 #蒙戈127.0.0.1:27017/c2d -u C2D C2D -p
MongoDB的外壳版本:3.2.6-29-g5c19788
连接:127.0.0.1:27017/c2d
2016-05-22T10:37:43.713 + 0100ÉQUERY [线程1]错误:验证失败。 :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1441:20
@(AUTH):6:1
@(AUTH):1:2例外:登录失败


解决方案

那么,你就需要采取几个步骤顺序以成功创建用户。

首先,你需要创建一个管理员用户。我preFER创建超级用户。

 >使用admin
> db.createUser({用户:根,密码:123456,角色:根]})

重新启动您的MongoDB服务器,并启用与认证 - 身份验证标记。
一旦您的服务器已启动,连接到它作为管理员

>蒙戈<主机:端口> -u根-p123456--authenticationDatabase管理员

一旦连接,创建普通用户。假设你的用户数据库名是 CD2

 >使用CD2
> db.createUser({用户:CD2,密码:CD2角色:[的dbowner]})

如果你看到成功一封邮件,断开蒙戈外壳,并与新的用户重新连接
凭据。

 >蒙戈<主机:端口> / CD2 -uCD2-pCD2

I create a user with the following set of commands. This should create user in both admin db as well as my target db (c2d):

# mongo 127.0.0.1:27017
MongoDB shell version: 3.2.6-29-g5c19788
connecting to: 127.0.0.1:27017/test
> use admin
switched to db admin
> show collections
system.users
system.version
> db.system.users.find()
> db.createUser({user:"cd2", pwd:"cd2", roles:[{role:"dbOwner", db: "c2d"}]})
Successfully added user: {
    "user" : "cd2",
    "roles" : [
        {
            "role" : "dbOwner",
            "db" : "c2d"
        }
    ]
}
> db.system.users.find()
{ "_id" : "admin.cd2", "user" : "cd2", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "4g6t9kC+godz7k6QQOfD+A==", "storedKey" : "m3tDZBQDU2Tlb1lIjLGyTHmr2QQ=", "serverKey" : "GSA4OXSod1s8mBuZBtfmXq2tlTo=" } }, "roles" : [ { "role" : "dbOwner", "db" : "c2d" } ] }
> use c2d
switched to db c2d
> db.createUser({user:"cd2", pwd:"cd2", roles:[{role:"dbOwner", db: "c2d"}]})
Successfully added user: {
    "user" : "cd2",
    "roles" : [
        {
            "role" : "dbOwner",
            "db" : "c2d"
        }
    ]
}
> use admin
switched to db admin
> db.system.users.find()
{ "_id" : "admin.cd2", "user" : "cd2", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "4g6t9kC+godz7k6QQOfD+A==", "storedKey" : "m3tDZBQDU2Tlb1lIjLGyTHmr2QQ=", "serverKey" : "GSA4OXSod1s8mBuZBtfmXq2tlTo=" } }, "roles" : [ { "role" : "dbOwner", "db" : "c2d" } ] }
{ "_id" : "c2d.cd2", "user" : "cd2", "db" : "c2d", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "vnMjnjfykVQS8ujQXeWaYw==", "storedKey" : "OYXivkmIwuTavlwTGfjrspT6j2E=", "serverKey" : "lw8xqzAaW8V4IQ9wOmQrG2VSp88=" } }, "roles" : [ { "role" : "dbOwner", "db" : "c2d" } ] }

If I try to login, I'm welcomed with an error message:

# mongo 127.0.0.1:27017/c2d -u c2d -p c2d
MongoDB shell version: 3.2.6-29-g5c19788
connecting to: 127.0.0.1:27017/c2d
2016-05-22T10:35:41.862+0100 E QUERY    [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1441:20
@(auth):6:1
@(auth):1:2

exception: login failed

Then I enable security features in the conf file and restart the server:

security:
  authorization: enabled

Error is still the same:

# mongo 127.0.0.1:27017/c2d -u c2d -p c2d
MongoDB shell version: 3.2.6-29-g5c19788
connecting to: 127.0.0.1:27017/c2d
2016-05-22T10:37:43.713+0100 E QUERY    [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1441:20
@(auth):6:1
@(auth):1:2

exception: login failed

解决方案

Well, you'll need to take couple of steps in sequence to create user successfully.

First of all, you need to create an administrator user. I prefer creating super user.

> use admin
> db.createUser({user: "root", pwd: "123456", roles:["root"]})

Restart your MongoDB server and enable authentication with --auth flag. Once your server is up, connect to it as administrator

> mongo <host:port> -u "root" -p "123456" --authenticationDatabase "admin"

Once you are connected, create normal user. Assuming your user database name is cd2.

> use cd2
> db.createUser({user: "cd2", pwd: "cd2", roles:["dbOwner"]})

If you see success messsage, disconnect from mongo shell and reconnect with new user credentials.

> mongo <host:port>/cd2 -u "cd2" -p "cd2"

这篇关于MongoDB的3.2身份验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆