mongodb 副本集中仅辅助节点
我正在开发一个项目,我希望能够指定副本集的某些节点永远不能成为主节点,即,如果发生故障,所有有主能力的节点都死亡,系统应降低为只读状态直到某个有能力的主要节点出现。这可能吗?如果是的话怎么办?如果不是,最好的解决方法是什么。
I am working on a project where I want to have the ability to specify that certain nodes of the replica set can never be primary nodes ie in case of a failure where all primary capable nodes die the system should be reduced to a read-only state till some primary capable node comes up. Is this possible? If yes how? If not what is the best way around it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是来自文档(强调我的):
所以将优先级设置为零应该可以达到你想要的效果。
This is from the documentation (emphasis mine):
So setting the priority to zero should achieve what you want.
据我所知,mongodb 还没有完全支持您的需求。如果在没有主节点的情况下重新启动只读从节点,它将进入 STARTUP2 状态,而不是 SECONDARY。在 STARTUP2 中尝试查询 mongod 实例将会失败。
因此,如果您的设置不稳健,例如您的主集群和只读服务器集群位于同一城市,并且发生断电,那么您最终会导致主 DC 关闭(有人忘记检查发电机和 UPS)并且只读服务器恢复正常(其他 DC 中的发电机工作正常),那么您将处于从属服务器无法工作的情况。
From what I can tell, mongodb does not completely support what you require yet. If you restart a read-only slave while there is no primary, it will enter STARTUP2 state, not SECONDARY. Trying to query a mongod instance while in STARTUP2 will fail.
So if you had a unrobust setup, e.g. your cluster of masters and cluster of read only servers in the same city and there was a power cut, and you end up with the primary DC down (someone forgot to check the generators & UPS) and the read only servers came back up fine (generator in other DC works fine) then you will be in a situation where the slaves will not work.