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.您可以在应用程序服务器或监控主机上部署仲裁器。
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:要将仲裁器添加到现有副本集,请执行以下操作:
You do not need to change the cluster wide write concern before starting a new replica set with an arbiter.在使用仲裁器启动新副本集之前,不需要更改集群范围的写入问题。
Arbiters are not supported with quarterly rapid releases releases. 季度快速发布不支持仲裁。If your deployment includes arbiters, only use LTS releases.如果您的部署包含仲裁器,请仅使用LTS版本。
If you are using a three-member primary-secondary-arbiter (PSA) architecture, the write concern 如果您使用的是三成员主辅仲裁器(PSA)体系结构,那么如果辅仲裁器不可用或滞后,写问题"majority"
can cause performance issues if a secondary is unavailable or lagging. "majority"
可能会导致性能问题。See Mitigate Performance Issues with PSA Replica Set for advice on how to mitigate these issues.有关如何缓解这些问题的建议,请参阅使用PSA副本集缓解性能问题。
For the following MongoDB versions, 对于以下MongoDB版本,对于具有仲裁器的副本集,与pv1
increases the likelihood of w:1
rollbacks compared to pv0
(no longer supported in MongoDB 4.0+) for replica sets with arbiters:pv0
(MongoDB 4.0+不再支持)相比,pv1
增加了w:1
回滚的可能性:
See Replica Set Protocol Version.请参阅副本集协议版本。
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
过程一样,以一组数据文件和一个完整大小的日志启动。
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, MongoDB二进制文件mongod
and mongos
, bind to localhost by default. mongod
和mongos
默认绑定到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 默认情况下,绑定到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. 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 要覆盖默认绑定并绑定到其他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 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 为了连接到此实例,远程客户端必须指定主机名或其关联的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. 使用主机名而不是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地址配置的节点将无法通过启动验证,无法启动。
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.在使用仲裁器启动新副本集之前,不需要更改集群范围的写入问题。
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地址配置的节点将无法通过启动验证,无法启动。
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
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
作为副本集名称启动仲裁器:
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)>
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
上运行的仲裁器。