[英]Can't connect to remote mongodb with mongo shell
I am attempting to connect to a remote mongodb service and cannot figure out how to get it to work. 我试图连接到远程mongodb服务,无法弄清楚如何让它工作。 The remote mongod
is running on an Ubuntu box. 远程mongod
在Ubuntu盒子上运行。 I am a very novice unix user, but I'm reasonably certain the problem is that I am not opening up the firewall probably with iptables
, I've tried the commands in the mongodb docs and still no success. 我是一个非常新手的unix用户,但我有理由确定问题是我没有用iptables
打开防火墙,我已经尝试了mongodb文档中的命令但仍然没有成功。
mongodb.conf relevant rules mongodb.conf相关规则
bind_ip = 0.0.0.0
port = 27017
auth = false
netstat -A netstat -A
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:28017 *:* LISTEN
tcp 0 0 *:27017 *:* LISTEN
iptables -L -n iptables -L -n
target prot opt source destination
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
DROP all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:27017 state NEW,ESTABLISHED
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:28017 state NEW,ESTABLISHED
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp spt:27017 state ESTABLISHED
iptables commands executed as documented in mongodb docs at - http://docs.mongodb.org/manual/tutorial/configure-linux-iptables-firewall/#patterns 按照mongodb文档中的说明执行iptables命令 - http://docs.mongodb.org/manual/tutorial/configure-linux-iptables-firewall/#patterns
Here is what I've tried: 这是我尝试过的:
browser: http://xx.xx.xx.xx:27017/ no response. 浏览器: http://xx.xx.xx.xx:27017 /无响应。
browser: http://xx.xx.xx.xx:28017/ no response. 浏览器: http://xx.xx.xx.xx:28017 /无响应。
browser: http://www.hostname.com:27017/ no reponse. 浏览器: http : //www.hostname.com :27017 /无响应。
browser: http://www.hostname.com:28017/ no response. 浏览器: http : //www.hostname.com : 28017 /没有回复。
mongo.exe xx.xx.xx.xx:27017 (remotely) couldn't connect to server xx.xx.xx.xx
mongo.exe xx.xx.xx.xx:27017(远程) couldn't connect to server xx.xx.xx.xx
mongo xx.xx.xx.xx:27017 (from localhost) connects properly mongo xx.xx.xx.xx:27017(来自localhost)正确连接
mongo www.hostname.com:27017 (from localhost) connects properly mongo www.hostname.com:27017(来自localhost)正确连接
The fact that it connects properly over localhost on the server hosting the mongodb, even when I specify the IP address, makes me think it has to be a firewall issue. 通过托管mongodb的服务器上的localhost正确连接的事实,即使我指定IP地址,也让我认为它必须是防火墙问题。 Any ideas? 有任何想法吗?
iptables
rules are read in exactly in the order as they appear. iptables
规则完全按照它们出现的顺序读取。 You now have DROP
taking precedence over ACCEPT
of your mongodb ports. 您现在让DROP
优先于您的mongodb端口的ACCEPT
。
Shuffle the lines in your particular script that sets up iptables and flush and re-read them back in. 在您的特定脚本中随机设置iptables并刷新并重新读取它们。
If you haven't saved your firewall yet, remove the DROP
rule and re-add it again, it will shift it down the list and will also solve your issue. 如果您尚未保存防火墙,请删除DROP
规则并再次重新添加,它会将其移至列表中并解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.