On this page本页内容
The architecture of a replica set affects the set's capacity and capability. 副本集的体系结构会影响副本集的容量和功能。This document provides strategies for replica set deployments and describes common architectures.本文档提供了副本集部署的策略,并描述了常见的体系结构。
The standard replica set deployment for a production system is a three-member replica set. 生产系统的标准副本集部署是一个三成员副本集。These sets provide redundancy and fault tolerance. 这些设置提供冗余和容错。Avoid complexity when possible, but let your application requirements dictate the architecture.尽可能避免复杂性,但让应用程序需求决定体系结构。
Add members in a replica set according to these strategies.根据这些策略在副本集中添加成员。
A replica set can have up to 50 members, but only 7 voting members. 一个副本集最多可以有50个成员,但只有7个投票成员。If the replica set already has 7 voting members, additional members must be non-voting members.如果副本集已经有7个投票成员,则其他成员必须是无投票权成员。
Ensure that the replica set has an odd number of voting members. 确保副本集具有奇数个投票成员。A replica set can have up to 7 voting members. 一个副本集最多可以有7个投票成员。If you have an even number of voting members, deploy another data bearing voting member or, if constraints prohibit against another data bearing voting member, an arbiter.如果您有偶数个投票成员,请部署另一个数据承载投票成员,或者如果约束条件禁止另一个投票成员使用仲裁器,则部署一个仲裁器。
An arbiter does not store a copy of the data and requires fewer resources. 仲裁器不存储数据副本,并且需要更少的资源。As a result, you may run an arbiter on an application server or other shared resource. 因此,您可以在应用程序服务器或其他共享资源上运行仲裁程序。With no copy of the data, it may be possible to place an arbiter into environments that you would not place other members of the replica set. 在没有数据拷贝的情况下,可能会将仲裁器放置到您不会放置副本集其他成员的环境中。Consult your security policies.请参阅您的安全策略。
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:pv1
比pv0
(MongoDB 4.0+不再支持)增加了w:1
回滚的可能性:
See Replica Set Protocol Version.请参阅副本集协议版本。
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.在使用仲裁程序启动新副本集之前,无需更改集群范围的写入问题。
Fault tolerance for a replica set is the number of members that can become unavailable and still leave enough members in the set to elect a primary. 副本集的容错性是指可以不可用但仍保留足够成员以选择主副本集的成员数。In other words, it is the difference between the number of members in the set and the 换言之,这是选举初选所需的集合成员数与majority
of voting members needed to elect a primary. majority
投票成员数之间的差异。Without a primary, a replica set cannot accept write operations. Fault tolerance is an effect of replica set size, but the relationship is not direct. See the following table:如果没有主副本,副本集将无法接受写入操作。容错是副本集大小的一种影响,但这种关系不是直接的。见下表:
3 | 2 | 1 |
4 | 3 | 1 |
5 | 3 | 2 |
6 | 4 | 2 |
Adding a member to the replica set does not always increase the fault tolerance. 向副本集添加成员并不总是会增加容错能力。However, in these cases, additional members can provide support for dedicated functions, such as backups or reporting.但是,在这些情况下,其他成员可以为专用功能提供支持,如备份或报告。
Starting in version 4.2.1, 从版本4.2.1开始,rs.status()
returns majorityVoteCount
for the replica set.rs.status()
返回副本集的majorityVoteCount
。
Add hidden or delayed members to support dedicated functions, such as backup or reporting.添加隐藏或延迟成员以支持专用功能,如备份或报告。
In a deployment with very high read traffic, you can improve read throughput by distributing reads to secondary members. 在具有极高读取流量的部署中,可以通过将读取分发给辅助成员来提高读取吞吐量。As your deployment grows, add or move members to alternate data centers to improve redundancy and availability.随着部署的增长,将成员添加或移动到备用数据中心,以提高冗余和可用性。
Distributing replica set members across two data centers provides benefit over a single data center. 跨两个数据中心分布副本集成员比单个数据中心更具优势。In a two data center distribution,在两个数据中心的分布中,
If possible, distribute members across at least three data centers. 如果可能,请将成员分布到至少三个数据中心。For config server replica sets (CSRS), the best practice is to distribute across three (or more depending on the number of members) centers. 对于配置服务器副本集(CSRS),最佳实践是分布在三个(或更多,具体取决于成员数量)中心。If the cost of the third data center is prohibitive, one distribution possibility is to evenly distribute the data bearing members across the two data centers and store the remaining member in the cloud if your company policy allows.如果第三个数据中心的成本过高,一种分布可能性是在两个数据中心均匀分布数据承载成员,如果公司政策允许,将其余成员存储在云中。
Always ensure that the main facility is able to elect a primary.始终确保主设备能够选择主设备。
The existing members of a replica set must have spare capacity to support adding a new member. 副本集的现有成员必须具有备用容量才能支持添加新成员。Always add new members before the current demand saturates the capacity of the set.总是在当前需求使集合容量饱和之前添加新成员。
To protect your data in case of a data center failure, keep at least one member in an alternate data center. 为了在数据中心发生故障时保护数据,请在备用数据中心中至少保留一个成员。If possible, use an odd number of data centers, and choose a distribution of members that maximizes the likelihood that even with a loss of a data center, the remaining replica set members can form a majority or at minimum, provide a copy of your data.如果可能,请使用奇数个数据中心,并选择一种成员分布,以最大限度地提高即使丢失数据中心,其余副本集成员也可以构成大多数或至少提供数据副本的可能性。
Distributing replica set members across two data centers provides benefit over a single data center. 跨两个数据中心分布副本集成员比单个数据中心更具优势。In a two data center distribution,在两个数据中心的分布中,
If possible, distribute members across at least three data centers. For config server replica sets (CSRS), the best practice is to distribute across three (or more depending on the number of members) centers. 如果可能,请将成员分布到至少三个数据中心。对于配置服务器副本集(CSRS),最佳实践是分布在三个(或更多,具体取决于成员数量)中心。If the cost of the third data center is prohibitive, one distribution possibility is to evenly distribute the data bearing members across the two data centers and store the remaining member in the cloud if your company policy allows.如果第三个数据中心的成本过高,一种分布可能性是在两个数据中心均匀分布数据承载成员,如果公司政策允许,将其余成员存储在云中。
To ensure that the members in your main data center be elected primary before the members in the alternate data center, set the 为了确保主数据中心中的成员优先于备用数据中心的成员,请将备用数据中心中成员的members[n].priority
of the members in the alternate data center to be lower than that of the members in the primary data center.members[n].priority
设置为低于主数据中心成员的优先级。
For more information, see Replica Sets Distributed Across Two or More Data Centers有关更多信息,请参阅跨两个或更多数据中心分布的副本集
Use replica set tag sets to target read operations to specific members or to customize write concern to request acknowledgement from specific members.使用副本集标记集将读取操作定向到特定成员,或自定义写入关注点以请求特定成员的确认。
MongoDB enables journaling by default. MongoDB默认启用日志记录。Journaling protects against data loss in the event of service interruptions, such as power failures and unexpected reboots.日志记录可防止服务中断(如电源故障和意外重新启动)时的数据丢失。
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地址的节点将无法通过启动验证,无法启动。
If your application connects to more than one replica set, each set must have a distinct name. 如果应用程序连接到多个副本集,则每个副本集必须具有不同的名称。Some drivers group replica set connections by replica set name.一些驱动程序按副本集名称对副本集连接进行分组。
The following documents describe common replica set deployment patterns. 以下文档描述了常见的副本集部署模式。Other patterns are possible and effective depending on the application's requirements. 根据应用程序的需求,其他模式是可能的和有效的。If needed, combine features of each architecture in your own deployment:如果需要,在您自己的部署中结合每个体系结构的功能: