我试图连接到远程mongodb服务,无法弄清楚如何让它工作 . 远程 mongod
正在Ubuntu盒子上运行 . 我是一个非常新手的unix用户,但我有理由确定问题是我没有用 iptables
打开防火墙,我已经尝试了mongodb文档中的命令但仍然没有成功 .
mongodb.conf相关规则
bind_ip = 0.0.0.0
port = 27017
auth = false
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
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
如mongodb docs中所述执行的iptables命令 - http://docs.mongodb.org/manual/tutorial/configure-linux-iptables-firewall/#patterns
这是我尝试过的:
浏览器:http://xx.xx.xx.xx:27017/没有回复 .
浏览器:http://xx.xx.xx.xx:28017/没有回复 .
浏览器:http://www.hostname.com:27017/无响应 .
浏览器:http://www.hostname.com:28017/没有回复 .
mongo.exe xx.xx.xx.xx:27017(远程) couldn't connect to server xx.xx.xx.xx
mongo xx.xx.xx.xx:27017(来自localhost)正确连接
mongo www.hostname.com:27017(来自localhost)正确连接
即使我指定了IP地址,它在托管mongodb的服务器上通过localhost正确连接的事实让我觉得它必须是防火墙问题 . 有任何想法吗?
1 回答
iptables
规则完全按照它们出现的顺序读取 . 您现在DROP
优先于您的mongodb端口的ACCEPT
.在您的特定脚本中随机设置iptables并刷新并重新读取它们 .
如果您尚未保存防火墙,请删除
DROP
规则并重新添加它,它会将其移至列表中并解决您的问题 .