管理链式复制¶
On this page
自2.0版本之后,MongoDB开始支持链式复制。当 secondary 从其他从节点上进行复制而不是 primary 的时候,就发生了链式复制。当从节点根据节点之间的ping值来进行选取的时候,最近的从节点可能会被选中,从而产生链式复制。
链式复制可以减低主节点的load。但是链式复制也可能造成复制的滞后,这取决于网络情况。
使用如下的操作将 chainingAllowed 设置为 false :
MongoDB默认是允许链式复制的。本教程讲述了如何禁止和重新开启链式复制。
注解
如果禁止了链式复制,我们也可以通过使用 replSetSyncFrom 来指定某个从节点由另一个从节点上进行复制。但是该配置仅会在从节点重新计算由哪复制后生效。
禁止链式复制¶
To disable chained replication, set the settings.chainingAllowed field in Replica Set Configuration to false.
You can use the following sequence of commands to set settings.chainingAllowed to false:
将配置信息赋值给 cfg :
cfg = rs.config()
Take note of whether the current configuration settings contain the settings embedded document. If they do, skip this step.
警告
To avoid data loss, skip this step if the configuration settings contain the settings embedded document.
If the current configuration settings do not contain the settings embedded document, create the embedded document by issuing the following command:
cfg.settings = { }
Issue the following sequence of commands to set settings.chainingAllowed to false:
cfg.settings.chainingAllowed = false rs.reconfig(cfg)
Re-enable Chained Replication¶
To re-enable chained replication, set settings.chainingAllowed to true. You can use the following sequence of commands:
cfg = rs.config()
cfg.settings.chainingAllowed = true
rs.reconfig(cfg)