MongoDB:服务器具有启动警告“未为数据库启用访问控制" [英] MongoDB: Server has startup warnings ''Access control is not enabled for the database''
问题描述
我今天首先安装了MongoDB 3.4.1.但是,当我启动它并使用MongoDB shell时,它在下面给了我这些警告:
I firstly installed MongoDB 3.4.1 today. But when I start it and use MongoDB shell, it gave me these warnings below:
C:\Users\hs>"C:\Program Files\MongoDB\Server\3.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]
我的计算机是Microsoft Windows [version 10.0.14393
].
my computer is Microsoft Windows [version 10.0.14393
].
推荐答案
Mongodb v3.4
Mongodb v3.4
您需要执行以下操作来创建安全的数据库:
You need to do the following to create a secure database:
确保启动该过程的用户具有权限并且目录存在(在本例中为/data/db
).
Make sure the user starting the process has permissions and that the directories exist (/data/db
in this case).
1)在没有访问控制的情况下启动MongoDB.
1) Start MongoDB without access control.
mongod --port 27017 --dbpath /data/db
2)连接到实例.
mongo --port 27017
3)创建用户管理员(在admin身份验证数据库中).
3) Create the user administrator (in the admin authentication database).
use admin
db.createUser(
{
user: "myUserAdmin",
pwd: "abc123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
4)使用访问控制重新启动MongoDB实例.
4) Re-start the MongoDB instance with access control.
mongod --auth --port 27017 --dbpath /data/db
5)连接并以用户管理员身份进行验证.
5) Connect and authenticate as the user administrator.
mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"
6)根据部署(例如,在测试身份验证数据库中)的需要创建其他用户.
6) Create additional users as needed for your deployment (e.g. in the test authentication database).
use test
db.createUser(
{
user: "myTester",
pwd: "xyz123",
roles: [ { role: "readWrite", db: "test" },
{ role: "read", db: "reporting" } ]
}
)
7)连接并验证为myTester.
7) Connect and authenticate as myTester.
mongo --port 27017 -u "myTester" -p "xyz123" --authenticationDatabase "test"
我基本上只是在这里解释了官方文档的简短版本: https://docs.mongodb.com/master/tutorial/enable-authentication/
I basically just explained the short version of the official docs here: https://docs.mongodb.com/master/tutorial/enable-authentication/
这篇关于MongoDB:服务器具有启动警告“未为数据库启用访问控制"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!