无法连接到启用身份验证的MongoDB [英] Can't connect to MongoDB with authentication enabled

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

问题描述

我正在为Ubuntu 14.04运行最新的MongoDB

I'm running the latest MongoDB for Ubuntu 14.04


  • 我创建了一个名为admin的用户userAdminAnyDatabase / li>
  • 我可以在本地和外部访问数据库

  • 我可以使用SHA-SCRAM-1用admin登录

当我编辑到配置文件以限制访问只有身份验证的东西出了问题时会发生什么:

When I edit to config file to restrict access only with authentication things go wrong. What happens:


  1. 我在配置文件中取消注释#auth = true。

  2. 我无法使用admin帐户的正确凭据访问。

请记住,我在做更改后使用service mongod restart。

Bear in mind that I do use "service mongod restart" after making changes.

配置文件参考:

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0


#processManagement:

#security:
#auth = true
#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:
#snmp:

数据库快照供参考:

出现了什么问题?

推荐答案

我认为 auth = true 是一个无效的配置, 。要启用授权,请尝试改用以下方式:

I think that auth = true is an invalid configuration and your mongod is not starting because of it. To enable authorization, try using the following instead:

security:
  authorization: enabled

然后,要连接到数据库,请确保您的客户端正在使用正确的认证数据库和认证机制。这可以使用命令行通过以下命令:

Then, to connect to the database, make sure that your client is using the correct authentication database and authentication mechanism. This can be done using the commmand line by the following command:

mongo localhost -u admin -p myAdminPass --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-1

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

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