mongo 副本集无法导入示例餐厅 json

mongo 副本集无法导入示例餐厅 json

我是 mongo 的新手,刚刚在我的笔记本电脑上本地设置了一个副本集。

我正在尝试从这里导入餐厅的演示数据库: https://raw.githubusercontent.com/mongodb/docs-assets/primer-dataset/dataset.json

并执行 mongoimport 命令如下:

mongoimport -v --db test --collection restaurants --drop --file dataset.json

导入结束,刚好在 45% 处停止

2015-12-29T12:42:56.847-0500    filesize: 11880944 bytes
2015-12-29T12:42:56.847-0500    using fields:
2015-12-29T12:42:56.859-0500    connected to: localhost
2015-12-29T12:42:56.859-0500    ns: test.restaurants
2015-12-29T12:42:56.860-0500    connected to node type: replset
2015-12-29T12:42:56.860-0500    using write concern: w='majority', j=false, fsync=false, wtimeout=0
2015-12-29T12:42:56.861-0500    dropping: test.restaurants
2015-12-29T12:42:56.864-0500    using write concern: w='majority', j=false, fsync=false, wtimeout=0
2015-12-29T12:42:59.859-0500    [#########...............] test.restaurants     4.5 MB/11.3 MB (39.9%)
2015-12-29T12:43:02.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:05.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:08.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:11.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:14.849-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:17.849-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:20.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:23.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:26.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:29.849-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:32.849-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:35.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:38.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:41.849-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:44.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:47.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:50.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:53.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:56.850-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:43:59.849-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:44:02.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:44:05.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:44:08.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:44:11.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)
2015-12-29T12:44:14.848-0500    [##########..............] test.restaurants     5.2 MB/11.3 MB (45.5%)

在从属服务器上创建了一个数据库测试,但如果我尝试进行查找:db.restaurants.find();

我回复说:

Error: error: { "$err" : "not master and slaveOk=false", "code" : 13435 }

这是我的来自主服务器的副本配置:

    repl1:PRIMARY> rs.config()
{
        "_id" : "repl1",
        "version" : 7,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "mongo1:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : 0,
                        "votes" : 1
                },
                {
                        "_id" : 1,
                        "host" : "mongo2:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : 0,
                        "votes" : 1
                },
                {
                        "_id" : 2,
                        "host" : "mongo3:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : 0,
                        "votes" : 1
                }
        ],
        "settings" : {
                "chainingAllowed" : true,
                "heartbeatTimeoutSecs" : 10,
                "getLastErrorModes" : {

                },
                "getLastErrorDefaults" : {
                        "w" : 1,
                        "wtimeout" : 0
                }
        }
}

看起来从属服务器没有意识到它们是副本集的一部分。

在哪里可以找到更多有关正在发生的事情的信息?

答案1

导入结束,刚好在 45% 处停止

它可能没问题,只是在构建索引。或者您可能耗尽了某些系统资源,或者可能只是速度很慢。跟踪该mongod过程的日志以获取更多信息。检查磁盘的可用空间,并检查top或使用您拥有的任何系统监控工具来查看在导入似乎停止在 45% 时正在使用哪些资源。

在从属服务器上创建了一个数据库测试,但如果我尝试进行查找:db.restaurants.find();

我回复说:

Error: error: { "$err" : "not master and slaveOk=false", "code" : 13435 }

如果不先告知驱动程序或 mongo shell 可以这样做,则无法查询辅助节点上的数据。请先运行rs.slaveOk(),然后才能运行find()查询。

答案2

防火墙阻止了从服务器与主服务器进行通信。主服务器可以与从服务器通信,但从服务器无法进行响应。

如果您遇到类似问题,请检查您的防火墙(如果您使用的是 Centos7)

答案3

要导入,您可以尝试以下代码:

mongoimport --db <database-name> --collection <collection-name> --file ~/path/file-name.json

相关内容