Upgrade to the Latest Revision of MongoDB升级至MongoDB的最新版本

On this page本页内容

MongoDB versioning have the form X.Y.Z where Z refers to the revision/patch number. MongoDB版本控制的格式为X.Y.Z,其中Z表示版本号/补丁号。Revisions provide security patches, bug fixes, and new or changed features that generally do not contain any backward breaking changes. 修订版提供了安全补丁、错误修复,以及通常不包含任何向后破坏性更改的新功能或更改的功能。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兼容性考虑

Important重要
  • 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 v1 resume tokens. 从MongoDB 4.0.7开始,change streams使用v1的恢复令牌。MongoDB versions earlier than 4.0.7 use v0 resume tokens.4.0.7之前的MongoDB版本使用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 v1 resume token when connected to a member that has not been updated (i.e. only accepts v0 or BinData token) and fail. 从MongoDB 4.0.6或更早版本升级到MongoDB 4.0.7或更高版本时,当连接到未更新的成员(即仅接受v0或BinData令牌)并失败时,客户端可能会尝试使用新的v1 resume令牌恢复更改流。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升级程序

Important重要
Always backup all of your data before upgrading MongoDB.升级MongoDB之前,请始终备份所有数据。

Upgrade each mongod and mongos binary separately, using the procedure described here. 使用此处描述的过程分别升级每个mongodmongos二进制文件。When upgrading a binary, use the procedure Upgrade a MongoDB Instance.升级二进制文件时,请使用升级MongoDB实例的过程

Follow this upgrade procedure:请遵循以下升级过程:

  1. For deployments that use authentication, first upgrade all of your MongoDB Drivers. 对于使用身份验证的部署,首先升级所有MongoDB驱动程序。To upgrade, see the documentation for your driver.要升级,请参阅驱动程序的文档
  2. Upgrade sharded clusters, as described in Upgrade Sharded Clusters.升级分片群集,如U升级分片群集中所述。
  3. Upgrade any standalone instances. 升级任何独立实例。See Upgrade a MongoDB Instance.请参阅升级MongoDB实例
  4. 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:要升级mongodmongos实例,请使用以下方法之一:

  • Upgrade the instance using the operating system's package management tool and the official MongoDB packages. 使用操作系统的包管理工具和官方的MongoDB包升级实例。This is the preferred approach. 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替换现有的二进制文件

Important重要
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:要通过替换现有二进制文件升级mongodmongos实例,请执行以下操作:

  1. Download the binaries for the latest MongoDB revision from the MongoDB Download Page and store the binaries in a temporary location. MongoDB下载页面下载最新MongoDB版本的二进制文件,并将二进制文件存储在临时位置。The binaries download as compressed files that uncompress to the directory structure used by the MongoDB installation.二进制文件作为压缩文件下载,解压缩到MongoDB安装使用的目录结构。
  2. Shutdown the instance.关闭实例。
  3. Replace the existing MongoDB binaries with the downloaded binaries.用下载的二进制文件替换现有的MongoDB二进制文件。
  4. Make any required configuration file changes.进行任何必要的配置文件更改。
  5. Restart the instance.重新启动实例。

Upgrade Replica Sets升级副本集

To upgrade a replica set, upgrade each member individually, starting with the secondaries and finishing with the primary. 要升级副本集,请分别升级每个成员,从secondaries开始,到primary结束。Plan the upgrade during a predefined maintenance window.在预定义的维护窗口期间计划升级。

Important重要

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.如果不这样做,升级或降级将在所有成员启动之前完成。

Note注意

Starting in MongoDB 4.0.7, change streams use a version 1 v1resume tokens. 从MongoDB 4.0.7开始,更改流使用v1恢复令牌MongoDB versions earlier than 4.0.7 use v0 resume tokens or BinData resume tokens.4.0.7之前的MongoDB版本使用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 v1 resume token when connected to a member that has not been updated (i.e. only accepts v0 token or BinData) and fail. 从MongoDB 4.0.0-4.0.6升级到MongoDB 4.0.7或更高版本时,当连接到未更新的成员(即仅接受v0令牌或BinData)且失败时,客户端可能会尝试使用新的v1恢复令牌恢复更改流。In such cases, the client must wait for the upgrade to complete before resuming change streams.在这种情况下,客户端必须等待升级完成,然后才能恢复更改流。

Upgrade Secondaries升级辅助设备

Upgrade each secondary separately as follows:按如下方式分别升级每个辅助设备:

  1. Upgrade the secondary's mongod binary by following the instructions in Upgrade a MongoDB Instance.按照升级MongoDB实例中的说明升级辅助服务器的mongod二进制文件。
  2. 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() in mongosh.要检查成员的状态,请在mongosh中发出rs.status()

    The secondary may briefly go into STARTUP2 or RECOVERING. 第二阶段可能会短暂进入STARTUP2RECOVERING阶段。This is normal. 这很正常。Make sure to wait for the secondary to fully recover to SECONDARY before you continue the upgrade.在继续升级之前,请确保等待辅助服务器完全恢复到SECONDARY

Upgrade the Primary升级主设备

  1. Step down the primary to initiate the normal failover procedure. 关闭主设备以启动正常的故障切换过程。Using one of the following:使用以下选项之一:

    During failover, the set cannot accept writes. 故障转移期间,该集无法接受写入。Typically this takes 10-20 seconds. 通常这需要10-20秒。Plan the upgrade during a predefined maintenance window.在预定义的维护窗口期间计划升级。

    Note注意

    Stepping down the primary is preferable to directly shutting down the primary. 与直接关闭主电源相比,最好是关闭主电源。Stepping down expedites the failover procedure.退出将加快故障切换过程。

  2. Once the primary has stepped down, call the rs.status() method from mongosh until you see that another member has assumed the PRIMARY state.主成员退出后,从mongosh调用rs.status()方法,直到看到另一个成员已采用PRIMARY状态。
  3. 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 5.0. 该程序适用于5.0。To make revision upgrades for other versions of MongoDB sharded clusters, refer to the appropriate version of the manual.要对其他版本的MongoDB分片集群进行修订升级,请参阅相应版本的手册。

Note注意

Starting in MongoDB 4.0.7, change streams use a version 1 v1resume tokens. 从MongoDB 4.0.7开始,变更流使用版本1的恢复令牌MongoDB versions earlier than 4.0.7 use v0 resume tokens or BinData resume tokens.4.0.7之前的MongoDB版本使用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 v0 or BinData resume tokens until the mongos instance(s) are updated. 当从MongoDB 4.0.6或更早版本升级到4.0.7或更高版本时,分片集群的成员将继续生成v0或BinData resume令牌,直到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 mongos that has not yet been upgraded to 4.0.7 or later.这些令牌不能用于恢复mongos上尚未升级到4.0.7或更高版本的流。

To upgrade a 5.0 sharded cluster:要升级5.0分片群集,请执行以下操作:

  1. Disable the cluster's balancer as described in Disable the Balancer.禁用群集的均衡器,如禁用均衡器中所述。
  2. Upgrade the config servers.升级配置服务器

    To upgrade the config server replica set, use the procedures in Upgrade Replica Sets.要升级配置服务器副本集,请使用升级副本集中的步骤。

  3. Upgrade each shard.升级每个分片。

  4. Once the config servers and the shards have been upgraded, upgrade each mongos instance by following the instructions in Upgrade a MongoDB Instance. 升级配置服务器和分片后,按照升级MongoDB实例中的说明升级每个mongos实例。You can upgrade the mongos instances in any order.您可以按任何顺序升级mongos实例。
  5. Re-enable the balancer, as described in Enable the Balancer.重新启用均衡器,如启用均衡器中所述。
←  Run-time Database ConfigurationManage mongod Processes →