On this page本页内容
A replica set member becomes "stale" when its replication process falls so far behind that the primary overwrites oplog entries the member has not yet replicated. 当副本集成员的复制过程落后太多,以至于primary覆盖了该成员尚未复制的oplog条目时,副本集成员就会变得“过时”。The member cannot catch up and becomes "stale." 成员无法赶上并变得“过时”。When this occurs, you must completely resynchronize the member by removing its data and performing an initial sync.发生这种情况时,必须通过删除其数据并执行初始同步来完全重新同步该成员。
This tutorial addresses both resyncing a stale member and creating a new member using seed data from another member, both of which can be used to restore a replica set member. 本教程介绍了重新同步过时成员和使用来自另一个成员的种子数据创建新成员,这两个都可以用于恢复副本集成员。When syncing a member, choose a time when the system has the bandwidth to move a large amount of data. 同步成员时,请选择系统有带宽移动大量数据的时间。Schedule the synchronization during a time of low usage or during a maintenance window.在低使用率或维护时段安排同步。
MongoDB provides two options for performing an initial sync:MongoDB为执行初始同步提供了两个选项:
Restart the 使用空数据目录重新启动mongod
with an empty data directory and let MongoDB's normal initial syncing feature restore the data. mongod
,让MongoDB的正常初始同步功能恢复数据。This is the more simple option but may take longer to replace the data.这是一个更简单的选项,但替换数据可能需要更长的时间。
See Automatically Sync a Member.请参见自动同步成员。
Restart the machine with a copy of a recent data directory from another member in the replica set. 使用副本集中其他成员的最新数据目录副本重新启动计算机。This procedure can replace the data more quickly but requires more manual steps.此过程可以更快地替换数据,但需要更多的手动步骤。
See Sync by Copying Data Files from Another Member.请参见通过从其他成员复制数据文件进行同步。
To prevent changing the write quorum, never rotate more than one replica set member at a time.要防止更改写入仲裁,请不要一次旋转多个副本集成员。
This procedure relies on MongoDB's regular process for Replica Set Syncing. 此过程依赖于MongoDB的副本集同步常规过程。This stores the current data on the member. 这将存储成员的当前数据。For an overview of MongoDB initial sync process, see the Replica Set Syncing section.有关MongoDB初始同步过程的概述,请参阅副本集同步部分。
Initial sync operations can impact the other members of the set and create additional traffic to the primary. 初始同步操作可能会影响集合中的其他成员,并为主要成员创建额外的流量。The syncing member requires another member of the set that is accessible and up to date.同步成员需要集合中另一个可访问且最新的成员。
If the instance has no data, you can follow the Add Members to a Replica Set or Replace a Replica Set Member procedure to add a new member to a replica set.如果实例没有数据,可以按照将成员添加到副本集或替换副本集成员过程向副本集添加新成员。
You can also force a 您还可以通过重新启动实例而不使用mongod
that is already a member of the set to perform an initial sync by restarting the instance without the contents of the dbPath
directory:dbPath
目录的内容来强制已经是集合成员的mongod
执行初始同步:
mongod
instance. mongod
实例。db.shutdownServer()
method from mongosh
or on Linux systems, the mongod --shutdown
option.mongosh
或Linux系统中的db.shutdownServer()
方法,mongod
-shutdown选项。dbPath
directory. dbPath
目录中的所有数据和子目录。diagnostic.data
directory to preserve potentially-useful troubleshooting data in the event of an issue. diagnostic.data
目录,以在出现问题时保留可能有用的故障排除数据。dbPath
directory.dbPath
目录中删除所有数据和子目录。mongod
进程。At this point, the 此时,mongod
performs an initial sync. mongod
执行初始同步。The length of the initial sync process depends on the size of the database and the network latency between members of the replica set.初始同步过程的长度取决于数据库的大小和副本集成员之间的网络延迟。
This approach "seeds" a new or stale member using the data files from an existing member of the replica set. 这种方法使用副本集现有成员的数据文件“种子”新成员或过时成员。The data files must be sufficiently recent to allow the new member to catch up with the oplog. 数据文件必须足够新,以允许新成员赶上oplog。Otherwise the member would need to perform an initial sync.否则,成员将需要执行初始同步。
You can capture the data files as either a snapshot or a direct copy. 您可以将数据文件捕获为快照或直接副本。However, in most cases you cannot copy data files from a running 然而,在大多数情况下,您不能将数据文件从一个正在运行的mongod
instance to another because the data files will change during the file copy operation.mongod
实例复制到另一个实例,因为数据文件在文件复制操作期间会发生更改。
If copying data files, ensure that your copy includes the content of the 如果复制数据文件,请确保副本包含local
database.local
数据库的内容。
You cannot use a 不能对数据文件使用mongodump
backup for the data files: only a snapshot backup. mongodump
备份:只能使用快照备份。For approaches to capturing a consistent snapshot of a running 有关捕获正在运行的mongod
instance, see the MongoDB Backup Methods documentation.mongod
实例的一致快照的方法,请参阅MongoDB备份方法文档。
After you have copied the data files from the "seed" source, start the 从“种子”源复制数据文件后,使用新mongod
instance with a new members[n]._id
and allow it to apply all operations from the oplog until it reflects the current state of the replica set. members[n]._id
启动mongod
实例,并允许它应用oplog中的所有操作,直到它反映副本集的当前状态。To see the current status of the replica set, use 要查看副本集的当前状态,请使用rs.printSecondaryReplicationInfo()
or rs.status()
.rs.printSecondaryReplicationInfo()
或rs.status()
。