恢复到副本集时挂起mongorestore

时间:2018-06-29 17:41:41

标签: mongodb

使用以下.mongorc.js:

rs.slaveOk();

function startRS() {
    config = {_id: 'rs', members: [{_id: 0, host: 'localhost:27017', priority: 1}, {_id: 1, host: 'localhost:27016', priority: 0}]};
    rs.initiate(config);
}

以及以下启动脚本:

#!/bin/bash

mkdir /data/db/rs{0,1} >/dev/null 2>&1

/opt/mongo-db/bin/mongod --replSet rs --port 27016 --dbpath /data/db/rs1 &

/opt/mongo-db/bin/mongod --replSet rs --port 27017 --dbpath /data/db/rs0 &

/opt/mongo-db/bin/mongo --eval "startRS()"

Mongo一切正常启动。但是当我尝试将mongorestore运行为

$ /opt/mongo-db/bin/mongorestore  --drop dump/

它在连续书写时挂起

2018-06-29T19:35:47.661+0200    [########################]    ardoq-common.model.versions   753KB/753KB  (100.0%)
2018-06-29T19:35:47.661+0200    [#####...................]  iansneworg.component.versions  456KB/1.99MB   (22.4%)
2018-06-29T19:35:47.661+0200    [........................]        home.component.versions  447KB/12.9MB    (3.4%)
2018-06-29T19:35:47.661+0200    [#.......................]   piedpiper.component.versions  593KB/12.4MB    (4.7%)
2018-06-29T19:35:47.661+0200
2018-06-29T19:35:50.662+0200    [########################]    ardoq-common.model.versions   753KB/753KB  (100.0%)
2018-06-29T19:35:50.662+0200    [#####...................]  iansneworg.component.versions  456KB/1.99MB   (22.4%)
2018-06-29T19:35:50.662+0200    [........................]        home.component.versions  447KB/12.9MB    (3.4%)
2018-06-29T19:35:50.662+0200    [#.......................]   piedpiper.component.versions  593KB/12.4MB    (4.7%)
2018-06-29T19:35:50.662+0200
2018-06-29T19:35:53.664+0200    [########################]    ardoq-common.model.versions   753KB/753KB  (100.0%)
2018-06-29T19:35:53.664+0200    [#####...................]  iansneworg.component.versions  456KB/1.99MB   (22.4%)
2018-06-29T19:35:53.664+0200    [........................]        home.component.versions  447KB/12.9MB    (3.4%)
2018-06-29T19:35:53.664+0200    [#.......................]   piedpiper.component.versions  593KB/12.4MB    (4.7%)
2018-06-29T19:35:53.664+0200

当mongodb日志

2018-06-29T19:37:57.368+0200 I NETWORK  [listener] connection accepted from 127.0.0.1:62632 #60 (11 connections now open)
2018-06-29T19:37:57.372+0200 I NETWORK  [listener] connection accepted from 127.0.0.1:62634 #10 (4 connections now open)
2018-06-29T19:37:57.377+0200 I COMMAND  [conn60] CMD: drop home.component.versions
2018-06-29T19:37:57.377+0200 I STORAGE  [conn60] dropCollection: home.component.versions (623af0a3-ee8d-4b8a-9e28-349bd1094b32) - renaming to drop-pending collection: home.system.drop.1530293877i1t5.component.versions with drop optime { ts: Timestamp(1530293877, 1), t: 5 }
2018-06-29T19:37:57.379+0200 I NETWORK  [listener] connection accepted from 127.0.0.1:62636 #61 (12 connections now open)
2018-06-29T19:37:57.379+0200 I STORAGE  [conn60] createCollection: home.component.versions with generated UUID: f5cb88f9-df22-4990-9ef8-cdd689892b50
2018-06-29T19:37:57.380+0200 I COMMAND  [repl writer worker 9] CMD: drop home.component.versions
2018-06-29T19:37:57.380+0200 I STORAGE  [repl writer worker 9] dropCollection: home.component.versions (623af0a3-ee8d-4b8a-9e28-349bd1094b32) - renaming to drop-pending collection: home.system.drop.1530293877i1t5.component.versions with drop optime { ts: Timestamp(1530293877, 1), t: 5 }
2018-06-29T19:37:57.382+0200 I NETWORK  [listener] connection accepted from 127.0.0.1:62638 #62 (13 connections now open)
2018-06-29T19:37:57.383+0200 I COMMAND  [conn61] CMD: drop piedpiper.component.versions
2018-06-29T19:37:57.383+0200 I STORAGE  [conn61] dropCollection: piedpiper.component.versions (1eaf6561-eea5-414d-80d2-b914f5110559) - renaming to drop-pending collection: piedpiper.system.drop.1530293877i3t5.component.versions with drop optime { ts: Timestamp(1530293877, 3), t: 5 }
2018-06-29T19:37:57.384+0200 I STORAGE  [repl writer worker 0] createCollection: home.component.versions with provided UUID: f5cb88f9-df22-4990-9ef8-cdd689892b50

这是在MacOS High Sierra上,带有mongodb-osx-x86_64-enterprise-3.6.5

我在MacOS High Sierra上,但也可能在mongodb-3.6.4上,在另一台Mac上运行了这种精确的设置(由于它正在运行,可能不太精确)。

有什么提示吗?

1 个答案:

答案 0 :(得分:0)

您的mongorestore命令行在默认端口上连接到localhost上的独立mongod,您发布的日志片段指示将无法进行写操作的辅助节点。

为了使monorestore自动切换到可写节点,您将需要在命令行中指定副本集

connection options:
-h, --host=<hostname>                                     mongodb host to connect to (setname/host1,host2 for replica sets)
--port=<port>                                         server port (can also use --host hostname:port)

喜欢

/opt/mongo-db/bin/mongorestore --host=rs/localhost:27017,localhost:27016 --drop dump/