Upgrade to the Latest Revision of MongoDB升级至MongoDB的最新版本
On this page本页内容
MongoDB 7.0 is a rapid release and is only supported for MongoDB Atlas. MongoDB 7.0是一个快速版本,仅支持MongoDB Atlas。MongoDB 7.0 is not supported for use on-premises. MongoDB 7.0不支持在本地使用。For more information, see MongoDB Versioning.有关更多信息,请参阅MongoDB版本控制。
To install the latest MongoDB version supported for on-premises use, MongoDB 6.0, see the MongoDB 6.0 installation instructions.要安装支持本地使用的最新MongoDB版本MongoDB 6.0,请参阅MongoDB 6.0安装说明。
MongoDB versioning have the form MongoDB版本控制的形式为X.Y.Z
where Z
refers to the revision/patch number. Revisions provide security patches, bug fixes, and new or changed features that generally do not contain any backward breaking changes. X.Y.Z
,其中Z
表示修订版/补丁号。修订版提供了安全补丁、错误修复以及新的或已更改的功能,这些功能通常不包含任何向后突破性的更改。Always upgrade to the latest revision in your release series.始终升级到发行系列中的最新修订版。
For more information on versioning, see MongoDB Versioning.有关版本控制的更多信息,请参阅MongoDB版本控制。
Before Upgrading升级前
Backup备份
Ensure you have an up-to-date backup of your data set. See MongoDB Backup Methods.请确保您拥有数据集的最新备份。请参阅MongoDB备份方法。
Compatibility Considerations兼容性注意事项
Consult the following documents for any special considerations or compatibility issues specific to your MongoDB release:有关特定于MongoDB版本的任何特殊注意事项或兼容性问题,请参阅以下文档:The release notes, located at Release Notes.发行说明,位于发行说明中。The documentation for your driver.驱动程序的文档。
Starting in MongODB 4.2, MongoDB removes support for Ubuntu 16.04 PPCLE.从MongODB 4.2开始,MongODB删除了对Ubuntu 16.04 PPCLE的支持。Starting in MongoDB 3.6.13, MongoDB 3.6-series removes support for Ubuntu 16.04 PPCLE.从MongoDB 3.6.13开始,MongoDB 3.6系列删除了对Ubuntu 16.04 PPCLE的支持。Starting in MongoDB 3.4.21, MongoDB 3.4-series removes support for Ubuntu 16.04 PPCLE.从MongoDB 3.4.21开始,MongoDB 3.4系列删除了对Ubuntu 16.04 PPCLE的支持。
Maintenance Window维护窗口
If your installation includes replica sets, plan the upgrade during a predefined maintenance window.如果您的安装包括复制副本集,请在预定义的维护窗口内计划升级。
Change Streams更改流
Starting in MongoDB 4.0.7, change streams use a version 1 从MongoDB 4.0.7开始,变更流使用版本1v1
resume tokens. v1
的恢复令牌。MongoDB versions earlier than 4.0.7 use 4.0.7之前的MongoDB版本使用v0
resume tokens.v0
恢复令牌。
When upgrading from MongoDB 4.0.6 or earlier to MongoDB 4.0.7 or later, a client may try to resume change streams using the new 当从MongoDB 4.0.6或更早版本升级到MongoDB 4.0.7或更高版本时,当客户端连接到未更新的成员(即仅接受v1
resume token when connected to a member that has not been updated (i.e. only accepts v0
or BinData token) and fail. v0
或BinData令牌)时,可能会尝试使用新的v1恢复令牌恢复更改流,但失败。In such cases, the client must wait for the upgrade to complete before resuming change streams.在这种情况下,客户端必须等待升级完成,然后才能恢复更改流。
Staging Environment Check暂存环境检查
Before you upgrade a production environment, use the procedures in this document to upgrade a staging environment that reproduces your production environment, to ensure that your production configuration is compatible with all changes.在升级生产环境之前,请使用本文档中的步骤升级复制生产环境的暂存环境,以确保生产配置与所有更改兼容。
Upgrade Procedure升级过程
Always backup all of your data before upgrading MongoDB.在升级MongoDB之前,请始终备份所有数据。
Upgrade each 使用此处描述的过程分别升级每个mongod
and mongos
binary separately, using the procedure described here. When upgrading a binary, use the procedure Upgrade a MongoDB Instance.mongod
和mongos
-binary。升级二进制文件时,请使用升级MongoDB实例的过程。
Follow this upgrade procedure:请遵循以下升级过程:
For deployments that use authentication, first upgrade all of your MongoDB Drivers.对于使用身份验证的部署,首先升级所有MongoDB驱动程序。To upgrade, see the documentation for your driver.要升级,请参阅驱动程序的文档。Upgrade sharded clusters, as described in Upgrade Sharded Clusters.升级分片集群,如升级分片集群中所述。Upgrade any standalone instances.升级任何独立实例。See Upgrade a MongoDB Instance.请参阅升级MongoDB实例。Upgrade any replica sets that are not part of a sharded cluster, as described in Upgrade Replica Sets.升级不属于分片集群的任何副本集,如升级副本集中所述。
Upgrade a MongoDB Instance升级MongoDB实例
To upgrade a 要升级mongod
or mongos
instance, use one of these approaches:mongod
或mongos
实例,请使用以下方法之一:
Upgrade the instance using the operating system's package management tool and the official MongoDB packages. This is the preferred approach.使用操作系统的包管理工具和MongoDB官方包升级实例。这是首选方法。See Install MongoDB.请参阅安装MongoDB。Upgrade the instance by replacing the existing binaries with new binaries. See Replace the Existing Binaries.通过用新的二进制文件替换现有的二进制文件来升级实例。请参见替换现有二进制文件。Make any required configuration file changes before restarting the instance.在重新启动实例之前,进行任何所需的配置文件更改。
Replace the Existing Binaries替换现有二进制文件
Always backup all of your data before upgrading MongoDB.在升级MongoDB之前,请始终备份所有数据。
This section describes how to upgrade MongoDB by replacing the existing binaries. 本节介绍如何通过替换现有二进制文件来升级MongoDB。The preferred approach to an upgrade is to use the operating system's package management tool and the official MongoDB packages, as described in Install MongoDB.升级的首选方法是使用操作系统的包管理工具和官方的MongoDB包,如安装MongoDB中所述。
To upgrade a 要通过替换现有二进制文件来升级mongod
or mongos
instance by replacing the existing binaries:mongod
或mongos
实例,请执行以下操作:
Download the binaries for the latest MongoDB revision from the MongoDB Download Page从MongoDB下载页面and store the binaries in a temporary location.
下载最新MongoDB版本的二进制文件,并将二进制文件存储在临时位置。
The binaries download as compressed files that uncompress to the directory structure used by the MongoDB installation.二进制文件作为压缩文件下载,解压缩到MongoDB安装所使用的目录结构。Shutdown the instance.关闭实例。Replace the existing MongoDB binaries with the downloaded binaries.用下载的二进制文件替换现有的MongoDB二进制文件。Make any required configuration file changes.进行任何所需的配置文件更改。Restart the instance.重新启动实例。
Upgrade Replica Sets升级副本集
To upgrade a replica set, upgrade each member individually, starting with the secondaries and finishing with the primary. 要升级复制副本集,请分别升级每个成员,从secondary开始,到primary结束。Plan the upgrade during a predefined maintenance window.在预定义的维护窗口期间计划升级。
Before you upgrade or downgrade a replica set, ensure all replica set members are running. If you do not, the upgrade or downgrade will not complete until all members are started.在升级或降级复制副本集之前,请确保所有复制副本集成员都在运行。如果不这样做,则在启动所有成员之前,升级或降级不会完成。
Starting in MongoDB 4.0.7, change streams use a version 1 从MongoDB 4.0.7开始,变更流使用版本1v1
resume tokens. v1
的恢复令牌。MongoDB versions earlier than 4.0.7 use 4.0.7之前的MongoDB版本使用v0
resume tokens or BinData resume tokens.v0
恢复令牌或BinData恢复令牌。
When upgrading from MongoDB 4.0.0-4.0.6 to MongoDB 4.0.7 or later, a client may try to resume change streams using the new 当从MongoDB 4.0.0-4.0.6升级到MongoDB 4.0.7或更高版本时,当客户端连接到未更新的成员(即仅接受v1
resume token when connected to a member that has not been updated (i.e. only accepts v0
token or BinData) and fail. v0
令牌或BinData)时,可能会尝试使用新的v1
恢复令牌恢复更改流,但失败。In such cases, the client must wait for the upgrade to complete before resuming change streams.在这种情况下,客户端必须等待升级完成,然后才能恢复更改流。
Upgrade Secondaries升级Secondary
Upgrade each secondary separately as follows:按如下方式分别升级每个辅助设备:
Upgrade the secondary's按照更新MongoDB实例中的说明升级secondary的mongod
binary by following the instructions in Upgrade a MongoDB Instance.mongod
二进制文件。After upgrading a secondary, wait for the secondary to recover to the升级辅助实例后,请等待辅助实例恢复到SECONDARY
state before upgrading the next instance.SECONDARY
状态,然后再升级下一个实例。To check the member's state, issue要检查成员的状态,请在rs.status()
inmongosh
.mongosh
中发出rs.status()
。The secondary may briefly go into辅助可能会短暂进入STARTUP2
orRECOVERING
.STARTUP2
或RECOVERING
。This is normal. Make sure to wait for the secondary to fully recover to这很正常。请确保等待辅助系统完全恢复到SECONDARY
before you continue the upgrade.SECONDARY
,然后再继续升级。
Upgrade the Primary升级Primary
Step down the primary to initiate the normal failover procedure.逐步关闭主服务器以启动正常的故障切换过程。Using one of the following:使用以下方法之一:Thers.stepDown()
helper inmongosh
.mongosh
中的rs.stepDown()
帮助程序。ThereplSetStepDown
database command.replSetStepDown
数据库命令。
During failover, the set cannot accept writes.在故障转移期间,该集无法接受写入。Typically this takes 10-20 seconds.这通常需要10-20秒。Plan the upgrade during a predefined maintenance window.在预定义的维护窗口期间计划升级。NoteStepping down the primary is preferable to directly shutting down the primary.关闭初级比直接关闭初级更可取。Stepping down expedites the failover procedure.退出会加快故障转移过程。Once the primary has stepped down, call the主成员退出后,从rs.status()
method frommongosh
until you see that another member has assumed thePRIMARY
state.mongosh
调用rs.status()
方法,直到您看到另一个成员已进入PRIMARY
状态。Shut down the original primary and upgrade its instance by following the instructions in Upgrade a MongoDB Instance.按照升级MongoDB实例中的说明关闭原始主数据库并升级其实例。
Upgrade Sharded Clusters升级分片集群
Changed in version 3.4.3.4版更改。The procedure applies to 6.0. To make revision upgrades for other versions of MongoDB sharded clusters, refer to the appropriate version of the manual.该程序适用于6.0。要对MongoDB分片集群的其他版本进行修订升级,请参阅相应版本的手册。
Starting in MongoDB 4.0.7, change streams use a version 1 从MongoDB 4.0.7开始,变更流使用版本1v1
resume tokens. v1
的恢复令牌。MongoDB versions earlier than 4.0.7 use 4.0.7之前的MongoDB版本使用v0
resume tokens or BinData resume tokens.v0
恢复令牌或BinData恢复令牌。
When upgrading from MongoDB 4.0.6 or earlier to 4.0.7 or later, the members of the sharded clusters will continue to produce 当从MongoDB 4.0.6或更早版本升级到4.0.7或更高版本时,分片集群的成员将继续生成v0
or BinData resume tokens until the mongos
instance(s) are updated. v0
或BinData恢复令牌,直到mongos
实例更新为止。Upgraded 升级后的mongos
instances will begin producing v1
change stream resume tokens. mongos
实例将开始生成v1更改流恢复令牌。These tokens cannot be used to resume a stream on a 这些令牌不能用于在尚未升级到4.0.7或更高版本的mongos
that has not yet been upgraded to 4.0.7 or later.mongos
上恢复流。
To upgrade a 6.0 sharded cluster:要升级6.0分片集群,请执行以下操作:
Disable the cluster's balancer as described in Disable the Balancer.按照禁用平衡器中的说明禁用群集的平衡器。Upgrade the config servers.升级config
服务器。To upgrade the config server replica set, use the procedures in Upgrade Replica Sets.要升级配置服务器副本集,请使用升级副本集中的过程。Upgrade each shard.升级每个分片。If a shard is a replica set, upgrade the shard using the procedure titled Upgrade Replica Sets.如果分片是副本集,请使用名为升级副本集的过程升级分片。If a shard is a standalone instance, upgrade the shard using the procedure titled Upgrade a MongoDB Instance.如果一个分片是一个独立的实例,请使用名为更新MongoDB实例的过程升级该分片。
Once the config servers and the shards have been upgraded, upgrade each配置服务器和分片升级后,按照升级MongoDB实例中的说明升级每个mongos
instance by following the instructions in Upgrade a MongoDB Instance.mongos
实例。You can upgrade the您可以按任何顺序升级mongos
instances in any order.mongos
实例。Re-enable the balancer, as described in Enable the Balancer.重新启用平衡器,如启用平衡器中所述。