mongodb mongorestore 失败:没有可访问的服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30093744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:25:20  来源:igfitidea点击:

mongorestore Failed: no reachable servers

mongodb

提问by Maxim Yefremov

I tried to restore mongo from dump but failed:

我试图从转储恢复 mongo 但失败了:

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.1didn't help

主机127.0.0.1没有帮助

$ 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 mongocommand:

虽然我仍然可以使用mongo命令连接:

$ 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.0didn't help as well:

主机0.0.0.0也没有帮助:

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

I have 3.2 version of MongoDb:

我有 3.2 版本的 MongoDb:

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

采纳答案by Maxim Yefremov

The problem occured because --replSetwas enabled in configuration. But the node wasn't yet in any replica set.

出现问题是因为--replSet在配置中启用。但是该节点还没有在任何副本集中。

After I removed --replSetfrom configuration, relaunched mongodb server, mongorestorestarted to work without any --hostparameter.

--replSet从配置中删除后,重新启动 mongodb 服务器,mongorestore开始在没有任何--host参数的情况下工作。

回答by ranjeetcao

try adding host param

尝试添加主机参数

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

回答by Shi Jieming

Do you run mongoin replica set, i.e., mongod --replSet rs0?

您是否在副本集中运行mongo,即mongod --replSet rs0

If yes, please remember to run in your mongo shell the command: rs.initiate()

如果是,请记住在您的 mongo shell 中运行以下命令: rs.initiate()

Then you can use cmd mongorestoreto restore your db.

然后你可以使用 cmdmongorestore来恢复你的数据库。

回答by Colin Marshall

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

我通过 Homebrew 安装了 MongoDB,并且遇到了这个问题。以下是症状:

These failed:

这些失败了:

mongorestore dump

mongorestore dump

mongorestore dump --host=localhost

mongorestore dump --host=localhost

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

我得到的错误: Failed: error connecting to db server: no reachable servers

These worked (as a workaround):

这些工作(作为一种解决方法):

mongorestore dump --host=127.0.0.1

mongorestore dump --host=127.0.0.1

mongorestore dump --host=0.0.0.0

mongorestore dump --host=0.0.0.0

This fixed the problem for me:

这为我解决了问题:

brew update && brew upgrade

brew update && brew upgrade

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

将 MongoDB 更新到 3.0.7,现在mongorestore dump无需主机标志即可工作。

回答by Prashanth Kumar B

check your mongod configuration file, if you have enabled replication disable it, if enabled, key based authentication disable it basically disable every other thing and restart the mongod service and then try doing mongo restore.

检查您的 mongod 配置文件,如果您启用了复制禁用它,如果启用,基于密钥的身份验证禁用它基本上禁用所有其他事情并重新启动 mongod 服务,然后尝试执行 mongo restore。

And BTW, try binding mongod ipaddress to your machine address as well, if it is a local mongod instance try binding the ip address to 0.0.0.0, in mongod.conf file under bind_ip="your ip address", do let me know it does or does not.

顺便说一句,尝试将 mongod ipaddress 绑定到您的机器地址,如果它是本地 mongod 实例,请尝试将 ip 地址绑定到 0.0.0.0,在 mongod.conf 文件中的 bind_ip="your ip address" 下,请告诉我做或不做。

回答by Liz

I had difficulty with that question also.

我也很难回答这个问题。

mongorestore --host f8cab83e7294 --port 27601 gene_backup_final/gene_backup/s2/  --verbose

2016-12-05T13:48:15.333-0700 Failed: error connecting to db server: no reachable servers

I failed to initiate the replica set. That is why there was no reachable server

我未能启动副本集。这就是为什么没有可访问的服务器

After initiating the RS, restore worked.

启动 RS 后,恢复工作。

mongo localhost:27501
rs.initiate()

回答by Phily Austria

First run mongod

第一次运行 mongod

If you get exception exception in initAndListen: 29 Data directory /data/db not found., terminating, do sudo mkdir -p /data/db

如果您遇到异常exception in initAndListen: 29 Data directory /data/db not found., terminating,请执行sudo mkdir -p /data/db

If you get expection exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating, This probably you have the permission issue. If this is your local, you can run sudo chmod 7777 /data/dbto fix the issue.

如果你得到期望exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating,这可能是你的权限问题。如果这是您本地的,您可以运行sudo chmod 7777 /data/db以解决问题。

Now, mongodshould work. Then, run mongorestore dumpwhere your dump file is.

现在,mongod应该工作。然后,mongorestore dump在您的转储文件所在的位置运行。

You should successfully restore the dump file.

您应该成功恢复转储文件。

回答by Neil Mayhew

In my case (with Mongo 3.2.9), the server was configured to listen on the IPv4 localhostaddress (127.0.0.1) but mongorestoretried only the IPv6 localhostaddress (::1).

在我的情况下(使用 Mongo 3.2.9),服务器被配置为侦听 IPv4localhost地址 ( 127.0.0.1) 但mongorestore只尝试了 IPv6localhost地址 ( ::1)。

Using -h 127.0.0.1worked. However, this shouldn't be necessary, IMHO, and is a bug in mongorestore. It should use the same connection logic as the mongocommand-line client, which was working.

使用-h 127.0.0.1工作。但是,恕我直言,这应该不是必需的,并且是mongorestore. 它应该使用与mongo正在工作的命令行客户端相同的连接逻辑。

Note:replica sets were not enabled.

注意:未启用副本集。

回答by Dere Sagar

In my case, I am defining port two times.

就我而言,我定义了两次端口。

mongorestore --noIndexRestore --host X.X.X.X:27017-d XYZ --port 27017foldername

mongorestore --noIndexRestore --host XXXX:27017-d XYZ --port 27017FOLDERNAME

Solve in my case,

解决我的情况,

mongorestore --noIndexRestore --host X.X.X.X -d XYZ --port 27017foldername

mongorestore --noIndexRestore --host XXXX -d XYZ --port 27017FOLDERNAME

回答by Dere Sagar

If you're using a hosted service (like MongoDB Atlas), make sure you've set up the IP white-list so that it isn't blocking your IP address. You can set it to 0.0.0.0/0to whitelist all IP addresses, but this is a bad idea in terms of security so it should only be used as a temporary measure.

如果您使用的是托管服务(如 MongoDB Atlas),请确保您已设置 IP 白名单,以便它不会阻止您的 IP 地址。您可以将其设置为0.0.0.0/0将所有 IP 地址列入白名单,但这在安全方面是一个坏主意,因此它只能用作临时措施。