翻译或纠错本页面

FAQ:复制和复制集

这篇文档回答了MongoDB数据库复制的常见问题。

MongoDB 支持那些类型的复制?

MongoDB supports replica sets, which can have up to 50 nodes.

MongoDB also supports master-slave replication; however, replica sets are the recommended replication topology. However, if your deployment requires more than 50 nodes, you must use master/slave replication.

可以在互联网和广域网(WAN)上进行复制吗?

可以。

例如,可能在东海岸的数据中心部署维护了一个 primarysecondary ,在遥远的西海岸,部署了一个 secondary 节点用于灾难恢复。

MongoDB的复制可以部署在较差的网络环境中吗?

可以,但是并不是没有连接失败和明显的延迟。

如果子节点和 主节点 的TCP连接被破坏, 复制集 将自动从复制集中选举出一个 term:子节点 并且将它设置为主节点。

既然复制已经提供了数据冗余,为什么还要使用日志?

日志 有助于系统崩溃后更快的恢复。在日志出现之前,系统崩溃往往需要 数据库修复 或者全部数据重新同步。这两种方法都很慢,第一种方法是不可靠的。

日志可以特别有效的预防电源故障,特别是如果你的复制集部署在一个单一的数据中心或单一的电源电路上。

一个复制集在投票时如果节点的数量是奇数,不需要投票节点。

注解

考虑一个常见的配置:两个复制节点包含一个 主节点 和一个 子节点投票节点 作为第三个节点。这种配置使出现错误事件时,选举一个主节点成为了可能,不需要三个复制节点。

如果一个复制集有相等的数量的节点在两个设施或网络分区在两个设施之间,你也可以考虑在复制集中增加一个投票节点,在这种情况下,投票节点将打破两个设施间的平衡,允许复制集选举出一个新的主节点。

What information do arbiters exchange with the rest of the replica set?

投票节点从不接收任何数据集的内容,除了和其余的复制集节点交换以下数据:

  • 用于验证复制集中投票节点的证书。复制集中所有的 MongoDB 进程使用密钥文件,交换信息是加密的。

  • 复制集确认数据和投票数据。这些信息是非加密的,只有证书交换是加密的。

如果你的 MongoDB 使用 SSL 部署,那么在投票节点和复制集中其他节点的所有通信都是安全的。参见文档: Configure mongod and mongos for TLS/SSL 获得更多信息。像所有的 MongoDB 组件一样,运行所有的投票节点在安全的网络环境中。

See the documentation for Configure mongod and mongos for TLS/SSL for more information. As with all MongoDB components, run arbiters on secure networks.

See

The overview of Arbiter Members of Replica Sets.

复制集中的节点使用磁盘空间数量不同正常吗?

可以。

Factors including: different oplog sizes, different levels of storage fragmentation, and MongoDB’s data file pre-allocation can lead to some variation in storage utilization between nodes. Storage use disparities will be most pronounced when you add members at different times.

Can I rename a replica set?

No.

You can use the backup and restore procedure described in the Restore a Replica Set from MongoDB Backups tutorial to create a new replica set with the desired name. Downtime may be necessary in order to ensure parity between the original replica set and the new one.