mongodb失败:连接到数据库服务器时出错:没有可访问的服务器 [英] mongodb Failed: error connecting to db server: no reachable servers

查看:170
本文介绍了mongodb失败:连接到数据库服务器时出错:没有可访问的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I installed mongodb in Ubuntu14.04 server

我无法通过"mongoimport","mongodump","mongostat"等连接到mongodb.它始终显示没有可访问的服务器"

I was not able to connect to mongodb via "mongoimport", "mongodump", "mongostat", etc. It always show "no reachable server"

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

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

Somehow, I was able to connect with mongo shell

mongo --port 27017
MongoDB shell version: 3.0.6
connecting to: 127.0.0.1:27017/test

起初,我怀疑它是否是由iptables引起的,因此我刷新了所有iptables规则并创建了ALL接受的规则,但仍然相同

At first, I doubt if it cause by my iptables, so I flush all iptables rules and create rules for ALL accept, but it still same

 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

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

I search the stackOverflow and google and someone told marked off bind_ip or set bind_ip to 0.0.0.0, I tried all but still failed.

下面是我的mangodb配置,有人可以帮我检查一下吗? 谢谢您的帮助

Below are my mangodb config, would any one can help me to check? Thanks for your help

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

推荐答案

一个临时的解决方法是将host参数添加到您的mongoimport调用中,让mongo知道主机是您自己的计算机(127.0.0.1) :

A temporary workaround is to add the host param to your mongoimport call, letting mongo know that the host is your own machine (127.0.0.1):

mongoimport --host=127.0.0.1

您所需要的完整命令如下:

The full command in your case is then:

mongoimport --host=127.0.0.1 \
  --db test --collection restaurants --drop --file dataset.json

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

更新:

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

Updating to Mongo >= 3.0.7 should solve the issue

(来源:科林·马歇尔(Colin Marshall)@ mongorestore失败:没有可访问的服务器)

更新2:

似乎错误 此处还有一个未解决的JIRA问题.

There's also an open JIRA issue here.

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

更新3:

在某些情况下,这可能是由于Mongo作为ReplicaSet运行所致.为了解决此问题,据我所知,可以禁用ReplicaSet功能或将其重置.参见:

In some cases, this can be caused by Mongo running as a ReplicaSet. To solve this, as far as I've seen, one can either disable the ReplicaSet functionality or reset it. See:

  • How to reset MongoDB replica set settings
  • How to convert a MongoDB replica set to a stand alone server

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

这篇关于mongodb失败:连接到数据库服务器时出错:没有可访问的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆