gpt4 book ai didi

mongodb - "This node was not started with the replSet option"

转载 作者:可可西里 更新时间:2023-11-01 09:57:00 33 4
gpt4 key购买 nike

我正在研究 MongoDBUniversityM101P:面向开发人员的 MongoDB 类(class)。

我在 MongoDB 3.2 上使用 WiredTiger

我目前的主题是副本集

类(class)要求我使用以下代码创建一个副本集:

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

但我使用的是 Windows,它不支持 fork,所以使用 this要点(根据类(class)管理员的建议)我在创建目录后(运行 mongod)在 3 个不同的控制台中同时运行这些行:

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

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

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

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

rs.initiate(config)
rs.status()

哪个是 throw :

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

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

我看过关于这个主题的其他问题,但很少,而且没有一个是我能找到地址并为我解决这个问题的。 This一个陈述从错误中看起来很明显:我的配置文件应该包括 --replSet=rs1,但是从阅读 documentation给我的印象是我定义的配置的 _id 用于此目的:

_id
Type: string

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

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

此外,在类(class) Material 视频演示中清楚地显示了它以我尝试使用它的方式正确运行。

我已无计可施,非常感谢您的帮助。
jack

最佳答案

所以当我写完这个问题时,答案就像一个灯泡一样出现在我的脑海中,这似乎经常发生......但是这次我想我会把答案留给那些为此苦苦挣扎的人,考虑到论坛上缺少关于此主题的问题/答案。

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

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

mongo --port 27020 < init_replica.js 

我很遗憾,但我希望这能帮助那些也在学习这门类(class)但发现自己陷入类似困境的人。

jack

关于mongodb - "This node was not started with the replSet option",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40711829/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com