我有2台服务器,一台nginx / PHP和一台mongoDB服务器。我已经正确配置了mongoDB服务器的iptables,当防火墙关闭时,我可以使用nginx服务器连接到它。但是,当我打开防火墙时。它停止工作。在应用程序服务器上应该打开什么才能连接到MongoDB?
我正在使用mongo数据库服务器上的默认端口。这是我的网络服务器上iptables的输出。
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- { MongDB IP } anywhere tcp dpt:27017
ACCEPT tcp -- anywhere anywhere tcp dpt:http state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:https state NEW,ESTABLISHED
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- anywhere { MongDB IP } tcp spt:27017
ACCEPT tcp -- anywhere anywhere tcp spt:http state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:https state ESTABLISHED
答案 0 :(得分:1)
除非您有分片群集或更改了default ports used by MongoDB,否则您的应用程序服务器上需要打开的唯一端口是MongoDB服务器上的27017。
MongoDB使用的默认端口是:
MongoDB文档包含Configuring Linux iptables
Firewall for MongoDB的示例。
您可能还需要检查bind_ip
值(如果已设置)以确保mongod
正在侦听应用程序服务器尝试连接的网络接口。默认情况下,mongod
会侦听所有接口,但某些发行版可能会在初始安装时将此限制为localhost。