mongodb 如何更改默认端口

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

mongodb how to change default port

mongodb

提问by visualight

For my project I need to use mongodb on port 80. In fact I can't use the default mongodb port (27017). I must use port 80.

对于我的项目,我需要在端口 80 上使用 mongodb。事实上,我无法使用默认的 mongodb 端口 (27017)。我必须使用端口 80。

If I edit the config file:

如果我编辑配置文件:

sudo nano /etc/mongodb.conf

and I change the port to 80 then I restart mongodb service, I get this message when I try to connect to mongodb

我将端口更改为 80 然后我重新启动 mongodb 服务,当我尝试连接到 mongodb 时收到此消息

$ mongo --port 80

MongoDB shell version: 2.4.9
connecting to: 127.0.0.1:80/test
Fri Feb  6 14:16:42.705 Error: couldn't connect to server 127.0.0.1:80 at src/mongo/shell/mongo.js:147
exception: connect failed

If I change the port again to 27017, all work fine.

如果我再次将端口更改为 27017,则一切正常。

Can someone help me?

有人能帮我吗?

回答by MCurbelo

Check if port is already open by another application or service:

检查端口是否已被另一个应用程序或服务打开:

on Windows, open cmdand type: netstat -a

在 Windows 上,打开cmd并输入:netstat -a

on Linux, type: netstat -lptn

在 Linux 上,键入: netstat -lptn

Look for open port 80, like TCP 0.0.0.0:80

寻找开放的 80 端口,比如 TCP 0.0.0.0:80

If you can't find it, open mongodb.confand change the netsection:

如果找不到,请打开mongodb.conf并更改该net部分:

net:
   bindIp: 127.0.0.1
   port: 80

I hope this help you

我希望这对你有帮助