Docs HomeMongoDB Manual

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.将复制副本集成员分布在地理位置不同的数据中心会增加冗余,并在其中一个数据中心不可用时提供容错能力。

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.如果Data Center 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

Distributing replica set members across two data centers provides benefit over a single data center. In a two data center distribution,将复制副本集成员分布在两个数据中心提供了优于单个数据中心的优势。在双数据中心分布中,

  • If one of the data centers goes down, the data is still available for reads unlike a single data center distribution.如果其中一个数据中心出现故障,则与单个数据中心分布不同,数据仍可用于读取。
  • If the data center with a minority of the members goes down, the replica set can still serve write operations as well as read operations.如果拥有少数成员的数据中心宕机,副本集仍然可以提供写操作和读操作。
  • However, if the data center with the majority of the members goes down, the replica set becomes read-only.但是,如果包含大多数成员的数据中心出现故障,则副本集将变为只读。

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.如果第三个数据中心的成本过高,一种分发可能性是在两个数据中心之间平均分配数据承载成员,并在公司政策允许的情况下将剩余成员存储在云中。

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.如果Data Center 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

Distributing replica set members across two data centers provides benefit over a single data center. In a two data center distribution,将复制副本集成员分布在两个数据中心提供了优于单个数据中心的优势。在双数据中心分布中,

  • If one of the data centers goes down, the data is still available for reads unlike a single data center distribution.如果其中一个数据中心出现故障,则与单个数据中心分布不同,数据仍可用于读取。
  • If the data center with a minority of the members goes down, the replica set can still serve write operations as well as read operations.如果拥有少数成员的数据中心宕机,副本集仍然可以提供写操作和读操作。
  • However, if the data center with the majority of the members goes down, the replica set becomes read-only.但是,如果包含大多数成员的数据中心出现故障,则副本集将变为只读。

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.如果第三个数据中心的成本过高,一种分发可能性是在两个数据中心之间平均分配数据承载成员,并在公司政策允许的情况下将剩余成员存储在云中。

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 communication among all members; i.e. each member must be able to connect to every other member.验证您的网络配置是否允许所有成员之间进行通信;即每个成员都必须能够连接到其他成员。