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

cnh2zyt3  于 11个月前  发布在  Go
关注(0)|答案(4)|浏览(105)

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

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 ]。

aurhwmvo

aurhwmvo1#

Mongodb v3.4
您需要执行以下操作来创建安全数据库:
确保启动进程的用户具有权限,并且目录存在(本例中为/data/db)。
1)在没有访问控制的情况下启动MongoDB

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

字符串
2)连接到示例。

mongo --port 27017


3)创建用户administrator (在管理员身份验证数据库中)

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


4)使用访问控制重新启动MongoDB示例。

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


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

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


6)根据您的部署需要创建其他用户 (例如,在测试身份验证数据库中)

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


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

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


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

ux6nzvsh

ux6nzvsh2#

你需要做的就是:
1.编辑您的配置,例如C:\Program Files\MongoDB\Server\4.4\bin\mongodb.cfg
1.将security: authorization:转换为enabled,如图所示;注意,这个子条目可能完全丢失。然后添加它。
1.从Windows服务控制面板重新启动MongoDB Server服务。
x1c 0d1x的数据
显然,如果在此之后,设置一个基于角色的读/读写策略,这将更有意义。
参考号:https://docs.mongodb.com/manual/tutorial/configure-scram-client-authentication/
我刚刚用phpunit测试了一下,效果和预期的一样。

4ioopgfo

4ioopgfo3#

你可以创建一个admin用户或另一个role.在mongo shell上运行它.

db.createUser({user: "username", pwd: "password", roles: ["dbAdmin"]})

字符串
如果你得到SCRAM-SHA-256错误,你可以设置SHA-1机制。

db.createUser({user: "username", pwd: "password", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"]})

ewm0tg9j

ewm0tg9j4#

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

相关问题