mongodb Failed: error connecting to db server: no reachable servers

I installed mongodb in Ubuntu14.04 server

在Ubuntu14.04上安装MongoDB

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

不能通过 "mongoimport", "mongodump", "mongostat"等命令连接到MongoDB,一直报错:

"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

Somehow, I was able to connect with mongo shell

但是,我可以连接到mongo shell

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

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

开始时,我怀疑是我的iptables出错,所以我刷新iptables规则,为ALL accept创建规则,但还是出错。

 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

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.

我搜索了stackOerflow和Google,有人说把bind_ip设为0.0.0.0,但还是失败了。

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

A temporary workaround (worked for me) is to add the "host" param:

mongoimport --host=127.0.0.1

(Source: ranjeetcao @ mongorestore Failed: no reachable servers)

Update:

Updating to Mongo >= 3.0.7 should solve the issue

(Source: Colin Marshall @ mongorestore Failed: no reachable servers)

更新MongoDB到3.0.7版本以上,成功解决问题。

原文来自:http://stackoverflow.com/questions/32195997/mongodb-failed-error-connecting-to-db-server-no-reachable-servers


I tried to restore mongo from dump but failed:

mongorestore --port 27133 dump
2015-05-07T09:39:11.760+0300    Failed: no reachable servers

Although I can connect to it without any problem:

$ mongo --port 27133
MongoDB shell version: 3.0.1
connecting to: 127.0.0.1:27133/test

In a log file there is nothing special:

2015-05-07T09:37:00.350+0300 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:44901 #1 (1 connection now open)
2015-05-07T09:37:13.935+0300 I NETWORK  [conn1] end connection 127.0.0.1:44901 (0 connections now open)
2015-05-07T09:39:08.752+0300 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:44906 #2 (1 connection now open)
2015-05-07T09:39:11.763+0300 I NETWORK  [conn2] end connection 127.0.0.1:44906 (0 connections now open)
2015-05-07T09:39:52.365+0300 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:44907 #3 (1 connection now open)
2015-05-07T09:39:55.064+0300 I NETWORK  [conn3] end connection 127.0.0.1:44907 (0 connections now open)
2015-05-07T09:40:11.272+0300 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:44909 #4 (1 connection now open)
2015-05-07T09:40:14.281+0300 I NETWORK  [conn4] end connection 127.0.0.1:44909 (0 connections now open)

Update

Host 127.0.0.1 didn't help

$ mongorestore --host=127.0.0.1 --port=27132 dump
2015-12-16T18:52:33.270+0300    Failed: no reachable servers

Although I can still connect using mongo command:

$ mongo --host=127.0.0.1 --port=27133
MongoDB shell version: 3.2.0
connecting to: 127.0.0.1:27133/test
> ^C
bye

Host 0.0.0.0 didn't help as well:

$ mongorestore --host=0.0.0.0 --port=27133 dump

I have 3.2 version of MongoDb:

$ mongorestore --version
mongorestore version: 3.2.0-rc5
git version: 6186100ad0500c122a56f0a0e28ce1227ca4fc88

try adding host param

mongorestore --host=127.0.0.1 --port=27133 dump
anwser2:

I have MongoDB installed through Homebrew, and was having this issue. Here are the symptoms:

These failed:

mongorestore dump

mongorestore dump --host=localhost

The error I got: Failed: error connecting to db server: no reachable servers

These worked (as a workaround):

mongorestore dump --host=127.0.0.1

mongorestore dump --host=0.0.0.0

This fixed the problem for me:

brew update && brew upgrade

That updated MongoDB to 3.0.7 and now mongorestore dump works without the host flag.

share improve this answer

原文来自:http://stackoverflow.com/questions/30093744/mongorestore-failed-no-reachable-servers/33139963#33139963




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值