windows MongoDB:服务器有启动警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36660117/
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
MongoDB: Server has startup warnings
提问by meiyl
I firstly installed MongoDB 3.2.5 today. But when I start it and use MongoDB shell, it gave me these warnings below:
我今天首先安装了 MongoDB 3.2.5。但是当我启动它并使用 MongoDB shell 时,它给了我以下警告:
C:\Windows\system32>mongo
MongoDB shell version: 3.2.5
connecting to: test
Server has startup warnings:
2016-04-16T11:06:17.943+0800 I CONTROL [initandlisten]
2016-04-16T11:06:17.943+0800 I CONTROL [initandlisten] ** WARNING: Insecure configuration, access control is not enabled and no --bind_ip has been specified.
2016-04-16T11:06:17.943+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted,
2016-04-16T11:06:17.943+0800 I CONTROL [initandlisten] ** and the server listens on all available network interfaces.
2016-04-16T11:06:17.943+0800 I CONTROL [initandlisten]
>
my OS is Microsoft Windows [version 10.0.10586
].
我的操作系统是 Microsoft Windows [ version 10.0.10586
]。
回答by Lakmal Vithanage
You haven't configure the security features in Mongodb like authorization and authentication. Use this linkfor more details. You can ignore this if you are going to learn Mongodb. But when the product is going to production level. you should concern them. You can enable access control by using mongod --auth.
您还没有在 Mongodb 中配置授权和身份验证等安全功能。使用此链接了解更多详情。如果你打算学习 Mongodb,你可以忽略这一点。但是当产品进入生产水平时。你应该关心他们。您可以使用 mongod --auth 启用访问控制。
For example you can run mongod --auth --port 27017 --dbpath /data/db1
. After that you can secure your database with username and password.
例如,您可以运行mongod --auth --port 27017 --dbpath /data/db1
. 之后,您可以使用用户名和密码保护您的数据库。
you can add user in database using following command.
您可以使用以下命令在数据库中添加用户。
use admin
db.auth("myUserAdmin", "abc123" )
After that you can use mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"
to connect to the database.
之后就可以使用mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"
连接数据库了。
You can add bind_ip
in mongod.conf as follows,
您可以bind_ip
在 mongod.conf 中添加如下,
`bind_ip = 127.0.0.1,192.168.161.100`
You can define many if you need. This bind_ip option tells MongoDB to accept connections from which local network interfaces, not which “remote IP address”.
And run mongod --config <file path to your mongod.conf>
Altogether you can run mongod --auth --port 27017 --dbpath /data/db1 --config <file path to your mongod.conf>
如果需要,您可以定义多个。这个 bind_ip 选项告诉 MongoDB 接受来自哪个本地网络接口的连接,而不是哪个“远程 IP 地址”。并运行mongod --config <file path to your mongod.conf>
总而言之你可以运行mongod --auth --port 27017 --dbpath /data/db1 --config <file path to your mongod.conf>
回答by Evan Hu
回答by Mehraj Malik
- Select the target DB (Exp :
use admin
) - Create user in the selected DB
- 选择目标数据库 (Exp :
use admin
) - 在选定的数据库中创建用户
Select the required DB (exp use admin
)
选择所需的数据库 (exp use admin
)
db.createUser(
{
user: "root",
pwd: "root",
roles: [ "readWrite", "dbAdmin" ]
}
)
The above command will create the root
user with rolesreadWrite
and dbAdmin
in the admin
DB. more info about roles
上面的命令将创建root
与用户的角色readWrite
,并dbAdmin
在admin
数据库中。有关角色的更多信息
Now, run the server in authentication mode using mongod --auth
现在,使用身份验证模式运行服务器 mongod --auth
Run client and provide username and password to login using db.auth("root","root")
运行客户端并提供用户名和密码以使用登录 db.auth("root","root")