node.js 如何只收听 MongoDB 上的本地主机

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4961177/
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-02 13:51:36  来源:igfitidea点击:

How to listen only to localhost on MongoDB

ubuntumongodbnode.js

提问by Stephen

MongoDB Suggeststhat the easy way to handle security is to run it in a trusted environment, given that, "in such a configuration, one must be sure only trusted machines can access database TCP ports."

MongoDB 建议处理安全性的简单方法是在受信任的环境中运行它,因为“在这样的配置中,必须确保只有受信任的机器才能访问数据库 TCP 端口。”

What would be the best approach for doing this? Is there a way for mongodb to natively only listen to localhost?

这样做的最佳方法是什么?mongodb 有没有办法本地只听本地主机?

I'm using ubuntu 10.10

我正在使用 ubuntu 10.10

回答by freedev

Add the following line into mongodb.conf:

将以下行添加到mongodb.conf

bind_ip = 127.0.0.1

As @Josh Rickard stated in comments: don't forget to restart the process after updating the config file:

正如@Josh Rickard 在评论中所说:不要忘记在更新配置文件后重新启动该过程:

service mongodb restart

回答by Scott Hernandez

As Andreas mentioned in a round-about way:

正如安德烈亚斯以一种迂回的方式提到的:

mongod --bind_ip 127.0.0.1

回答by Thibaut Barrère

Note that although it didn't appear in the documentation last time I checked, you can also put this setting in the .conf file (vs. command line).

请注意,虽然我上次检查时它没有出现在文档中,但您也可以将此设置放在 .conf 文件中(相对于命令行)。

No setting = bind to all ips.

无设置 = 绑定到所有 ip。

回答by Rick

No one mentioned the location of the mongodb.conffile which is /etc/mongodb.conf. Double check before running the following commands.

没有人提到mongodb.conf文件的位置,即/etc/mongodb.conf. 在运行以下命令之前仔细检查。

echo "bind_ip = 127.0.0.1" >> /etc/mongodb.conf
service mongodb restart