【问题标题】:My MongoDB authentication config is not working我的 MongoDB 身份验证配置不起作用
【发布时间】:2019-08-27 09:37:06
【问题描述】:

我在我的 Mac 上使用自制软件安装了 MongoDB。
我在本地 mongodb 上创建了管理员帐户。
然后,我将以下代码添加到我的“mongod.conf”中以使用身份验证模式。
代码是“安全:授权:启用”。

systemLog:
  destination: file
  path: /usr/local/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /usr/local/var/mongodb
net:
  bindIp: 127.0.0.1
security:
  authorization: enabled

然后我重新启动了 MongoDB。 '酿造服务重启 mongodb'
但是每当我启动 mongo shell 时,它仍然会打印

WARNING: Access control is not enabled for the database.
Read and write access to data and configuration is unrestricted.

自然无需用户连接即可使用。
我该如何解决这个问题?
如果我输入

db.auth("username", "password")

它打印“1”。 如果我使用自制软件,是否无法对 mongoDB 进行身份验证?
我不知道我要做什么了。
请帮帮我。
谢谢。


+ 这是完整的日志

MongoDB shell version v4.0.3
connecting to: mongodb://127.0.0.1:27017
Implicit session: session { "id" : UUID("573560e4-0a3a-472e-a94a-79b1cecab4fd") }
MongoDB server version: 4.0.3
Server has startup warnings: 
2019-08-27T19:02:40.847+0900 I CONTROL  [initandlisten] 
2019-08-27T19:02:40.847+0900 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-08-27T19:02:40.847+0900 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-08-27T19:02:40.847+0900 I CONTROL  [initandlisten] 
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()

【问题讨论】:

    标签: mongodb macos authentication homebrew


    【解决方案1】:
    1. 尝试删除当前服务
    2. 首先在配置文件中启用授权,然后第一次运行 mongod daemon。
    3. mongo 允许“本地主机异常”。在文档中阅读它
    4. 然后在 admin 数据库上创建具有所需权限的第一个帐户。确保包括创建其他用户的权限。
    5. 重启 mongod 守护进程。

    检查错误是否消失..

    重点是在创建任何用户之前启用授权,甚至在管理员之前。

    【讨论】:

      【解决方案2】:

      我没有看到您在配置文件中指定了身份验证机制。请将其添加到您的 mongod 配置文件中

      security:
        authorization: enabled
      
      setParameter:
        authenticationMechanisms: SCRAM-SHA-1
      

      完成上述操作后,重新启动您的 mongo 实例,这应该可以工作

      【讨论】:

      • 我按照你上面的方法。它不工作......我附上了我的配置文件(mongod.conf)。请检查文件。感谢 Anban 的快速回复。
      • systemLog: 目的地: 文件路径: /usr/local/var/log/mongodb/mongo.log logAppend: true storage: dbPath: /usr/local/var/mongodb net: bindIp: 127.0. 0.1 安全性:授权:启用 setParameter: authenticationMechanisms: SCRAM-SHA-1
      • 你有任何错误吗?您还可以检查 mongod 日志文件中记录的内容并将其发布在此处吗?
      • 我不确定它为什么不读取身份验证机制。您能否尝试使用以下链接docs.mongodb.com/manual/reference/parameters/… 中指定的命令重新启动您的服务
      • 最后,我放弃了尝试使用自制软件启动服务器。我仍然不知道为什么我的配置不起作用。无论如何... 'brew services start mongodb' (x) -> 'mongod --auth' (o) 现在,它可以工作了。感谢您的帮助。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 2017-02-28
      • 2012-10-04
      • 2017-07-09
      相关资源
      最近更新 更多