MySQL Shell 9.0  /  ...  /  InnoDB 集群升级

7.10.1 InnoDB 集群升级

要升级 InnoDB 集群中的服务器实例,请完成以下步骤

检查已安装二进制文件的版本

  • mysqlrouter --version: 检查已安装的 MySQL Router 版本。

  • mysqlsh --version: 检查已安装的 MySQL Shell 版本。

  • mysqld --version: 检查已安装的 MySQL Server 版本。

升级 MySQL Router。

要升级 MySQL Router,请完成以下步骤

  1. 停止 MySQL Router。

    在 Unix 系统上,如果您使用了可选的 --directory 引导选项,则会创建一个自包含的安装,其中所有生成的目录和文件都位于您在 引导 路由器时选择的目录中。这些文件包括 stop.sh。导航到此目录并发出以下命令

    Press CTRL+C to copy
    ./stop.sh

    在 Microsoft Windows 上,如果您使用了可选的 --directory 引导选项,则会创建一个自包含的安装,其中所有生成的目录和文件都位于您在 引导 路由器时选择的目录中。这些文件包括 stop.ps1。导航到此目录并发出以下命令

    Press CTRL+C to copy
    .\stop.ps1

    或者在使用 systemd 的 Linux 系统上,通过发出以下命令停止 MySQL Router 服务

    Press CTRL+C to copy
    systemctl stop mysqlrouter.service

    否则,请终止相关 mysqlrouter 进程的 进程 ID (PID)

  2. 获取并安装 最新版本的 MySQL Router。

  3. 启动 MySQL Router。

    在 Unix 系统上,如果您使用了可选的 --directory 引导选项,则会创建一个自包含的安装,其中所有生成的目录和文件都位于您选择的目录中。这些文件包括 start.sh。导航到目录并发出以下命令

    Press CTRL+C to copy
    ./start.sh

    如果新路由器路径已更改,您必须更新 start.sh shell 脚本以反映该路径。

    Press CTRL+C to copy
    #!/bin/bash basedir=/tmp/myrouter ROUTER_PID=$basedir/mysqlrouter.pid /usr/bin/mysqlrouter -c $basedir/mysqlrouter.conf & disown %-

    如果您手动升级 MySQL Router,而不是使用包管理,则可以更新 basedir=。如果您再次引导路由器,则会重新生成 start.sh shell 脚本。

    或者在使用 systemd 的 Linux 系统上,通过发出以下命令启动 MySQL Router 服务

    Press CTRL+C to copy
    systemctl start mysqlrouter.service

    在 Microsoft Windows 上,如果您使用了可选的 --directory 引导选项,则会创建一个自包含的安装,其中所有生成的目录和文件都位于您选择的目录中。这些文件包括 start.ps1。导航到目录并发出以下命令

    Press CTRL+C to copy
    .\start.ps1

    在使用新的路由器二进制文件启动 MySQL Router 时,通过发出以下命令检查路由器版本是否已升级

    Press CTRL+C to copy
    mysqlrouter --version

升级 MySQL Shell

通过安装新的二进制文件,并停止和启动 MySQL Shell 来升级 MySQL Shell

  1. 获取并安装 最新版本的 MySQL Shell。

  2. 通过发出以下命令停止并退出 MySQL Shell

    Press CTRL+C to copy
    \q
  3. 从命令行重新启动 MySQL Shell,通过发出以下命令

    Press CTRL+C to copy
    mysqlsh
  4. 升级 InnoDB 集群元数据

    • 要升级 InnoDB 集群的元数据,请将 MySQL Shell 的全局会话连接到您的集群,并使用 dba.upgradeMetadata() 操作将集群的元数据升级到新元数据。

    元数据升级

    如果集群已使用最新版本,则元数据升级可能不会执行任何操作。

升级 MySQL 服务器

通过在升级主实例之前升级所有辅助实例来升级 MySQL 服务器。

升级 MySQL 服务器是可选的

升级 MySQL 服务器是可选的。服务器升级可能比升级 MySQL Shell 和 MySQL Router 影响更大。此外,即使服务器未升级,也应始终将 MySQL Shell 和 MySQL Router 保持在最新版本;这对 InnoDB 集群和副本集来说都是如此。

  1. 通过发出以下命令之一停止 MySQL 服务器

    • 如果 MySQL 服务器使用的是 systemd,请发出以下命令

      Press CTRL+C to copy
      systemctl stop mysqld
    • 如果 MySQL 服务器使用的是 init.d,请发出以下命令

      Press CTRL+C to copy
      /etc/init.d/mysql stop
    • 如果 MySQL 服务器使用的是 service,请发出以下命令

      Press CTRL+C to copy
      service mysql stop
    • 如果您在 Microsoft Windows 上部署了 MySQL 服务器,请发出以下命令

      Press CTRL+C to copy
      mysqladmin -u root -p shutdown
  2. 获取并安装 最新版本的 MySQL Server。

  3. 通过发出以下命令之一启动 MySQL Server

    • 如果 MySQL 服务器使用的是 systemd,请发出以下命令

      Press CTRL+C to copy
      systemctl start mysqld
    • 如果 MySQL 服务器使用的是 init.d,请发出以下命令

      Press CTRL+C to copy
      /etc/init.d/mysql start
    • 如果 MySQL 服务器使用的是 service,请发出以下命令

      Press CTRL+C to copy
      service mysql start
    • 如果您在 Microsoft Windows 上部署了 MySQL 服务器,请发出以下命令

      Press CTRL+C to copy
      mysqld
  4. 当所有辅助实例都升级后,升级主实例以完成升级过程。

升级后状态检查

升级 MySQL Router、MySQL Shell 和 MySQL Server 后

  1. 检查集群,通过发出 <Cluster>.status()。有关 <Cluster>.status() 的更多信息,请参阅 使用 Cluster.status() 检查集群的状态

  2. 解决 clusterErrorsstatusText 返回的任何错误,这些错误是由 <Cluster>.status() 操作返回的。

这些命令使您可以检查升级是否成功,或者您是否需要完成任何其他步骤。

注意

其他步骤取决于您跳过的版本数量、要升级的版本以及您要升级的版本。

  1. 通过发出 <Cluster>.status() 检查每个 InnoDB 集群的状态。

    在以下示例中,<Cluster>.status({extended: true}) 用于提供有关集群状态的更详细的信息,它返回两个问题

    Press CTRL+C to copy
    mysqlsh> <Cluster>.status({extended: true}); { "clusterName": "MyCluster", "defaultReplicaSet": { "GRProtocolVersion": "8.0.16", "groupName": "459ec434-8926-11ec-b8c3-02001707f44a", "groupViewChangeUuid": "AUTOMATIC", "groupViewId": "16443558036060755:13", "name": "default", "ssl": "REQUIRED", "status": "OK", "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.", "topology": { "example-el7-1644251369:33311": { "address": "example-el7-1644251369:33311", "applierWorkerThreads": 4, "fenceSysVars": [], "instanceErrors": [ "NOTE: instance server_id is not registered in the metadata. Use cluster.rescan() to update the metadata.", "NOTE: The required parallel-appliers settings are not enabled on the instance. Use dba.configureInstance() to fix it." ], "memberId": "247131ab-8926-11ec-850b-02001707f44a", "memberRole": "PRIMARY", "memberState": "ONLINE", "mode": "R/W", "readReplicas": {}, "replicationLag": null, "role": "HA", "status": "ONLINE", "version": "8.0.28" }, "example-el7-1644251369:33314": { "address": "example-el7-1644251369:33314", "applierWorkerThreads": 4, "fenceSysVars": [], "instanceErrors": [ "NOTE: instance server_id is not registered in the metadata. Use cluster.rescan() to update the metadata.", "NOTE: The required parallel-appliers settings are not enabled on the instance. Use dba.configureInstance() to fix it." ], "memberId": "303dcfa7-8926-11ec-a6e5-02001707f44a", "memberRole": "PRIMARY", "memberState": "ONLINE", "mode": "R/W", "readReplicas": {}, "replicationLag": null, "role": "HA", "status": "ONLINE", "version": "8.0.28" }, "example-el7-1644251369:33317": { "address": "example-el7-1644251369:33317", "applierWorkerThreads": 4, "fenceSysVars": [], "instanceErrors": [ "NOTE: instance server_id is not registered in the metadata. Use cluster.rescan() to update the metadata.", "NOTE: The required parallel-appliers settings are not enabled on the instance. Use dba.configureInstance() to fix it." ], "memberId": "3bb2592e-8926-11ec-8b6f-02001707f44a", "memberRole": "PRIMARY", "memberState": "ONLINE", "mode": "R/W", "readReplicas": {}, "replicationLag": null, "role": "HA", "status": "ONLINE", "version": "8.0.28" } }, "topologyMode": "Multi-Primary" }, "groupInformationSourceMember": "example-el7-1644251369:33311", "metadataVersion": "2.1.0" }

    <Cluster>.status({extended: true}) 显示有关集群的更详细信息。在此示例中,我们使用布尔值 true,它等效于 <Cluster>.status({'extended':1})。有关更多信息,请参阅 使用 Cluster.status() 检查集群的状态

  2. 解决 <Cluster>.status({extended:1}) 操作返回的任何错误。

    在此示例中,instanceErrors 表明在此升级中,我们应该对集群中的每个成员发出 <Cluster>.rescan()dba.configureInstance()

    Press CTRL+C to copy
    ... "NOTE: instance server_id is not registered in the metadata. Use <Cluster>.rescan() to update the metadata.", "NOTE: The required parallel-appliers settings are not enabled on the instance. Use dba.configureInstance() to fix it." ...

    <Cluster>.rescan() 操作使您能够重新扫描集群以查找新的和过时的群组复制实例,以及使用的拓扑模式中的更改。有关更多信息,请参阅 重新扫描集群

    Press CTRL+C to copy
    mysqlsh> <Cluster>.rescan(); Rescanning the cluster... Result of the rescanning operation for the 'MyCluster1' cluster: { "name": "MyCluster1", "newTopologyMode": null, "newlyDiscoveredInstances": [], "unavailableInstances": [], "updatedInstances": [] }

    dba.configureInstance() 函数检查启用实例以供 InnoDB 集群使用所需的所有设置。有关更多信息,请参阅 配置生产实例以供 InnoDB 集群使用

    在此示例中,我们在 InnoDB 集群中的每个成员上发出 dba.configureInstance(),以确保实例上启用了所需的并行应用器设置

    Press CTRL+C to copy
    mysqlsh> dba.configureInstance('cladmin:cladminpw@localhost:33311') The instance 'example-el7-1644251369:33311' belongs to an InnoDB Cluster. Configuring local MySQL instance listening at port 33311 for use in an InnoDB cluster... This instance reports its own address as ^[[1mexample-el7-1644251369:33311^[[0m Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQL system variable should be changed. applierWorkerThreads will be set to the default value of 4. ^[[36mNOTE: ^[[0mSome configuration options need to be fixed: +----------------------------------------+---------------+----------------+----------------------------+ | Variable | Current Value | Required Value | Note | +----------------------------------------+---------------+----------------+----------------------------+ | binlog_transaction_dependency_tracking | COMMIT_ORDER | WRITESET | Update the server variable | +----------------------------------------+---------------+----------------+----------------------------+ Configuring instance... The instance 'example-el7-1644251369:33311' was configured to be used in an InnoDB cluster.

有关集群升级故障排除的信息,请参阅 InnoDB 集群升级故障排除