“此节点未使用 replSet 选项启动" [英] "This node was not started with the replSet option"

查看:868
本文介绍了“此节点未使用 replSet 选项启动"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 MongoDBUniversityM101P:MongoDB for Developers 课程.

I am studying the MongoDBUniversity's M101P: MongoDB for Developers course.

我在 MongoDB 3.2 上使用 WiredTiger.

我目前讨论的是副本集.

课程要求我使用以下代码创建副本集:

The course requires I create a replica set using the following code:

mongod --replSet rs1 --logpath "1.log" --dbpath /data/rs1 --port 27017 --fork

但我使用的是不支持 fork 的 Windows,所以使用 this gist(由课程管理员推荐)在创建目录(运行 mongod)后,我在 3 个不同的控制台中同时运行这些行:

But I am using Windows, which doesn't support fork, so using this gist (as recommended by a course admin) I ran these lines simultaneously in 3 different consoles after I had created the directories (with mongod running):

mongod --replSet rs1 --logpath "1.log" --dbpath rs1 --port 27018 --smallfiles --oplogSize64  
mongod --replSet rs1 --logpath "2.log" --dbpath rs2 --port 27019 --smallfiles --oplogSize64  
mongod --replSet rs1 --logpath "3.log" --dbpath rs3 --port 27020 --smallfiles --oplogSize64

似乎一切正常;我可以看到目录已经填满,日志文件都显示等待连接"和相关端口号.

Which all seems to work fine; I can see the directories have been filled, and the log files, which all show "waiting for connection" with the relevant port number.

最后,我运行以下代码将服务器统一为副本集:

Finally, I am running the following code to unify the servers as a replica set:

config = {_id: "rs1", members: [
           { _id: 0, host: "localhost:27018"},
           { _id: 1, host: "localhost:27019"},
           { _id: 2, host: "localhost:27020"}
                                ]
         }

rs.initiate(config)
rs.status()

什么是投掷:

"errmsg" : "This node was not started with the replSet option",
"code" : 76

我无法理解,因为我已经清楚地为每个服务器使用了 --replSet 选项,并且确实提供了在配置文件中使用的相同 replSet 名称.

Which I can't get my head around, as I have clearly used the --replSet option for each server, and indeed provided the same replSet name used in the config file.

我已经查看了有关此主题的其他问题,但我可以找到解决此问题并为我解决此问题的问题很少,而且没有一个.这个说明了从错误中可以看出什么:我的配置文件应该包含 --replSet=rs1,但通过阅读 文档 我的印象是我定义的配置的 _id 用于此目的:

I've looked at other questions on this topic, but there are few, and none that I can find address and solve this issue for me. This one states what looks obvious from the error: my config file should include --replSet=rs1, but from reading the documentation I am given the impression that the _id of the config I have defined serves that purpose:

_id
类型:字符串

副本集的名称.一旦设置,您将无法更改名称副本集.

The name of the replica set. Once set, you cannot change the name of a replica set.

_id 必须与replication.replSetName或命令行中指定给mongod的-replSet的值相同.

_id must be identical to the replication.replSetName or the value of –replSet specified to mongod on the command line.

此外,这在课程材料视频演示中清楚地显示为我尝试使用它的方式正确运行.

Furthermore, this is clearly shown functioning correctly in the course material video demonstrations in precisely the manner I am attempting to use it.

我无能为力,非常感谢您的帮助.
杰克

I am at my wit's end, and would very much appreciate help.
Jake

推荐答案

所以当我写完这个问题时,答案就像一个灯泡一样来到我身边,这似乎经常发生......但这次我想我会考虑到论坛上关于此主题的问题/答案有些缺乏,请将答案留给其他遇到此问题的人.

So as I finished writing this question, the answer just came to me like a lightbulb, which seems to happen often... but this time I thought I would leave the answer here for anyone else who has struggled with this, considering the somewhat lack of questions/answers on this topic on the forum.

这是运行我的配置文件时使用的默认端口的简单情况.
我正在使用 mongo <init_replica.js 运行我的配置并统一服务器以创建副本集.

It was a simple case of the default port being used when running my config file.
I was using mongo < init_replica.js to run my config and unify the servers to create the replica set.

只需添加一个有效服务器使用的端口,它就可以正确运行:

By simply adding a port used by one of the valid servers, it ran correctly:

mongo --port 27020 < init_replica.js 

不幸的是我,但我希望这能帮助那些也在学习这门课程但发现自己陷入类似困境的人.

Woe is me for that one, but I hope this helps those also studying the course who find themselves stuck somewhere similar.

杰克

这篇关于“此节点未使用 replSet 选项启动"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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