2014-01-08 33 views
0

我有2个服务器,一个nginx/PHP和一个mongoDB服务器。我已经正确配置了mongoDB服务器的iptables,并且可以在防火墙关闭时使用nginx服务器连接到它。但是,当我打开防火墙时。它停止工作。应用服务器上应该打开什么来连接到MongoDB?MongoDB应用服务器IPTables

我在我的mongo数据库服务器上使用了默认端口。这是我的Web服务器上的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 

回答

1

除非你有一个分片集群或已经改变了default ports used by MongoDB,你需要有从应用程序服务器只开放端口27017的MongoDB的服务器上。

通过MongoDB中使用的默认端口是:

  • 27017(独立的mongod)
  • 27018(mongod的--shardsvr)
  • 27019(mongod的--configsvr)
  • 28017(网络状态页面..您不应该在生产中启用此功能)

MongoDB文档包含的示例。

您可能还需要检查bind_ip值(如果设置)以确保mongod正在侦听应用程序服务器试图连接的网络接口。默认情况下,mongod侦听所有接口,但在初始安装时,某些发行版可能会将其限制为localhost。

+0

查看上面的我的iptables – user1978109