Database Manual / Replication / Deployment Architectures

Replica Sets Distributed Across Two or More Data Centers分布在两个或多个数据中心的副本集

Overview概述

While replica sets provide basic protection against single-instance failure, replica sets whose members are all located in a single data center are susceptible to data center failures. Power outages, network interruptions, and natural disasters are all issues that can affect replica sets whose members are located in a single facility.虽然副本集提供了针对单实例故障的基本保护,但其成员都位于单个数据中心的副本集容易受到数据中心故障的影响。停电、网络中断和自然灾害都是可能影响其成员位于单个设施中的副本集的问题。

Distributing replica set members across geographically distinct data centers adds redundancy and provides fault tolerance if one of the data centers is unavailable.将副本集成员分布在地理位置不同的数据中心可以增加冗余,并在其中一个数据中心不可用时提供容错。

Some cloud providers use regions and availability zones. Regions are separate geographic areas. Availability zones are the same as data centers and are separate physical locations within a region. A replica set has high availability if the nodes are in different availability zones because it is unlikely that all zones will fail at the same time.一些云提供商使用区域和可用性区域。区域是独立的地理区域。可用区与数据中心相同,是一个区域内独立的物理位置。如果节点位于不同的可用性区域,则副本集具有高可用性,因为不太可能所有区域同时发生故障。

Distribution of the Members成员分布

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.为了在数据中心发生故障时保护数据,请在备用数据中心中至少保留一个成员。如果可能的话,使用奇数个数据中心,并选择一个成员分布,以最大限度地提高即使数据中心丢失,剩余副本集成员也可以形成多数或至少提供数据副本的可能性。

Examples示例

Three-member Replica Set三人副本集

For example, for a three-member replica set, some possible distributions of members include:例如,对于一个由三个成员组成的副本集,一些可能的成员分布包括:

  • Two data centers: two members to Data Center 1 and one member to Data Center 2.两个数据中心:数据中心1有两个成员,数据中心2有一个成员。

    • If Data Center 1 goes down, the replica set becomes read-only.如果数据中心1发生故障,副本集将变为只读。
    • If Data Center 2 goes down, the replica set remains writable as the members in Data Center 1 can hold an election.如果数据中心2发生故障,副本集仍然可写,因为数据中心1中的成员可以进行选举。
  • Three data centers: one member to Data Center 1, one member to Data Center 2, and one member to Data Center 3.三个数据中心:一个成员到数据中心1,一个成员来数据中心2,还有一个成员去数据中心3。

    • If any Data Center goes down, the replica set remains writable as the remaining members can hold an election.如果任何数据中心发生故障,副本集仍然可写,因为其余成员可以进行选举。

Note

For production deployments, we recommend deplying config server and shard replica sets on at least three data centers. This configuration provides high availability in case a single data center goes down.对于生产部署,我们建议将配置服务器和分片副本集部署在至少三个数据中心上。此配置可在单个数据中心发生故障时提供高可用性。

Five-member Replica Set五人复制品套装

For a replica set with 5 members, some possible distributions of members include:对于包含5个成员的副本集,一些可能的成员分布包括:

  • Two data centers: three members to Data Center 1 and two members to Data Center 2.两个数据中心:数据中心1有三个成员,数据中心2有两个成员。

    • If Data Center 1 goes down, the replica set becomes read-only.如果数据中心1发生故障,副本集将变为只读。
    • If Data Center 2 goes down, the replica set remains writeable as the members in Data Center 1 can create a majority.如果数据中心2发生故障,副本集将保持可写状态,因为数据中心1中的成员可以创建多数副本集。
  • Three data centers: two member to Data Center 1, two members to Data Center 2, and one member to site Data Center 3.三个数据中心:两个成员到数据中心1,两个成员去数据中心2,一个成员到站点数据中心3。

    • If any Data Center goes down, the replica set remains writeable as the remaining members can hold an election.如果任何数据中心发生故障,副本集仍然可以写入,因为其余成员可以进行选举。

Note

For production deployments, we recommend deplying config server and shard replica sets on at least three data centers. This configuration provides high availability in case a single data center goes down.对于生产部署,我们建议将配置服务器和分片副本集部署在至少三个数据中心上。此配置可在单个数据中心发生故障时提供高可用性。

For example, the following 5 member replica set distributes its members across three data centers.例如,以下5个成员的副本集将其成员分布在三个数据中心。

Diagram of a 5 member replica set distributed across three data centers.

Electability of Members成员的选举权

Some members of the replica set, such as members that have networking restraint or limited resources, should not be able to become primary in a failover. 副本集的某些成员(如具有网络限制或资源有限的成员)不应成为故障转移中的主要成员。Configure members that should not become primary to have priority 0.将不应成为主要成员的成员配置为具有优先级0

In some cases, you may prefer that the members in one data center be elected primary before the members in the other data centers. 在某些情况下,您可能希望一个数据中心中的成员在其他数据中心的成员之前被选为主要成员。You can modify the priority of the members such that the members in the one data center has higher priority than the members in the other data centers.您可以修改成员的priority,使一个数据中心中的成员具有比其他数据中心中成员更高的priority

In the following example, the replica set members in Data Center 1 have a higher priority than the members in Data Center 2 and 3; the members in Data Center 2 have a higher priority than the member in Data Center 3:在以下示例中,数据中心1中的副本集成员具有比数据中心2和3中的成员更高的优先级;数据中心2中的成员具有比数据中心3中的成员更高的优先级:

Diagram of a 5 member replica set distributed across three data centers. Replica set includes members with priority 0.5 and priority 0.

Connectivity连接性

Verify that your network configuration allows each member to connect to every other member.验证网络配置是否允许每个成员连接到其他所有成员。

Learn More了解更多