mongodb失败:连接到数据库服务器时出错:没有可访问的服务器

Jam*_*ien 53 mongodb

我在Ubuntu14.04服务器上安装了mongodb

我无法连接通过"mongoimport","mongodump","mongostat"等方面的MongoDB它总是显示"无可达服务器"

mongoimport --db test --collection restaurants --drop --file dataset.json
2015-08-25T13:08:29.802+0800    [........................] test.restaurants 0.0 B/11.3 MB (0.0%)
2015-08-25T13:08:30.306+0800    Failed: error connecting to db server: no reachable servers
2015-08-25T13:08:30.306+0800    imported 0 documents
Run Code Online (Sandbox Code Playgroud)

不知何故,我能够连接mongo shell

mongo --port 27017
MongoDB shell version: 3.0.6
connecting to: 127.0.0.1:27017/test
Run Code Online (Sandbox Code Playgroud)

起初,我怀疑它是否由我的iptables引起,所以我清除所有iptables规则并为ALL接受创建规则,但它仍然相同

 sudo iptables -S
    -P INPUT ACCEPT
    -P FORWARD ACCEPT
    -P OUTPUT ACCEPT
    -A INPUT -j ACCEPT
    -A INPUT -i lo -j ACCEPT
    -A FORWARD -j ACCEPT
    -A OUTPUT -j ACCEPT
    -A OUTPUT -o lo -j ACCEPT
Run Code Online (Sandbox Code Playgroud)

我搜索stackOverflow和google,有人告诉标记为bind_ip或将bind_ip设置为0.0.0.0,我尝试了所有但仍然失败.

下面是我的mangodb配置,任何人都可以帮我查一下吗?谢谢你的帮助

james@localhost:~$ cat /etc/mongod.conf 
# mongod.conf

# Where to store the data.

# Note: if you run mongodb as a non-root user (recommended) you may
# need to create and set permissions for this directory manually,
# e.g., if the parent directory isn't mutable by the mongodb user.
dbpath=/var/lib/mongodb

#where to log
logpath=/var/log/mongodb/mongod.log

logappend=true

port = 27017

# Listen to local interface only. Comment out to listen on all interfaces. 
#bind_ip = 127.0.0.1
# Disables write-ahead journaling
# nojournal = true

# Enables periodic logging of CPU utilization and I/O wait
#cpu = true

# Turn on/off security.  Off is currently the default
#noauth = true
#auth = true

# Verbose logging output.
verbose = true

# Inspect all client data for validity on receipt (useful for
# developing drivers)
#objcheck = true

# Enable db quota management
#quota = true

# Set oplogging level where n is
#   0=off (default)
#   1=W
#   2=R
#   3=both
#   7=W+some reads
#diaglog = 0

# Ignore query hints
#nohints = true

# Enable the HTTP interface (Defaults to port 28017).
#httpinterface = true

# Turns off server-side scripting.  This will result in greatly limited
# functionality
#noscripting = true

# Turns off table scans.  Any query that would do a table scan fails.
#notablescan = true

# Disable data file preallocation.
#noprealloc = true

# Specify .ns file size for new databases.
# nssize = <size>

# Replication Options

# in replicated mongo databases, specify the replica set name here
#replSet=setname
# maximum size in megabytes for replication operation log
#oplogSize=1024
# path to a key file storing authentication info for connections
# between replica set members
#keyFile=/path/to/keyfile
Run Code Online (Sandbox Code Playgroud)

why*_*ode 84

一个临时的解决方法是将hostparam 添加到你的mongoimport调用中,让mongo知道主机是你自己的机器(127.0.0.1):

mongoimport --host=127.0.0.1
Run Code Online (Sandbox Code Playgroud)

您的案例中的完整命令是:

mongoimport --host=127.0.0.1 \
  --db test --collection restaurants --drop --file dataset.json
Run Code Online (Sandbox Code Playgroud)

(来源:ranjeetcao @ mongorestore失败:没有可达的服务器)


更新:

更新到Mongo> = 3.0.7应该可以解决问题

(来源:Colin Marshall @ mongorestore失败:没有可达的服务器)


更新2:

对于一些用户来说,似乎仍然在发生 Bug .

还有一个开放JIRA问题在这里.

(来源:James Chien @这个问题主题)


更新3:

在某些情况下,这可能是由Mongo作为ReplicaSet运行引起的.为了解决这个问题,据我所见,可以禁用ReplicaSet功能或重置它.看到:

(来源:Maxim Yefremov @ mongorestore失败:没有可达的服务器)

  • 谢谢,它的确有效!无论出于何种原因,3.2.4版本中仍然会发生这种情况...... (2认同)