MongoDB:服务器有启动警告“未为数据库启用访问控制”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41615574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:52:59  来源:igfitidea点击:

MongoDB: Server has startup warnings ''Access control is not enabled for the database''

mongodb

提问by alewu

I firstly installed MongoDB 3.4.1 today. But when I start it and use MongoDB shell, it gave me these warnings below:

我今天首先安装了 MongoDB 3.4.1。但是当我启动它并使用 MongoDB shell 时,它给了我以下警告:

C:\Users\hs>"C:\Program Files\MongoDB\Server.4\bin\mongo.exe
MongoDB shell version v3.4.1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.1
Server has startup warnings:
2017-01-12T21:19:46.941+0800 I CONTROL  [initandlisten]
2017-01-12T21:19:46.942+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-01-12T21:19:46.942+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-01-12T21:19:46.942+0800 I CONTROL  [initandlisten]

my computer is Microsoft Windows [version 10.0.14393].

我的电脑是 Microsoft Windows [ version 10.0.14393]。

回答by Karl Morrison

Mongodb v3.4

MongoDB v3.4

You need to do the following to create a secure database:

您需要执行以下操作来创建安全数据库:

Make sure the user starting the process has permissions and that the directories exist (/data/dbin this case).

确保启动该进程的用户具有权限并且目录存在(/data/db在本例中)。

1) Start MongoDB without access control.

1)在没有访问控制的情况下启动MongoDB。

mongod --port 27017 --dbpath /data/db

2) Connect to the instance.

2) 连接到实例。

mongo --port 27017

3) Create the user administrator (in the admin authentication database).

3)创建用户管理员(在admin认证数据库中)

use admin
db.createUser(
  {
    user: "myUserAdmin",
    pwd: "abc123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

4) Re-start the MongoDB instance with access control.

4) 重启带有访问控制的MongoDB实例。

mongod --auth --port 27017 --dbpath /data/db

5) Connect and authenticate as the user administrator.

5) 以用户管理员身份进行连接和验证。

mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"

6) Create additional users as needed for your deployment (e.g. in the test authentication database).

6) 根据您的部署的需要(例如在测试认证数据库中)创建额外的用户。

use test
db.createUser(
  {
    user: "myTester",
    pwd: "xyz123",
    roles: [ { role: "readWrite", db: "test" },
             { role: "read", db: "reporting" } ]
  }
)

7) Connect and authenticate as myTester.

7) 以 myTester 身份连接并进行身份验证。

mongo --port 27017 -u "myTester" -p "xyz123" --authenticationDatabase "test"

I basically just explained the short version of the official docs here: https://docs.mongodb.com/master/tutorial/enable-authentication/

我基本上只是在这里解释了官方文档的简短版本:https: //docs.mongodb.com/master/tutorial/enable-authentication/

回答by Parag

You need to delete your old db folder and recreate new one. It will resolve your issue.

您需要删除旧的 db 文件夹并重新创建新文件夹。它将解决您的问题。