Aurora MySQL 就地升级教程 - Amazon Aurora

Aurora MySQL 就地升级教程

以下 Linux 示例展示了如何使用 AWS CLI 执行就地升级过程的一般步骤。

第一个示例创建了运行 Aurora MySQL 版本 2.x 的 Aurora 数据库集群。该集群包括写入器数据库实例和读取器数据库实例。wait db-instance-available 命令会暂停,直到写入器数据库实例可用。此时,集群做好升级准备。

aws rds create-db-cluster --db-cluster-identifier mynewdbcluster --engine aurora-mysql \ --db-cluster-version 5.7.mysql_aurora.2.10.2 ... aws rds create-db-instance --db-instance-identifier mynewdbcluster-instance1 \ --db-cluster-identifier mynewdbcluster --db-instance-class db.t4g.medium --engine aurora-mysql ... aws rds wait db-instance-available --db-instance-identifier mynewdbcluster-instance1

您可以将集群升级到的 Aurora MySQL 3.x 版本取决于集群当前正在运行的 2.x 版本和集群所在的 AWS 区域。第一个命令(带 --output text)只显示可用的目标版本。第二个命令显示响应的完整 JSON 输出。在该响应中,您可以看到详细信息,例如您用于 engine 参数的 aurora-mysql 值。您还可以看到这样一个事实,即升级到 3.02.0 表示主要版本升级。

aws rds describe-db-clusters --db-cluster-identifier mynewdbcluster \ --query '*[].{EngineVersion:EngineVersion}' --output text 5.7.mysql_aurora.2.10.2 aws rds describe-db-engine-versions --engine aurora-mysql --engine-version 5.7.mysql_aurora.2.10.2 \ --query '*[].[ValidUpgradeTarget]' ... { "Engine": "aurora-mysql", "EngineVersion": "8.0.mysql_aurora.3.02.0", "Description": "Aurora MySQL 3.02.0 (compatible with MySQL 8.0.23)", "AutoUpgrade": false, "IsMajorVersionUpgrade": true, "SupportedEngineModes": [ "provisioned" ], "SupportsParallelQuery": true, "SupportsGlobalDatabases": true, "SupportsBabelfish": false }, ...

此示例表示,如果您输入的目标版本号不是集群的有效升级目标,Aurora 不会执行升级。Aurora 也不会执行主要版本升级,除非您包含 --allow-major-version-upgrade 参数。这样一来,您就不能意外执行有可能需要大量测试和更改应用程序代码的升级。

aws rds modify-db-cluster --db-cluster-identifier mynewdbcluster \ --engine-version 5.7.mysql_aurora.2.09.2 --apply-immediately An error occurred (InvalidParameterCombination) when calling the ModifyDBCluster operation: Cannot find upgrade target from 5.7.mysql_aurora.2.10.2 with requested version 5.7.mysql_aurora.2.09.2. aws rds modify-db-cluster --db-cluster-identifier mynewdbcluster \ --engine-version 8.0.mysql_aurora.3.02.0 --region us-east-1 --apply-immediately An error occurred (InvalidParameterCombination) when calling the ModifyDBCluster operation: The AllowMajorVersionUpgrade flag must be present when upgrading to a new major version. aws rds modify-db-cluster --db-cluster-identifier mynewdbcluster \ --engine-version 8.0.mysql_aurora.3.02.0 --apply-immediately --allow-major-version-upgrade { "DBClusterIdentifier": "mynewdbcluster", "Status": "available", "Engine": "aurora-mysql", "EngineVersion": "5.7.mysql_aurora.2.10.2" }

集群和关联数据库实例的状态需要一段时间才能更改为 upgrading。集群和数据库实例的版本号仅在升级完成后才会更改。同样,您可以使用 wait db-instance-available 命令让写入器数据库实例等到升级完成后再继续。

aws rds describe-db-clusters --db-cluster-identifier mynewdbcluster \ --query '*[].[Status,EngineVersion]' --output text upgrading 5.7.mysql_aurora.2.10.2 aws rds describe-db-instances --db-instance-identifier mynewdbcluster-instance1 \ --query '*[].{DBInstanceIdentifier:DBInstanceIdentifier,DBInstanceStatus:DBInstanceStatus} | [0]' { "DBInstanceIdentifier": "mynewdbcluster-instance1", "DBInstanceStatus": "upgrading" } aws rds wait db-instance-available --db-instance-identifier mynewdbcluster-instance1

此时,集群的版本号与为升级指定的版本号匹配。

aws rds describe-db-clusters --db-cluster-identifier mynewdbcluster \ --query '*[].[EngineVersion]' --output text 8.0.mysql_aurora.3.02.0

前面的示例通过指定 --apply-immediately 参数进行了立即升级。为了让升级在集群预计不繁忙的方便之时进行,您可以指定 --no-apply-immediately 参数。这样做可以在集群的下一个维护时段内启动升级。维护时段定义了可以启动维护操作的时间段。在维护时段内,长时间运行的操作可能无法完成。因此,即使您预计升级可能需要很长时间,也不需要定义更大的维护时段。

以下示例升级最初运行 Aurora MySQL 版本 2.10.2 的集群。在 describe-db-engine-versions 输出中,FalseTrue 值表示 IsMajorVersionUpgrade 属性。您可以从版本 2.10.2 升级到一些其他 2.* 版本。这些升级不被视为主要版本升级,因此不需要就地升级。就地升级仅适用于升级到列表中显示的 3.* 版本。

aws rds describe-db-clusters --db-cluster-identifier mynewdbcluster \ --query '*[].{EngineVersion:EngineVersion}' --output text 5.7.mysql_aurora.2.10.2 aws rds describe-db-engine-versions --engine aurora-mysql --engine-version 5.7.mysql_aurora.2.10.2 \ --query '*[].[ValidUpgradeTarget]|[0][0]|[*].[EngineVersion,IsMajorVersionUpgrade]' --output text 5.7.mysql_aurora.2.10.3 False 5.7.mysql_aurora.2.11.0 False 5.7.mysql_aurora.2.11.1 False 8.0.mysql_aurora.3.01.1 True 8.0.mysql_aurora.3.02.0 True 8.0.mysql_aurora.3.02.2 True aws rds modify-db-cluster --db-cluster-identifier mynewdbcluster \ --engine-version 8.0.mysql_aurora.3.02.0 --no-apply-immediately --allow-major-version-upgrade ...

如果在没有指定的维护时段的情况下创建集群,Aurora 会随机选择一周中的一天。在这种情况下,modify-db-cluster 命令将在星期一提交。因此,我们将维护时段更改为星期二早上。所有时间都以 UTC 时区表示。tue:10:00-tue:10:30 时段对应于太平洋时间凌晨 2:00-2:30。维护时段的更改会立即生效。

aws rds describe-db-clusters --db-cluster-identifier mynewdbcluster --query '*[].[PreferredMaintenanceWindow]' [ [ "sat:08:20-sat:08:50" ] ] aws rds modify-db-cluster --db-cluster-identifier mynewdbcluster --preferred-maintenance-window tue:10:00-tue:10:30" aws rds describe-db-clusters --db-cluster-identifier mynewdbcluster --query '*[].[PreferredMaintenanceWindow]' [ [ "tue:10:00-tue:10:30" ] ]

以下示例说明如何获取升级所生成的事件的报告。--duration 参数表示检索事件信息的分钟数。系统需要此参数,因为默认情况下,describe-events 仅返回最后一个小时的事件。

aws rds describe-events --source-type db-cluster --source-identifier mynewdbcluster --duration 20160 { "Events": [ { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "DB cluster created", "EventCategories": [ "creation" ], "Date": "2022-11-17T01:24:11.093000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Upgrade in progress: Performing online pre-upgrade checks.", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T22:57:08.450000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Upgrade in progress: Performing offline pre-upgrade checks.", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T22:57:59.519000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Upgrade in progress: Creating pre-upgrade snapshot [preupgrade-mynewdbcluster-5-7-mysql-aurora-2-10-2-to-8-0-mysql-aurora-3-02-0-2022-11-18-22-55].", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T23:00:22.318000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Upgrade in progress: Cloning volume.", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T23:01:45.428000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Upgrade in progress: Purging undo records for old row versions. Records remaining: 164", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T23:02:25.141000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Upgrade in progress: Purging undo records for old row versions. Records remaining: 164", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T23:06:23.036000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Upgrade in progress: Upgrading database objects.", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T23:06:48.208000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Database cluster major version has been upgraded", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T23:10:28.999000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" } ] }