我的 MongoDB 身份验证配置不起作用
My MongoDB authentication config is not working
我在 mac 上使用自制软件安装了 MongoDB。
我在本地 mongodb 上创建了管理员帐户。
然后,我将下面的代码添加到我的 'mongod.conf' 中以使用身份验证模式。
密码是'security: authorization: enabled'.
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。 'brew services restart 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'。 <- 已验证。
如果我使用 homebrew,是否无法验证 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()
我没有看到您在配置文件中指定了身份验证机制。请将其添加到您的 mongod 配置文件
security:
authorization: enabled
setParameter:
authenticationMechanisms: SCRAM-SHA-1
完成上述操作后,重新启动您的 mongo 实例,这应该会起作用
- 尝试删除当前服务
- 首先在配置文件中启用授权,然后 运行 mongod 守护进程第一次。
- mongo 允许 "localhost exception"。在文档中阅读它
- 然后在 admin 数据库上创建具有所需权限的第一个帐户。确保包括创建其他用户的权限。
- 重新启动 mongod 守护程序。
检查错误是否消失..
重点是在创建任何用户之前启用授权,甚至在管理员之前。
我在 mac 上使用自制软件安装了 MongoDB。
我在本地 mongodb 上创建了管理员帐户。
然后,我将下面的代码添加到我的 'mongod.conf' 中以使用身份验证模式。
密码是'security: authorization: enabled'.
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。 'brew services restart 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'。 <- 已验证。
如果我使用 homebrew,是否无法验证 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()
我没有看到您在配置文件中指定了身份验证机制。请将其添加到您的 mongod 配置文件
security:
authorization: enabled
setParameter:
authenticationMechanisms: SCRAM-SHA-1
完成上述操作后,重新启动您的 mongo 实例,这应该会起作用
- 尝试删除当前服务
- 首先在配置文件中启用授权,然后 运行 mongod 守护进程第一次。
- mongo 允许 "localhost exception"。在文档中阅读它
- 然后在 admin 数据库上创建具有所需权限的第一个帐户。确保包括创建其他用户的权限。
- 重新启动 mongod 守护程序。
检查错误是否消失..
重点是在创建任何用户之前启用授权,甚至在管理员之前。