mongodb 连接到远程 mongo 服务器导致异常连接失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14010351/
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
connecting to remote mongo server results in exception connect failed
提问by spracketchip
Running this command in the mongodb installation file from mongodb.org
在 mongodb.org 的 mongodb 安装文件中运行此命令
./mongo ds045907.mongolab.com:45907/database -u user -p password
I changed Database, user, and password for anonymity.
为了匿名,我更改了数据库、用户和密码。
results in this
结果在这
Error: couldn't connect to server ds045907.mongolab.com:45907 src/mongo/shell/mongo.js:93
exception: connect failed
Maybe i'm being blocked by a server firewall? I have no problem using git or brew or pip...
也许我被服务器防火墙阻止了?我使用 git 或 brew 或 pip 没有问题...
采纳答案by coderLMN
It's a connection problem at your side. I tried it but got a login failure message:
这是您这边的连接问题。我试过了,但收到登录失败消息:
MongoDB shell version: 1.6.5
connecting to: ds045907.mongolab.com:45907/database
Mon Dec 24 01:12:31 uncaught exception: login failed
exception: login failed
MongoDB 外壳版本:1.6.5
连接到:ds045907.mongolab.com:45907/database
Mon Dec 24 01:12:31 未捕获异常:登录失败
异常:登录失败
回答by jared
Here are a few things you can try, but you can always feel free to contact us at [email protected]. I'm sure we can get to the bottom of this.
以下是您可以尝试的一些方法,但您可以随时通过 [email protected] 与我们联系。我相信我们可以深入了解这件事。
Anonymous mongo shell connection
匿名 mongo shell 连接
Mongo will let you connect without authenticating. You can do very little with an unauthenticated connection, but you can use it as a test to separate a connectivity problem from a credentials problem.
Mongo 将让您无需身份验证即可连接。您对未经身份验证的连接几乎无能为力,但您可以将其用作测试,将连接问题与凭据问题区分开来。
% mongo ds045907.mongolab.com:45907
MongoDB shell version: 2.0.7
connecting to: ds045907.mongolab.com:45907/test
> db.version()
2.2.2
> db.runCommand({ping:1})
{ "ok" : 1 }
> exit
bye
If you can connect without authenticating and run the commands as shown above, but trying to connect with authentication fails, then you have a problem with the credentials. If, however, connecting doesn't work even without supplying credentials then you have a connectivity problem.
如果您无需身份验证即可连接并运行如上所示的命令,但尝试使用身份验证连接失败,则您的凭据有问题。但是,如果即使不提供凭据也无法连接,那么您就有了连接问题。
ping
平
That server does allow ICMP traffic, so make sure it's reachable from wherever you are.
该服务器确实允许 ICMP 流量,因此请确保无论您身在何处都可以访问它。
% ping ds045907.mongolab.com
PING ec2-107-20-85-188.compute-1.amazonaws.com (107.20.85.188): 56 data bytes
64 bytes from 107.20.85.188: icmp_seq=0 ttl=41 time=99.744 ms
64 bytes from 107.20.85.188: icmp_seq=1 ttl=41 time=99.475 ms
64 bytes from 107.20.85.188: icmp_seq=2 ttl=41 time=99.930 ms
^C
--- ec2-107-20-85-188.compute-1.amazonaws.com ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 99.475/99.716/99.930/0.187 ms
traceroute
跟踪路由
If ping
fails, use traceroute
(or tracert
on Windows) to try to figure out where the problem is. Once the trace reaches AWS, however, it will trail off. That's normal. AWS prevents traces from seeing too far into their networks. Make sure that the last IP on your list is owned by Amazon using some kind of IP reverse lookup tool (many on the Web).
如果ping
失败,请使用traceroute
(或tracert
在 Windows 上)尝试找出问题所在。但是,一旦跟踪到达 AWS,它就会减弱。这是正常的。AWS 可防止痕迹深入到他们的网络中。使用某种 IP 反向查找工具(网络上有很多)确保您列表中的最后一个 IP 归亚马逊所有。
% traceroute ds045907.mongolab.com
traceroute to ec2-107-20-85-188.compute-1.amazonaws.com (107.20.85.188), 64 hops max, 52 byte packets
1 192.168.1.1 (192.168.1.1) 1.092 ms 0.865 ms 1.047 ms
2 192.168.27.1 (192.168.27.1) 1.414 ms 1.330 ms 1.224 ms
... snipped to protect the innocent ...
14 72.21.220.83 (72.21.220.83) 87.777 ms
72.21.220.75 (72.21.220.75) 87.406 ms
205.251.229.55 (205.251.229.55) 99.363 ms
15 72.21.222.145 (72.21.222.145) 87.703 ms
178.236.3.24 (178.236.3.24) 98.662 ms
72.21.220.75 (72.21.220.75) 87.708 ms
16 216.182.224.55 (216.182.224.55) 87.312 ms 86.791 ms 89.005 ms
17 * 216.182.224.55 (216.182.224.55) 91.373 ms *
18 216.182.224.55 (216.182.224.55) 121.754 ms * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *