On this page本页内容
A replica set in MongoDB is a group of MongoDB中的副本集是一组提供冗余和高可用性的mongod
processes that provide redundancy and high availability. mongod
进程。The members of a replica set are:副本集的成员包括:
The minimum recommended configuration for a replica set is a three member replica set with three data-bearing members: one primary and two secondary members. 副本集的最低建议配置为三成员副本集,其中包含三个数据承载成员:一个主成员和两个辅助成员。In some circumstances (such as you have a primary and a secondary but cost constraints prohibit adding another secondary), you may choose to include an arbiter. 在某些情况下(例如,您有一个主服务器和一个辅助服务器,但由于成本限制,无法添加另一个辅助服务器),您可以选择包括仲裁器。An arbiter participates in elections but does not hold data (i.e. does not provide data redundancy).仲裁人参与选举但不保存数据(即不提供数据冗余)。
A replica set can have up to 50 members but only 7 voting members.副本集最多可以有50个成员,但只有7个投票成员。
The primary is the only member in the replica set that receives write operations. 主副本是副本集中唯一接收写入操作的成员。MongoDB applies write operations on the primary and then records the operations on the primary's oplog. MongoDB在主服务器上应用写操作,然后在主服务器的oplog上记录这些操作。Secondary members replicate this log and apply the operations to their data sets.次要成员复制此日志,并将操作应用于其数据集。
In the following three-member replica set, the primary accepts all write operations. 在以下三成员副本集中,主副本接受所有写入操作。Then the secondaries replicate the oplog to apply to their data sets.然后,二级数据库复制oplog以应用于它们的数据集。
All members of the replica set can accept read operations. 副本集的所有成员都可以接受读取操作。However, by default, an application directs its read operations to the primary member. 但是,默认情况下,应用程序将其读取操作定向到主成员。See Read Preference for details on changing the default read behavior.有关更改默认阅读行为的详细信息,请参阅读取首选项。
The replica set can have at most one primary. 副本集最多可以有一个主副本。[2] If the current primary becomes unavailable, an election determines the new primary. 如果当前初选不可用,则选举将决定新的初选。See Replica Set Elections for more details.有关详细信息,请参阅副本集选举。
A secondary maintains a copy of the primary's data set. 辅助服务器维护primary数据集的副本。To replicate data, a secondary applies operations from the primary's oplog to its own data set in an asynchronous process. 为了复制数据,辅助服务器在异步过程中将主服务器的oplog中的操作应用于自己的数据集。[1] A replica set can have one or more secondaries.副本集可以有一个或多个辅助副本。
The following three-member replica set has two secondary members. 以下三个成员的副本集有两个辅助成员。The secondaries replicate the primary's oplog and apply the operations to their data sets.二级数据库复制主数据库的oplog,并将这些操作应用于它们的数据集。
Although clients cannot write data to secondaries, clients can read data from secondary members. 尽管客户端无法向辅助成员写入数据,但客户端可以从辅助成员读取数据。See Read Preference for more information on how clients direct read operations to replica sets.有关客户端如何将读取操作定向到副本集的更多信息,请参阅读取首选项。
A secondary can become a primary. 次要的可以变成主要的。If the current primary becomes unavailable, the replica set holds an election to choose which of the secondaries becomes the new primary.如果当前主副本不可用,副本集将进行选举,以选择哪个辅助副本将成为新的主副本。
See Replica Set Elections for more details.有关详细信息,请参阅副本集选举。
You can configure a secondary member for a specific purpose. 可以为特定目的配置辅助成员。You can configure a secondary to:您可以将辅助服务器配置为:
[1] |
|
In some circumstances (such as when you have a primary and a secondary, but cost constraints prohibit adding another secondary), you may choose to add an arbiter to your replica set. 在某些情况下(例如,当您有一个主副本和一个辅助副本,但成本限制禁止添加另一个辅助副本时),您可以选择向副本集中添加仲裁器。An arbiter participates in elections for primary but an arbiter does not have a copy of the data set and cannot become a primary.仲裁器参与primary选举,但仲裁员没有数据集的副本,不能成为primary。
An arbiter has exactly 一个仲裁者只有1
election vote. 1
张选举票。By default an arbiter has priority 默认情况下,仲裁者的优先级为0
.0
。
Do not run an arbiter on systems that also host the primary or the secondary members of the replica set.不要在同时承载副本集的主要或次要成员的系统上运行仲裁器。
To add an arbiter, see Add an Arbiter to Replica Set.要添加仲裁器,请参阅将仲裁器添加到副本集。
For considerations when using an arbiter, see Replica Set Arbiter.有关使用仲裁器时的注意事项,请参阅副本集仲裁器。
[2] | { w: "majority" } write concern. { w: "majority" } 写入问题完成写入。{ w: "majority" } writes is the current primary, and the other node is a former primary that has not yet recognized its demotion, typically due to a network partition. { w: "majority" } 写入的节点是当前主节点,而另一个节点是尚未识别其降级的前主节点,通常是由于网络分区。primary , and new writes to the former primary will eventually roll back.primary ,并且对前一个主节点的新写入最终会回滚。 |