【问题标题】:Ubuntu mongodb connection is OK on server side but can't be accessed remotely服务器端的 Ubuntu mongodb 连接正常,但无法远程访问
【发布时间】:2015-07-10 04:06:43
【问题描述】:

尝试获取 mongo 消息:

您似乎正试图在本机上通过 HTTP 访问 MongoDB 驱动程序端口。

所以我用 mongodb 设置了我的服务器,一切看起来都很好。当我从服务器执行以下操作时(即,我收到上述消息):

1. http://localhost:27017
2. http://xxx.xxx.xx.110:27017

但是当尝试从任何客户端执行此操作时 - 它不起作用(请注意,http://xxx.xxx.xx.110 可以运行 apache)。

我在 mongo.conf 上有什么:

端口 = 27017

bind_ip = 0.0.0.0

#auth = true

我的防火墙规则:

# Generated by iptables-save v1.4.21 on Thu Aug 28 16:37:08 2014
*filter
:INPUT ACCEPT [4102:2709470]
 :FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [2893:394270]
:ufw-after-forward - [0:0]
:ufw-after-input - [0:0]
:ufw-after-logging-forward - [0:0]
:ufw-after-logging-input - [0:0]
:ufw-after-logging-output - [0:0]
:ufw-after-output - [0:0]
:ufw-before-forward - [0:0]
:ufw-before-input - [0:0]
:ufw-before-logging-forward - [0:0]
:ufw-before-logging-input - [0:0]
:ufw-before-logging-output - [0:0]
:ufw-before-output - [0:0]
:ufw-reject-forward - [0:0]
 :ufw-reject-input - [0:0]
:ufw-reject-output - [0:0]
:ufw-track-forward - [0:0]
:ufw-track-input - [0:0]
:ufw-track-output - [0:0]
-A INPUT -p tcp -m state --state NEW,ESTABLISHED -m tcp --dport 27017 -j ACCEPT
-A INPUT -p tcp -m state --state NEW,ESTABLISHED -m tcp --dport 27017 -j ACCEPT
-A INPUT -j ufw-before-logging-input
-A INPUT -j ufw-before-input
-A INPUT -j ufw-after-input
-A INPUT -j ufw-after-logging-input
-A INPUT -j ufw-reject-input
-A INPUT -j ufw-track-input
-A FORWARD -j ufw-before-logging-forward
-A FORWARD -j ufw-before-forward
-A FORWARD -j ufw-after-forward
-A FORWARD -j ufw-after-logging-forward
-A FORWARD -j ufw-reject-forward
-A FORWARD -j ufw-track-forward
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -j ufw-before-logging-output
-A OUTPUT -j ufw-before-output
-A OUTPUT -j ufw-after-output
-A OUTPUT -j ufw-after-logging-output
-A OUTPUT -j ufw-reject-output
-A OUTPUT -j ufw-track-output
COMMIT
# Completed on Thu Aug 28 16:37:08 2014

我添加了一个小型 Java 程序来在服务器上进行测试 - 它可以工作 (CRUD)。当我在另一台计算机上尝试时,我得到:

Aug 29, 2014 9:58:23 AM com.mongodb.DBTCPConnector initDirectConnection
WARNING: Exception executing isMaster command on /xxx.xxx.xx.xxx:27017
java.io.IOException: couldn't connect to [/xxx.xxx.xx.xxx:27017]          bc:java.net.SocketTimeoutException: connect timed out
at com.mongodb.DBPort._open(DBPort.java:214)
at com.mongodb.DBPort.go(DBPort.java:107)

【问题讨论】:

  • 当您在端口 80 上监听 mongo 时会发生什么,然后从外部工作吗?
  • 我改成 80 - 不行。
  • 您使用什么客户端进行远程访问,您收到的具体错误信息是什么?如果端口是打开的(因为它似乎来自您通过 http 的检查),那么您应该能够从 mongo shell 进行连接以进行确认。
  • 我只使用另一台计算机(不同的网络/IP)并尝试这样做:xxx.xxx.xx.110:27017 以获取“看起来您正试图在本机驱动程序端口上通过 HTTP 访问 MongoDB 。”消息。
  • 你找出问题所在了吗?

标签: java mongodb ubuntu firewall iptables


【解决方案1】:

我通过使用 --httpinterface 启动 mongod 来让它工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-05
    • 2018-02-19
    相关资源
    最近更新 更多