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 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.您可以在应用程序服务器或监控主机上部署仲裁器。

Important重要

Do not run an arbiter on systems that also host the primary or the secondary members of the replica set.不要在同时承载副本集的主要或次要成员的系统上运行仲裁器。

Warning警告

Avoid deploying more than one arbiter in a replica set. See Concerns with Multiple Arbiters.避免在副本集中部署多个仲裁器。请参阅与多个仲裁员有关的问题

To add an arbiter to an existing replica set:要将仲裁器添加到现有副本集,请执行以下操作:

You do not need to change the cluster wide write concern before starting a new replica set with an arbiter.在使用仲裁器启动新副本集之前,不需要更改集群范围的写入问题。

Considerations注意事项

Arbiters are not supported with quarterly rapid releases releases. 季度快速发布不支持仲裁If your deployment includes arbiters, only use LTS releases.如果您的部署包含仲裁器,请仅使用LTS版本。

Primary-Secondary-Arbiter Replica Sets主辅助仲裁器副本集

If you are using a three-member primary-secondary-arbiter (PSA) architecture, the write concern "majority" can cause performance issues if a secondary is unavailable or lagging. 如果您使用的是三成员主辅仲裁器(PSA)体系结构,那么如果辅仲裁器不可用或滞后,写问题"majority"可能会导致性能问题。See Mitigate Performance Issues with PSA Replica Set for advice on how to mitigate these issues.有关如何缓解这些问题的建议,请参阅使用PSA副本集缓解性能问题

Replica Set Protocol Version副本集协议版本

Note注意

For the following MongoDB versions, pv1 increases the likelihood of w:1 rollbacks compared to pv0(no longer supported in MongoDB 4.0+) for replica sets with arbiters:对于以下MongoDB版本,对于具有仲裁器的副本集,与pv0(MongoDB 4.0+不再支持)相比,pv1增加了w:1回滚的可能性:

  • MongoDB 3.4.1
  • MongoDB 3.4.0
  • MongoDB 3.2.11 or earlier

See 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绑定

Warning警告

Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured 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, mongod and mongos, bind to localhost by default. MongoDB二进制文件mongodmongos默认绑定到localhost。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.如果为二进制文件设置了net.ipv6配置文件设置或--ipv6命令行选项,则二进制文件还将绑定到localhost ipv6地址。

By default mongod and mongos that are bound to localhost only accept connections from clients that are running on the same computer. 默认情况下,绑定到localhost的mongodmongos只接受来自运行在同一台计算机上的客户端的连接。This binding behavior includes mongosh and other members of your replica set or sharded cluster. 此绑定行为包括mongosh和副本集或分片集群的其他成员。Remote clients cannot connect to binaries that are bound only to localhost.远程客户端无法连接到仅绑定到本地主机的二进制文件。

To override the default binding and bind to other IP addresses, use the net.bindIp configuration file setting or the --bind_ip command-line option to specify a list of hostnames or IP addresses.要覆盖默认绑定并绑定到其他IP地址,请使用net.bindIp配置文件设置或--bind_ip命令行选项指定主机名或IP地址列表。

Warning警告

Starting in MongDB 5.0, split horizon DNS nodes that are only configured with an IP address fail startup validation and report an error. 从MongDB 5.0开始,仅使用IP地址配置的拆分地平线DNS节点无法通过启动验证并报告错误。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实例绑定到本地主机和主机名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 198.51.100.1:为了连接到此实例,远程客户端必须指定主机名或其关联的IP地址198.51.100.1

mongosh --host My-Example-Associated-Hostname
mongosh --host 198.51.100.1
Important重要

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. 使用主机名而不是IP地址来跨拆分网络范围配置群集。Starting in MongDB 5.0, nodes that are only configured with an IP address will fail startup validation and will not start.从MongDB 5.0开始,仅使用IP地址配置的节点将无法通过启动验证,无法启动。

Add an Arbiter添加仲裁员

Warning警告

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.在使用仲裁器启动新副本集之前,不需要更改集群范围的写入问题。

Important重要

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. 使用主机名而不是IP地址来跨拆分网络范围配置群集。Starting in MongDB 5.0, nodes that are only configured with an IP address will fail startup validation and will not start.从MongDB 5.0开始,仅使用IP地址配置的节点将无法通过启动验证,无法启动。

  1. Create a data directory (e.g. storage.dbPath) for the arbiter. 为仲裁器创建数据目录(例如storage.dbPath)。The mongod instance uses the directory for configuration data. mongod实例使用配置数据目录。The directory will not hold the data set. 目录将不保存数据集。For example, create the /var/lib/mongodb/arb directory:例如,创建/var/lib/mongodb/arb目录:

    mkdir /var/lib/mongodb/arb
  2. 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 the dbPath and rs for the replica set name:以下命令使用/var/lib/mongodb/arb作为dbPath并使用rs作为副本集名称启动仲裁器:

    Warning警告

    Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured 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)>
  3. Connect to the primary and add the arbiter to the replica set. 连接到主服务器并将仲裁器添加到副本集。Use the rs.addArb() method, as in the following example which assumes that m1.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 the m1.example.net host.此操作添加m1.example.net主机上端口27017上运行的仲裁器。

←  Deploy a Geographically Redundant Replica SetConvert a Standalone to a Replica Set →