Add an Arbiter to Replica Set将仲裁器添加到副本集中
On this page本页内容
In some circumstances (such as you have a primary and a secondary but cost constraints prohibit adding another secondary), you may choose to add a 在某些情况下(例如,您有一个主实例和一个辅助实例,但成本限制禁止添加另一个辅助),您可以选择将mongod
instance to a replica set as an arbiter to vote in elections.mongod
实例添加到副本集中,作为在选举中投票的仲裁器。
Arbiters are Arbiter是mongod
instances that are part of a replica set but do not hold data (i.e. do not provide data redundancy). mongod
实例,它们是副本集的一部分,但不包含数据(即不提供数据冗余)。They can, however, participate in elections.然而,他们可以参加选举。
Arbiters have minimal resource requirements and do not require dedicated hardware. You can deploy an arbiter on an application server or a monitoring host.仲裁器具有最低的资源需求,并且不需要专用硬件。您可以在应用程序服务器或监控主机上部署仲裁器。
Do not run an arbiter on systems that also host the primary or the secondary members of the replica set.不要在同时承载复制集的主成员或辅助成员的系统上运行仲裁器。
Avoid deploying more than one arbiter in a replica set. See Concerns with Multiple Arbiters.避免在副本集中部署多个仲裁器。请参阅与多个仲裁员有关的问题。
To add an arbiter to an existing replica set:要将仲裁器添加到现有副本集,请执行以下操作:
Typically, if there are two or fewer data-bearing members in the replica set, you might need to first set the cluster wide write concern for the replica set.通常,如果副本集中有两个或更少的数据承载成员,则可能需要首先为副本集设置集群范围的写入关注。See cluster wide write concern for more information on why you might need to set the cluster wide write concern.有关为什么可能需要设置集群范围的写入关注的更多信息,请参阅集群范围的写入关注。
You do not need to change the cluster wide write concern before starting a new replica set with an arbiter.在使用仲裁器启动新的副本集之前,不需要更改集群范围内的写入关注。
See also: 另请参阅:
Considerations注意事项
Arbiters are not supported with quarterly rapid releases. 仲裁器不支持季度快速发布。If your deployment includes arbiters, only use LTS releases.如果您的部署包括仲裁器,请仅使用LTS版本。
Primary-Secondary-Arbiter Replica SetsPrimary-Secondary-Arbiter副本集
If you are using a three-member primary-secondary-arbiter (PSA) architecture, consider the following:如果您使用的是由三个成员组成的主辅仲裁器(PSA)架构,请考虑以下事项:
The write concern如果辅助设备不可用或滞后,写入关注"majority"
can cause performance issues if a secondary is unavailable or lagging."majority"
可能会导致性能问题。For advice on how to mitigate these issues, see Mitigate Performance Issues with PSA Replica Set.有关如何缓解这些问题的建议,请参阅使用PSA副本集缓解性能问题。If you are using a global default如果使用全局默认的"majority"
and the write concern is less than the size of the majority, your queries may return stale (not fully replicated) data."majority"
,并且写入关注小于多数的大小,则查询可能会返回过时(未完全复制)的数据。
Replica Set Protocol Version副本集协议版本
Arbiter仲裁器
An arbiter does not store data, but until the arbiter's 仲裁器不存储数据,但在将仲裁器的mongod
process is added to the replica set, the arbiter will act like any other mongod
process and start up with a set of data files and with a full-sized journal.mongod
进程添加到副本集之前,仲裁器将像任何其他mongod
过程一样,从一组数据文件和一个完整大小的日志开始。
IP BindingIP绑定
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. 在将实例绑定到可公开访问的IP地址之前,必须保护群集不受未经授权的访问。For a complete list of security recommendations, see Security Checklist. 有关安全建议的完整列表,请参阅安全检查表。At minimum, consider enabling authentication and hardening network infrastructure.至少,考虑启用身份验证和强化网络基础设施。
MongoDB binaries, MongoDB二进制文件mongod
and mongos
, bind to localhost by default. If the net.ipv6
configuration file setting or the --ipv6
command line option is set for the binary, the binary additionally binds to the localhost IPv6 address.mongod
和mongos
默认绑定到localhost。如果为二进制文件设置了net.ipv6
配置文件设置或--ipv6
命令行选项,则二进制文件将额外绑定到localhost ipv6地址。
By default 默认情况下,绑定到localhost的mongod
and mongos
that are bound to localhost only accept connections from clients that are running on the same computer. mongod
和mongos
只接受来自在同一台计算机上运行的客户端的连接。This binding behavior includes 这种绑定行为包括mongosh
and other members of your replica set or sharded cluster. Remote clients cannot connect to binaries that are bound only to localhost.mongosh
和复制集或分片集群的其他成员。远程客户端无法连接到仅绑定到localhost的二进制文件。
To override the default binding and bind to other IP addresses, use the 要覆盖默认绑定并绑定到其他IP地址,请使用net.bindIp
configuration file setting or the --bind_ip
command-line option to specify a list of hostnames or IP addresses.net.bindIp
配置文件设置或--bind_ip
命令行选项指定主机名或IP地址列表。
Starting in MongDB 5.0, split horizon DNS从MongDB 5.0开始,仅配置有IP地址的拆分域DNS nodes that are only configured with an IP address fail startup validation and report an error.
节点无法通过启动验证并报告错误。
See 请参阅disableSplitHorizonIPCheck
.disableSplitHorizonIPCheck
。
For example, the following 例如,以下mongod
instance binds to both the localhost and the hostname My-Example-Associated-Hostname
, which is associated with the IP address 198.51.100.1
:mongod
实例绑定到localhost和主机名My-Example-Associated-Hostname
,后者与IP地址198.51.100.1
关联:
mongod --bind_ip localhost,My-Example-Associated-Hostname
In order to connect to this instance, remote clients must specify the hostname or its associated IP address 为了连接到此实例,远程客户端必须指定主机名或其关联的IP地址198.51.100.1
:198.51.100.1
:
mongosh --host My-Example-Associated-Hostname
mongosh --host 198.51.100.1
To avoid configuration updates due to IP address changes, use DNS hostnames instead of IP addresses. 若要避免由于IP地址更改而导致配置更新,请使用DNS主机名而不是IP地址。It is particularly important to use a DNS hostname instead of an IP address when configuring replica set members or sharded cluster members.在配置复制集成员或分片集群成员时,使用DNS主机名而不是IP地址尤为重要。
Use hostnames instead of IP addresses to configure clusters across a split network horizon. Starting in MongoDB 5.0, nodes that are only configured with an IP address will fail startup validation and will not start.使用主机名而不是IP地址来跨拆分的网络范围配置群集。从MongoDB 5.0开始,只配置了IP地址的节点将无法通过启动验证,也不会启动。
Add an Arbiter添加仲裁器
Avoid deploying more than one arbiter in a replica set. See Concerns with Multiple Arbiters.避免在副本集中部署多个仲裁器。请参阅与多个仲裁员有关的问题。
To add an arbiter to an existing replica set:要将仲裁器添加到现有副本集,请执行以下操作:
Typically, if there are two or fewer data-bearing members in the replica set, you might need to first set the cluster wide write concern for the replica set.通常,如果副本集中有两个或更少的数据承载成员,则可能需要首先为副本集设置集群范围的写入关注。See cluster wide write concern for more information on why you might need to set the cluster wide write concern.有关为什么可能需要设置集群范围的写入关注的更多信息,请参阅集群范围的写入关注。
You do not need to change the cluster wide write concern before starting a new replica set with an arbiter.在使用仲裁器启动新的副本集之前,不需要更改集群范围内的写入关注。
See also: 另请参阅:
To avoid configuration updates due to IP address changes, use DNS hostnames instead of IP addresses. 若要避免由于IP地址更改而导致配置更新,请使用DNS主机名而不是IP地址。It is particularly important to use a DNS hostname instead of an IP address when configuring replica set members or sharded cluster members.在配置复制集成员或分片集群成员时,使用DNS主机名而不是IP地址尤为重要。
Use hostnames instead of IP addresses to configure clusters across a split network horizon. Starting in MongoDB 5.0, nodes that are only configured with an IP address will fail startup validation and will not start.使用主机名而不是IP地址来跨拆分的网络范围配置群集。从MongoDB 5.0开始,只配置了IP地址的节点将无法通过启动验证,也不会启动。
Create a data directory (e.g.为仲裁器创建一个数据目录(例如storage.dbPath
) for the arbiter.storage.dbPath
)。Themongod
instance uses the directory for configuration data. The directory will not hold the data set.mongod
实例使用用于配置数据的目录。该目录将不包含数据集。For example, create the例如,创建/var/lib/mongodb/arb
directory:/var/lib/mongodb/arb
目录:mkdir /var/lib/mongodb/arb
Start the arbiter, specifying the data directory and the name of the replica set to join.启动仲裁器,指定数据目录和要加入的副本集的名称。The following starts an arbiter using the以下命令启动一个仲裁器,使用/var/lib/mongodb/arb
as thedbPath
andrs
for the replica set name:/var/lib/mongodb/arb
作为dbPath
和rs
作为副本集名称:WarningBefore you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access.在将实例绑定到可公开访问的IP地址之前,必须保护群集不受未经授权的访问。For a complete list of security recommendations, see Security Checklist.有关安全建议的完整列表,请参阅安全检查表。At minimum, consider enabling authentication and hardening network infrastructure.至少,考虑启用身份验证和强化网络基础设施。mongod --port 27017 --dbpath /var/lib/mongodb/arb --replSet rs --bind_ip localhost,<hostname(s)|ip address(es)>
Connect to the primary and add the arbiter to the replica set.连接到主服务器并将仲裁器添加到副本集中。Use the使用rs.addArb()
method, as in the following example which assumes thatm1.example.net
is the hostname associated with the specified ip address for the arbiter:rs.addArb()
方法,如下例所示,该方法假定m1.example.net
是与仲裁器的指定ip地址相关联的主机名:rs.addArb("m1.example.net:27017")
This operation adds the arbiter running on port此操作添加在27017
on them1.example.net
host.m1.example.net
主机上的端口27017
上运行的仲裁器。