Database Manual / Release Notes / 8.2 (Stable Release) / Upgrade 8.0 to 8.2

Upgrade a Sharded Cluster to 8.2将分片集群升级到8.2

Important

MongoDB 8.3 is the latest minor release. Starting with MongoDB 8.2, minor releases are available for on-premises deployments (Community and EA) for specific use cases. MongoDB 8.3是最新的次要版本。从MongoDB 8.2开始,次要版本可用于特定用例的本地部署(社区和EA)。For more information, see MongoDB Versioning.有关更多信息,请参阅MongoDB版本控制

To install the latest MongoDB version supported for on-premises use, see the installation instructions.要安装支持本地使用的最新MongoDB版本,请参阅安装说明

Familiarize yourself with the content of this document, including thoroughly reviewing the prerequisites, prior to upgrading to MongoDB 8.2.在升级到MongoDB 8.2之前,请熟悉本文档的内容,包括彻底审查先决条件。

The following steps outline the procedure to upgrade a mongod that is a shard member from version 8.0 to 8.2.以下步骤概述了将分片成员mongod从8.0版本升级到8.2的过程。

If you need guidance on upgrading to 8.2, MongoDB professional services offer major version upgrade support to help ensure a smooth transition without interruption to your MongoDB application.如果您需要升级到8.2的指导,MongoDB专业服务提供主要版本升级支持,以帮助确保顺利过渡到MongoDB应用程序,而不会中断。

Upgrade Recommendations and Checklists升级建议和清单

When upgrading, consider the following:升级时,请考虑以下事项:

Upgrade Version Path升级版本路径

To upgrade an existing MongoDB deployment to 8.2, you must be running a 8.0-series release.要将现有的MongoDB部署升级到8.2,您必须运行8.0系列版本。

To upgrade from a version earlier than the 8.0-series, you must successively upgrade major releases until you have upgraded to 8.0-series. 要从早于8.0系列的版本升级,您必须连续升级主要版本,直到升级到8.0系列。For example, if you are running a 7.0-series, you must upgrade first to 8.0 before you can upgrade to 8.2.例如,如果您运行的是7.0系列,则必须先升级到8.0,然后才能升级到8.2。

Check Driver Compatibility检查驱动程序兼容性

Before you upgrade MongoDB, check that you're using a MongoDB 8.2-compatible driver. Consult the driver documentation for your specific driver to verify compatibility with MongoDB 8.2.在升级MongoDB之前,请检查您是否使用了与MongoDB 8.2兼容的驱动程序。请参阅特定驱动程序的驱动程序文档,以验证与MongoDB 8.2的兼容性。

Upgraded deployments that run on incompatible drivers might encounter unexpected or undefined behavior.在不兼容的驱动程序上运行的升级部署可能会遇到意外或未定义的行为。

Preparedness准备

Before beginning your upgrade, see the Compatibility Changes in MongoDB 8.2 document to ensure that your applications and deployments are compatible with MongoDB 8.2. Resolve the incompatibilities in your deployment before starting the upgrade.在开始升级之前,请参阅MongoDB 8.2中的兼容性更改文档,以确保您的应用程序和部署与MongoDB 8.2兼容。在开始升级之前,请解决部署中的不兼容问题。

Before upgrading MongoDB, always test your application in a staging environment before deploying the upgrade to your production environment.在升级MongoDB之前,请务必在将升级部署到生产环境之前,在测试环境中测试您的应用程序。

Downgrade Consideration降级考虑

You cannot downgrade your deployment's binary version without assistance from support.没有支持人员的帮助,您无法降级部署的二进制版本。

To learn more, see Downgrade 8.2 to 8.0.要了解更多信息,请参阅降级8.2到8.0

Prerequisites先决条件

All Members Version所有成员版本

To upgrade a sharded cluster to 8.2, all members of the cluster must be at least version 8.0. The upgrade process checks all components of the cluster and will produce warnings if any component is running version earlier than 8.0.要将分片集群升级到8.2,集群的所有成员必须至少为8.0版本。升级过程会检查集群的所有组件,如果任何组件运行的版本早于8.0,则会产生警告。

Feature Compatibility Version功能兼容性版本

The 8.0 sharded cluster must have featureCompatibilityVersion set to "8.0".8.0分片集群的featureCompatibilityVersion必须设置为"8.0"

To ensure that all members of the sharded cluster have featureCompatibilityVersion set to "8.0", connect to each shard replica set member and each config server replica set member and check the featureCompatibilityVersion:为确保分片集群的所有成员都将featureCompatibilityVersion设置为"8.0",请连接到每个分片副本集成员和每个配置服务器副本集成员,并检查featureCompatibilityVersion

Tip

For a sharded cluster that has access control enabled, to run the following command against a shard replica set member, you must connect to the member as a shard local user.对于启用了访问控制的分片集群,要对分片副本集成员运行以下命令,您必须以分片本地用户的身份连接到该成员。

db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )

All members should return a result that includes "featureCompatibilityVersion" : { "version" : "8.0" }.所有成员都应返回包含"featureCompatibilityVersion" : { "version" : "8.0" }的结果。

To set or update featureCompatibilityVersion, run the following command on the mongos:要设置或更新featureCompatibilityVersion,请在mongos上运行以下命令:

db.adminCommand( { setFeatureCompatibilityVersion: "8.0", confirm: true } )

For more information, see setFeatureCompatibilityVersion.有关更多信息,请参阅setFeatureCompatibilityVersion

Replica Set Member State副本集成员状态

For shards and config servers, ensure that no replica set member is in the ROLLBACK or RECOVERING state.对于分片和配置服务器,请确保没有副本集成员处于ROLLBACKRECOVERING状态。

db.adminCommand( { replSetGetStatus: 1 } )

Back up the config Database备份config数据库

Optional but Recommended.可选,但推荐。 As a precaution, take a backup of the config database before upgrading the sharded cluster.作为预防措施,在升级分片集群之前,请备份config数据库。

Remove Invalid system.buckets Collections删除无效的system.buckets集合

When you upgrade to 8.3, if you have any system.buckets collections that are not time-series collections, you might need to drop or rename those collections before you upgrade, depending on your 8.0 patch release:升级到8.3时,如果您有任何不是时间序列集合的system.buckets集合,则可能需要在升级之前drop(丢弃)或rename(重命名)这些集合,具体取决于您的8.0补丁版本:

MongoDB 8.0.5 and laterMongoDB 8.0.5及更高版本
You do not need to drop system.buckets collections that aren't time-series collections before you upgrade. However, you must drop or rename them after you complete your upgrade.在升级之前,您不需要删除非时间序列集合的system.buckets集合。但是,您必须在完成升级后删除或重命名它们。
MongoDB 8.0.4 and earlierMongoDB 8.0.4及更早版本
You must drop or rename system.buckets collections that aren't time-series collections before you upgrade. 在升级之前,您必须删除或重命名非时间序列集合的system.buckets集合。All system.buckets collections must have valid time series options configured before you upgrade to versions 8.0.0 - 8.0.4.在升级到版本8.0.0-8.0.4之前,所有system.buckets集合都必须配置有效的时间序列选项

To determine whether you have system.buckets collections that are not time-series collections, use the db.getCollectionInfos() method with a filter:要确定是否有非时间序列集合的system.buckets集合,请使用带有筛选器的db.getCollectionInfos()方法:

db.getCollectionInfos(
{
$and: [
{ name: { $regex: /^system\.buckets/ } },
{ 'options.timeseries': { $exists: false } }
]
}
)

Download 8.2 Binaries下载8.2二进制文件

Use Package Manager使用包管理器

If you installed MongoDB from the MongoDB apt, yum, dnf, or zypper repositories, you should upgrade to 8.2 using your package manager.如果你从MongoDB aptyumdnfzypper存储库安装了MongoDB,你应该使用包管理器升级到8.2。

Follow the appropriate 8.2 installation instructions for your Linux system. This will involve adding a repository for the new release, then performing the actual upgrade process.按照适用于您的Linux系统的8.2安装说明进行操作。这将涉及为新版本添加一个存储库,然后执行实际的升级过程。

Download 8.2 Binaries Manually手动下载8.2二进制文件

If you have not installed MongoDB using a package manager, you can manually download the MongoDB binaries from the MongoDB Download Center.如果你没有使用包管理器安装MongoDB,你可以从MongoDB下载中心手动下载MongoDB二进制文件。

See 8.2 installation instructions for more information.有关更多信息,请参阅8.2安装说明

Upgrade Procedure升级程序

1

Disable the Balancer.禁用平衡器。

Connect mongosh to a mongos instance in the sharded cluster, and run sh.stopBalancer() to disable the balancer:mongosh连接到分片集群中的mongos实例,并运行sh.stopBalancer()以禁用平衡器:

sh.stopBalancer()

Note

If a migration is in progress, the system will complete the in-progress migration before stopping the balancer. You can run sh.isBalancerRunning() to check the balancer's current state.如果正在进行迁移,系统将在停止平衡器之前完成正在进行的迁移。您可以运行sh.isBalancerRunning()来检查平衡器的当前状态。

To verify that the balancer is disabled, run sh.getBalancerState(), which returns false if the balancer is disabled:要验证平衡器是否已禁用,请运行sh.getBalancerState(),如果平衡器已禁用,则返回false

sh.getBalancerState()

For more information on disabling the balancer, see Disable the Balancer.有关禁用平衡器的更多信息,请参阅禁用平衡器

2

Upgrade the config servers.升级配置服务器。

  1. Upgrade the secondary members of the replica set, one at a time.一次升级一个副本集的secondary成员。

    1. Shut down the secondary instance.关闭辅助实例。

      To shut down the mongod process, use mongosh to connect to the cluster member and run the following command:要关闭mongod进程,请使用mongosh连接到集群成员并运行以下命令:

      db.adminCommand( { shutdown: 1 } )
    2. Replace the 8.0 binary with the 8.2 binary.将8.0二进制替换为8.2二进制。
    3. Start the 8.2 binary.启动8.2二进制文件。

      Start the 8.2 binary with the --configsvr, --replSet, and --port. Include any other options as used by the deployment.使用--configsvr--replSet--port启动8.2二进制文件。包括部署使用的任何其他选项。

      mongod --configsvr --replSet <replSetName> --port <port> --dbpath <path> --bind_ip localhost,<ip address>

      If using a configuration file, update the file to specify sharding.clusterRole: configsvr, replication.replSetName, net.port, and net.bindIp, then start the 8.2 binary:如果使用配置文件,请更新该文件以指定sharding.clusterRole: configsvrreplication.replSetNamenet.portnet.bindIp,然后启动8.2二进制文件:

      sharding:
      clusterRole: configsvr
      replication:
      replSetName: <string>
      net:
      port: <port>
      bindIp: localhost,<ip address>
      storage:
      dbpath: <path>

      Include any other settings as appropriate for your deployment.根据部署情况,包括任何其他设置。

    4. Wait for the member to recover to the SECONDARY state before upgrading the next secondary member.在升级下一个辅助成员之前,请等待成员恢复到SECONDARY状态。

      To check the member's state, issue rs.status() in mongosh.要检查成员的状态,请mongosh用发出rs.status()

  2. Step down the replica set primary.逐步关闭primary副本集。

    1. Connect mongosh to the primary and use rs.stepDown() to step down the primary and force an election of a new primary:mongosh连接到primary,并使用rs.stepDown()退出primary并强制选举新的primary:

      rs.stepDown()
    2. Shut down the stepped-down primary.关闭已降级的小学。

      When rs.status() shows that the primary has stepped down and another member has assumed the PRIMARY state, shut down the stepped-down primary.rs.status()显示primary服务器已降级,另一个成员已处于PRIMARY状态时,关闭已降级的primary服务器。

      To shut down the stepped-down primary, use mongosh to connect to the primary and run the following command:要关闭已降级的主服务器,请使用mongosh连接到主服务器并运行以下命令:

      db.adminCommand( { shutdown: 1 } )
    3. Replace the mongod binary with the 8.2 binary.mongod二进制文件替换为8.2二进制文件。
    4. Start the 8.2 binary.启动8.2二进制文件。

      Start the 8.2 with the --configsvr, --replSet, --port, and --bind_ip options. 使用--configsvr--replSet--port--bind_ip选项启动8.2。Include any optional command line options used by the previous deployment:包括以前部署使用的任何可选命令行选项:

      mongod --configsvr --replSet <replSetName> --port <port> --dbpath <path> --bind_ip localhost,<ip address>

      If using a configuration file, update the file to specify sharding.clusterRole: configsvr, replication.replSetName, net.port, and net.bindIp, then start the 8.2 binary:如果使用配置文件,请更新该文件以指定sharding.clusterRole: configsvrreplication.replSetNamenet.portnet.bindIp,然后启动8.2二进制文件:

      sharding:
      clusterRole: configsvr
      replication:
      replSetName: <string>
      net:
      port: <port>
      bindIp: localhost,<ip address>
      storage:
      dbpath: <path>

      Include any other configuration as appropriate for your deployment.包括适合您部署的任何其他配置。

3

Upgrade the shards.升级分片。

Upgrade the shards one at a time.一次升级一个分片。

For each shard replica set:对于每个分片副本集:

  1. Upgrade the secondary members of the replica set, one at a time.一次升级一个副本集的secondary成员。

    1. Shut down the secondary instance.关闭辅助实例。

      To shut down the mongod process, use mongosh to connect to the cluster member and run the following command:要关闭mongod进程,请使用mongosh连接到集群成员并运行以下命令:

      db.adminCommand( { shutdown: 1 } )
    2. Replace the 8.0 binary with the 8.2 binary.将8.0二进制替换为8.2二进制。

      Start the 8.2 binary with the --shardsvr, --replSet, --port, and --bind_ip options. Include any additional command line options as appropriate for your deployment:使用--shardsvr--replSet--port--bind_ip选项启动8.2二进制文件。根据部署情况,包括任何其他命令行选项:

      mongod --shardsvr --replSet <replSetName> --port <port> --dbpath <path> --bind_ip localhost,<ip address>

      If using a configuration file, update the file to include sharding.clusterRole: shardsvr, replication.replSetName, net.port, and net.bindIp, then start the 8.2 binary:如果使用配置文件,请更新该文件以包含sharding.clusterRole: shardsvrreplication.replSetNamenet.portnet.bindIp,然后启动8.2二进制文件:

      sharding:
      clusterRole: shardsvr
      replication:
      replSetName: <string>
      net:
      port: <port>
      bindIp: localhost,<ip address>
      storage:
      dbpath: <path>

      Include any other configuration as appropriate for your deployment.包括适合您部署的任何其他配置。

    3. Wait for the member to recover to the SECONDARY state before upgrading the next secondary member.在升级下一个辅助成员之前,请等待成员恢复到SECONDARY状态。

      To check the member's state, you can issue rs.status() in mongosh.要检查成员的状态,您可以在mongosh中发出rs.status()

    4. Repeat for each secondary member.对每个次要成员重复此操作。
  2. Step down the replica set primary.逐步关闭primary副本集。

    Connect mongosh to the primary and use rs.stepDown() to step down the primary and force an election of a new primary:mongosh连接到primary,并使用rs.stepDown()退出primary并强制选举新的primary:

    rs.stepDown()
  3. Upgrade the stepped-down primary.升级已降级的primary。

    When rs.status() shows that the primary has stepped down and another member has assumed the PRIMARY state, upgrade the stepped-down primary:rs.status()显示primary已降级,另一个成员已处于PRIMARY状态时,升级降级的primary:

    1. Shut down the stepped-down primary.关闭已降级的primary。

      To shut down the stepped-down primary, use mongosh to connect to the replica set member and run the following command:要关闭已降级的primary,请使用mongosh连接到副本集成员并运行以下命令:

      db.adminCommand( { shutdown: 1 } )
    2. Replace the mongod binary. with the 8.2 binary.替换mongod二进制文件。使用8.2二进制。
    3. Start the 8.2 binary.启动8.2二进制文件。

      Start the 8.2 binary with the --shardsvr, --replSet, --port, and --bind_ip options. Include any additional command line options as appropriate for your deployment:使用--shardsvr--replSet--port--bind_ip选项启动8.2二进制文件。根据部署情况,包括任何其他命令行选项:

      mongod --shardsvr --replSet <replSetName> --port <port> --dbpath <path> --bind_ip localhost,<ip address>

      If using a configuration file, update the file to specify sharding.clusterRole: shardsvr, replication.replSetName, net.port, and net.bindIp, then start the 8.2 binary:如果使用配置文件,请更新该文件以指定sharding.clusterRole: shardsvrreplication.replSetNamenet.portnet.bindIp,然后启动8.2二进制文件:

      sharding:
      clusterRole: shardsvr
      replication:
      replSetName: <string>
      net:
      port: <port>
      bindIp: localhost,<ip address>
      storage:
      dbpath: <path>

      Include any other configuration as appropriate for your deployment.包括适合您部署的任何其他配置。

4

Upgrade the mongos instances.升级mongos实例。

Replace each mongos instance with the 8.2 binary and restart. Include any other configuration as appropriate for your deployment.将每个mongos实例替换为8.2二进制文件并重新启动。包括适合您部署的任何其他配置。

Note

The --bind_ip option must be specified when the sharded cluster members are run on different hosts or if remote clients connect to the sharded cluster.当分片群集成员在不同主机上运行或远程客户端连接到分片群集时,必须指定--bind_ip选项。

mongos --configdb csReplSet/<rsconfigsver1:port1>,<rsconfigsver2:port2>,<rsconfigsver3:port3> --bind_ip localhost,<ip address>
5

Re-enable the balancer.重新启用平衡器。

Using mongosh, connect to a mongos in the cluster and run sh.startBalancer() to re-enable the balancer:使用mongosh,连接到集群中的mongos并运行sh.startBalancer()以重新启用平衡器:

sh.startBalancer()

For more information about re-enabling the balancer, see Enable the Balancer.有关重新启用平衡器的更多信息,请参阅启用平衡器

6

Enable backwards-incompatible 8.2 features.启用向后不兼容的8.2功能。

At this point, you can run the 8.2 binaries without the 8.2 features that are incompatible with 8.0.此时,您可以运行8.2二进制文件,而不需要与8.0不兼容的8.2功能

To enable these 8.2 features, set the feature compatibility version (FCV) to 8.2. You must also set confirm to true if upgrading to 7.0 or later.要启用这些8.2功能,请将功能兼容性版本(FCV)设置为8.2。如果升级到7.0或更高版本,您还必须将confirm设置为true

Tip

Enabling these backwards-incompatible features can complicate the downgrade process since you must remove any persisted backwards-incompatible features before you downgrade.启用这些向后不兼容的功能可能会使降级过程复杂化,因为在降级之前必须删除任何持久的向后不兼容功能。

It is recommended that after upgrading, you allow your deployment to run without enabling these features for a burn-in period to ensure the likelihood of downgrade is minimal. When you are confident that the likelihood of downgrade is minimal, enable these features.建议升级后,在老化期内允许部署在不启用这些功能的情况下运行,以确保降级的可能性最小。当您确信降级的可能性很小时,启用这些功能。

On a mongos instance, run the setFeatureCompatibilityVersion command in the admin database:mongos实例上,在admin数据库中运行setFeatureCompatibilityVersion命令:

db.adminCommand( { setFeatureCompatibilityVersion: "8.2", confirm: true } )

Setting featureCompatibilityVersion (FCV) : "8.2" implicitly performs a replSetReconfig on each shard to add the term field to the shard replica configuration document.设置featureCompatibilityVersion (FCV) : "8.2"隐式地对每个分片执行replSetReconfig,以将term字段添加到分片副本配置文档中。

The command doesn't complete until the new configuration propagates to a majority of replica set members.在新配置传播到大多数副本集成员之前,该命令不会完成。

This command must perform writes to an internal system collection. If for any reason the command does not complete successfully, you can safely retry the command on the mongos as the operation is idempotent.此命令必须对内部系统集合执行写入操作。如果由于任何原因命令没有成功完成,您可以在mongos上安全地重试该命令,因为该操作是幂等的。

Note

While setFeatureCompatibilityVersion is running on the sharded cluster, chunk migrations, splits, and merges can fail with ConflictingOperationInProgress.setFeatureCompatibilityVersion在分片集群上运行时,块迁移、拆分和合并可能会因ConflictingOperationInProgress而失败。

Any orphaned documents that exist on your shards will be cleaned up when you set the setFeatureCompatibilityVersion to 8.2. The cleanup process:当您将setFeatureCompatibilityVersion设置为8.2时,分片上存在的任何孤立文档都将被清理。清理过程:

  • Does not block the upgrade from completing, and不会阻止升级完成,以及
  • Is rate limited. To mitigate the potential effect on performance during orphaned document cleanup, see Range Deletion Performance Tuning.价格有限。要减轻孤立文档清理过程中对性能的潜在影响,请参阅范围删除性能调整

Warning

mongos FCV Compatibility兼容性

The mongos binary cannot connect to mongod instances whose feature compatibility version (FCV) is greater than that of the mongos. mongos二进制文件无法连接到功能兼容性版本(FCV)大于mongosmongod实例。For example, you cannot connect a MongoDB 8.0 version mongos to a 8.2 sharded cluster with FCV set to 8.2. 例如,您无法将MongoDB 8.0版本的mongos连接到FCV设置为8.2的8.2分片集群。You can, however, connect a MongoDB 8.0 version mongos to a 8.2 sharded cluster with FCV set to 8.0.但是,您可以将MongoDB 8.0版本的mongos连接到FCV设置为8.0的8.2分片集群。

Additional Upgrade Procedures其他升级程序