如何在不调用rs.initiate()的情况下初始化mongodb复制集? [英] How to initialize mongodb replication set without calling rs.initiate()?

查看:438
本文介绍了如何在不调用rs.initiate()的情况下初始化mongodb复制集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用replSet = 1初始化mongod,如下所示: $ mongod --dbpath/x/y --replSet 1

但是我一直收到诸如您需要通过调用rs.initiate()初始化复制集"之类的错误,然后我启动mongo shell发出rs.initiate()并解决了问题.

但是我的问题是,为什么需要一个单独的mongo shell?有没有办法使用mongod选项来做到这一点?

解决方案

简短回答/tl; dr

否.

答案略长

否,因为使用外壳很有意义.

答案

设置副本集时,通常有多个成员.在初始化副本集之前,没有一个成员拥有必要的配置.初始化副本集的节点将成为主节点,并存储配置.现在,您可以使用rs.add命令或使用rs.reconfig添加成员.然后发生的事情是主要联系人联系了添加的成员,配置已同步等.最佳实践是,普通副本集成员应相等,以使一个节点发生故障,而没有另一个节点成为主节点的缺点,因此新的主节点可以保持主节点状态,直到由于某种原因或其他原因而关闭为止. >

因此,如果您要启动副本集成员,应该从哪里获取它的配置?自己决定必须做什么?这在群集中不能很好地工作.它应该如何发现其他成员及其配置?请记住,副本集成员可以位于不同的数据中心.如果有--IamPrimaryDoAsISay选项,那么如果集群中当前有另一个主节点,将会发生什么情况?那么,如何处理一个以上成员开始使用该选项的情况呢?退出其他服务器?可能仅仅是因为您更换了散热器吗?还是刚刚启动的实例在已经存在主实例的情况下应该什么都不做?那么该选项首先具有什么意义?

所有这些复杂性只是为了防止从外壳执行单个命令?

注意:如果要使用一台服务器,只需启动一个独立实例(不带--replSet选项的mongod).如果要探索副本集的可能性,则需要多个成员.

I am trying to initiate mongod with replSet=1 as below: $mongod --dbpath /x/y --replSet 1

But I kept getting errors like "you need to initialize the replication set by calling rs.initiate()", then I start a mongo shell to issue rs.initiate() and the problem gets resolved.

But my question is why a separate mongo shell is needed? Is there a way to do it using mongod option?

解决方案

Short answer / tl;dr

No.

Slightly longer answer

No, because it makes sense to use the shell.

Answer

When you set up a replica set, you usually have more than one member. Until the replica set is initialized, none of the members holds the necessary configuration. The node you initialize the replica set on becomes primary, storing the configuration. Now you add members either using the rs.add command or by using rs.reconfig. What happens then is that the primary contacts the added member, the config is synced and some other things. It is best practise that ordinary replica set members should be equal so that of one node fails, there is no drawback that another node becomes primary and so the new primary can stay primary until it goes down for some reason or the other itself.

So if you would start a replica set member, where should it get it's config from? Decide for itself what it has to do? That wouldn't work well in a cluster. How should it discover the other members and their config? Remember, replica set members can be in different data centers. And if there was a --IamPrimaryDoAsISay option, what would happen if there was another primary currently in the cluster? And how should a situation in which more than one member was started with that option be dealt with? A step down of the other server? May be just because you replaced a cooler? Or should the just started instance do nothing when there already was a primary? What sense would the option have then in the first place?

And all these complications just to prevent a single command from the shell?

Note: If you want a single server, just start a standalone instance (a mongod without the --replSet option).if you want to explore the possibilities of a replica set, you need more than one member.

这篇关于如何在不调用rs.initiate()的情况下初始化mongodb复制集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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