无法从我的本地机器连接我的 mongoDB 数据库

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

Can't connect my mongoDB database from my local machine

mongodb

提问by Ludo

UPDATED:

更新:

I just start to deal with a new VPS and i am trying to connect its port 27017 (mongodb database) from localhost (using robomongo).

我刚刚开始处理一个新的 VPS,我正在尝试从本地主机(使用 robomongo)连接它的端口 27017(mongodb 数据库)。

It's working on my localhost machine and with another remote server, but i can't connect mongodb on this VPS, what could cause this issue ? I start it this way:

它在我的本地主机和另一个远程服务器上工作,但我无法在这个 VPS 上连接 mongodb,是什么导致了这个问题?我是这样开始的:

mongod --setParameter enableLocalhostAuthBypass=0 --config /etc/mongodb.conf --fork

with the auth = trueuncommented in the /etc/mongodb.conf file (but it looks like the issue is not that i can't auth but mongodb is not responding at all). When i start mongo admin -u root -p rootby being connected with SSH, it works great (i can connect my database) and i can see that mongodb is well listenning on the port 27017.

auth = true在/etc/mongodb.conf文件中注释掉(但看起来这个问题不是我不能权威性,但MongoDB是不是在所有响应)。当我开始mongo admin -u root -p root与 SSH 连接时,它工作得很好(我可以连接我的数据库)并且我可以看到 mongodb 正在很好地侦听端口 27017。

But when i try to access it from my local machine, it can't establish the connection, and if i try to connect it with my browser, i am supposed to get a mongodb error message: You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port numberbut i don't, i just have a failure page with Chrome (and the port 28017 is not responding either).

但是当我尝试从我的本地机器访问它时,它无法建立连接,如果我尝试用我的浏览器连接它,我应该收到一条 mongodb 错误消息:You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number但我没有,我只是有Chrome 的失败页面(并且端口 28017 也没有响应)。

How to solve this ? My VPS is brand new and i could need to install more packages but i really don't see what could be need for this, it also looks like a firewall issue, like something prevent mongodb and response before the request could reach it, i have juste installed apache2 and nginx and they are not running so i really don't see...

如何解决这个问题?我的 VPS 是全新的,我可能需要安装更多的软件包,但我真的不明白这可能需要什么,它看起来也像一个防火墙问题,比如在请求到达之前阻止了 mongodb 和响应,我有juste 安装了 apache2 和 nginx,但它们没有运行,所以我真的没有看到...

回答by Ludo

Ok, I have found the issue!

好的,我找到了问题!

There is a line bind_ip 127.0.0.1in the /etc/mongod.conffile. It provides access only to the specified IP address to mongodb.

有一行bind_ip 127.0.0.1/etc/mongod.conf的文件。它仅向 mongodb 提供对指定 IP 地址的访问。

You should create an array of IPs and edit the config file as:

您应该创建一个 IP 数组并将配置文件编辑为:

bind_ip [127.0.0.1, x.x.x.x, ...]

Where x.x.x.xis your IP.

x.x.x.x你的IP在哪里。

回答by nivas

i resolved this issue with file(/etc/mongod.conf) commenting out as follows:

我用 file(/etc/mongod.conf) 注释解决了这个问题,如下所示:

#bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.

#bindIp: 127.0.0.1 # 只监听本地接口,注释监听所有接口。