使用 DR Orchestrator 框架自动执行跨区域故障转移和故障恢复 - AWS Prescriptive Guidance

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 DR Orchestrator 框架自动执行跨区域故障转移和故障恢复

由 Jitendra Kumar (AWS)、Oliver Francis () 和 Pavithra Balasubramanian (AWS) 创作 AWS

摘要

此模式描述了如何使用 DR Orchestrator 框架来编排和自动执行容易出错的手动步骤,以便在 Amazon Web Services () 区域执行灾难恢复。AWS该模式涵盖以下数据库:

  • 我的亚马逊关系数据库服务(亚马逊RDS)、Postgre RDS SQL 的亚马逊SQL、MariaDB RDS 的亚马逊

  • 亚马逊 Aurora 我的SQL兼容版或亚马逊 Aurora Postgre SQL-兼容版(使用集中式文件)

  • 亚马逊 ElastiCache (RedisOSS)

为了演示 DR Orchestrator Framework 的功能,您需要创建两个数据库实例或集群。主节点在中 AWS 区域 us-east-1,次要在中us-west-2。要创建这些资源,您可以使用 aws-cross-region-dr-databases GitHub 存储库App-Stack文件夹中的 AWS CloudFormation 模板。

先决条件和限制

一般先决条件

特定于引擎的先决条件

  • 亚马逊 Aurora — 必须至少有一个 Aurora 全球数据库在两个数据库中可用 AWS 区域。您可以us-east-1用作主要区域,也可以us-west-2用作辅助区域。

  • 亚马逊 ElastiCache (RedisOSS) — ElastiCache 全球数据存储必须分为两部分。 AWS 区域您可以use us-east-1作为主要区域,也可以us-west-2用作辅助区域。

亚马逊的RDS限制

  • DR Orchestrator Framework 在进行故障转移或故障恢复之前不会检查复制延迟。必须手动检查复制延迟。

  • 此解决方案已使用带有一个只读副本的主数据库实例进行了测试。如果要使用多个只读副本,请在生产环境中实施解决方案之前对其进行全面测试。

Aurora 的限制

  • 功能可用性和支持因每个数据库引擎的特定版本和不同版本而异 AWS 区域。有关跨区域复制功能和区域可用性的更多信息,请参阅跨区域只读副本。

  • Aurora 全局数据库对支持的 Aurora 数据库实例类和最大数量有特定的配置要求 AWS 区域。有关更多信息,请参阅 Amazon Aurora 全球数据库的配置要求

  • 此解决方案已使用带有一个只读副本的主数据库实例进行了测试。如果要使用多个只读副本,请在生产环境中实施解决方案之前对其进行全面测试。

ElastiCache 限制

  • 有关全球数据存储的区域可用性和 ElastiCache 配置要求的信息,请参阅 ElastiCache 文档中的先决条件和限制

Amazon RDS p 产品版本

Amazon RDS 支持以下引擎版本:

Aurora 产品版本

  • Amazon Aurora 全球数据库切换需要 Aurora 我的 SQL-兼容我的 SQL 5.7 版本,版本 2.09.1 及更高版本

    有关更多信息,请参阅 Amazon Aurora 全球数据库的限制

ElastiCache (RedisOSS) 产品版本

亚马逊 ElastiCache (RedisOSS) 支持以下 Redis 版本:

  • Redis 7.1(加强版)

  • Redis 7.0(加强版)

  • Redis 6.2(加强版)

  • Redis 6.0(加强版)

  • Redis 5.0.6(加强版)

有关更多信息,请参阅支持的 ElastiCache (RedisOSS) 版本

架构

亚马逊RDS架构

Amazon RDS 架构包括以下资源:

  • 在主区域 (us-east-1) 中创建的主要 Amazon RDS 数据库实例,客户端拥有读/写访问权限

  • 在次要区域 (us-west-2) 中创建的 Amazon 只RDS读副本,客户端具有只读访问权限

  • DR Orchestrator 框架部署在主区域和次要区域

单一AWS账户中的双区域RDS架构示意图。

此图显示以下内容:

  1. 主实例和辅助实例之间的异步复制

  2. 主区域内客户端的读/写访问权限

  3. 次要区域中客户端的只读访问权限

Aurora 架构

亚马逊 Aurora 架构包括以下资源:

  • 在主区域 (us-east-1) 中创建的带有主动写入器终端节点的主要 Aurora 数据库集群

  • 在辅助区域 (us-west-2) 中创建的 Aurora 数据库集群,其终端节点处于非活动状态

  • DR Orchestrator 框架部署在主区域和次要区域

在单个AWS账户中部署双区域 Aurora 的示意图。

此图显示以下内容:

  1. 主群集和辅助群集之间的异步复制

  2. 带有主动写入器终端节点的主数据库集群

  3. 带有非活动写入器终端节点的辅助数据库集群

ElastiCache (RedisOSS) 架构

亚马逊 ElastiCache (RedisOSS) 架构包括以下资源:

  • 由两个集群创建的 ElastiCache (RedisOSS) 全局数据存储:

    1. 主区域中的主集群 (us-east-1)

    2. 辅助区域中的辅助群集 (us-west-2)

  • 两个集群之间具有 TLS 1.2 加密功能的 Amazon 跨区域链接

  • DR Orchestrator 框架已部署在主区域和次要区域

带有 Amazon 跨区域链接的双区域 ElastiCache 部署示意图。

自动化和扩缩

DR Orchestrator Framework 具有可扩展性,并行支持多个 AWS 数据库的故障转移或故障恢复。

您可以使用以下负载代码对账户中的多个 AWS 数据库进行故障切换。在此示例中,三个 AWS 数据库(两个全球数据库,例如 Aurora My Com SQL patible 或 Aurora Postgre SQL 兼容,以及一个 Ama RDS zon for My SQL 实例)故障转移到灾难恢复区域:

{ "StatePayload": [ { "layer": 1, "resources": [ { "resourceType": "PlannedFailoverAurora", "resourceName": "Switchover (planned failover) of Amazon Aurora global databases (MySQL)", "parameters": { "GlobalClusterIdentifier": "!Import dr-globaldb-cluster-mysql-global-identifier", "DBClusterIdentifier": "!Import dr-globaldb-cluster-mysql-cluster-identifier" } }, { "resourceType": "PlannedFailoverAurora", "resourceName": "Switchover (planned failover) of Amazon Aurora global databases (PostgreSQL)", "parameters": { "GlobalClusterIdentifier": "!Import dr-globaldb-cluster-postgres-global-identifier", "DBClusterIdentifier": "!Import dr-globaldb-cluster-postgres-cluster-identifier" } }, { "resourceType": "PromoteRDSReadReplica", "resourceName": "Promote RDS for MySQL Read Replica", "parameters": { "RDSInstanceIdentifier": "!Import rds-mysql-instance-identifier", "TargetClusterIdentifier": "!Import rds-mysql-instance-global-arn" } } ] } ] }

工具

AWS 服务

  • Amazon Aurora 是一款完全托管的关系数据库引擎,专为云而构建,与 My SQL 和 Postgre SQL 兼容。

  • Amazon ElastiCache 可帮助您在中设置、管理和扩展分布式内存缓存环境。 AWS Cloud此模式使用亚马逊 ElastiCache (RedisOSS)。

  • AWS Lambda 是一项计算服务,可帮助您运行代码,无需预置或管理服务器。它仅在需要时运行您的代码,并且能自动扩缩,因此您只需为使用的计算时间付费。在这种模式中,使用 Lambda 函数 AWS Step Functions 来执行这些步骤。

  • Amazon Relational Database Service (AmazonRDS) 可帮助您在中设置、操作和扩展关系数据库 AWS Cloud。此模式支持 Amazon for My SQL、Ama RDS z RDS on for Postgre 和 Amazon SQL RDS for MariaDB。

  • AWS SDK for Python (Boto3)帮助您将 Python 应用程序、库或脚本与集成 AWS 服务。在这种模式中,Boto3 APIs 用于与数据库实例或全局数据库通信。

  • AWS Step Functions是一项无服务器编排服务,可帮助您组合 AWS Lambda 功能和其他功能 AWS 服务 来构建关键业务应用程序。在这种模式中,Step Functions 状态机用于协调和运行数据库实例或全局数据库的跨区域故障转移和故障恢复。

代码存储库

此模式的代码可在上的 aws-cross-region-dr GitHub-databases 存储库中找到。

操作说明

任务描述所需技能

克隆 GitHub 存储库。

要克隆存储库,请运行以下命令:

git clone https://github.com/aws-samples/aws-cross-region-dr-databases.git
AWS DevOps,AWS管理员

将 Lambda 函数代码打包到.zip 文件存档中。

为 Lambda 函数创建存档文件以包含 DR Orchestrator 框架依赖项:

cd <YOUR-LOCAL-GIT-FOLDER>/DR-Orchestration-artifacts bash scripts/deploy-orchestrator-sh.sh
AWS 管理员

创建 S3 存储桶。

需要使用 S3 存储桶来存储 DR Orchestrator 框架以及您的最新配置。创建两个 S3 存储桶,一个在主区域 (us-east-1),一个在辅助区域 (us-west-2):

  • dr-orchestrator-xxxxxx-us-east-1

  • dr-orchestrator-xxxxxx-us-west-2

替换为xxxxxx随机值以使存储桶名称独一无二。

AWS 管理员

创建子网和安全组。

在主区域 (us-east-1) 和次要区域 () 中,在您的us-west-2以下区域中为 Lambda 函数部署创建两个子网和一个安全组:VPC

  • subnet-XXXXXXX

  • subnet-YYYYYYY

  • sg-XXXXXXXXXXXX

AWS 管理员

更新 DR Orchestrator 参数文件。

在该<YOUR-LOCAL-GIT-FOLDER>/DR-Orchestration-artifacts/cloudformation文件夹中,更新以下 DR Orchestrator 参数文件:

  • Orchestrator-Deployer-parameters-us-east-1.json

  • Orchestrator-Deployer-parameters-us-west-2.json

使用以下参数值,用资源名称替换xy

[ { "ParameterKey": "TemplateStoreS3BucketName", "ParameterValue": "dr-orchestrator-xxxxxx-us-east-1" }, { "ParameterKey": "TemplateVPCId", "ParameterValue": "vpc-xxxxxx" }, { "ParameterKey": "TemplateLambdaSubnetID1", "ParameterValue": "subnet-xxxxxx" }, { "ParameterKey": "TemplateLambdaSubnetID2", "ParameterValue": "subnet-yyyyyy" }, { "ParameterKey": "TemplateLambdaSecurityGroupID", "ParameterValue": "sg-xxxxxxxxxx" } ]
AWS 管理员

将 DR Orchestrator 框架代码上传到 S3 存储桶。

S3 存储桶中的代码比本地目录中的代码更安全。将DR-Orchestration-artifacts目录(包括所有文件和子文件夹)上传到 S3 存储桶。

要上传代码,请执行以下操作:

  1. 登录到 AWS Management Console。

  2. 导航到 Amazon S3 控制台。

  3. 选择dr-orchestrator-xxxxxx-us-east-1 bucket

  4. 选择 “上传”,然后选择 “添加文件夹”

  5. 选择文件DR-Orchestration-artifacts夹。

  6. 选择上传

  7. 选择dr-orchestrator-xxxxxx-us-west-2存储桶。

  8. 重复步骤 4—7。

AWS 管理员

在主区域部署 DR Orchestrator 框架。

要在主区域 (us-east-1) 中部署 DR Orchestrator 框架,请运行以下命令:

cd <YOUR-LOCAL-GIT-FOLDER>/DR-Orchestration-artifacts/cloudformation aws cloudformation deploy \ --region us-east-1 \ --stack-name dr-orchestrator \ --template-file Orchestrator-Deployer.yaml \ --parameter-overrides file://Orchestrator-Deployer-parameters-us-east-1.json \ --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \ --disable-rollback
AWS 管理员

在辅助区域部署 DR Orchestrator 框架。

在辅助区域 (us-west-2) 中,运行以下命令:

cd <YOUR-LOCAL-GIT-FOLDER>/DR-Orchestration-artifacts/cloudformation aws cloudformation deploy \ --region us-west-2 \ --stack-name dr-orchestrator \ --template-file Orchestrator-Deployer.yaml \ --parameter-overrides file://Orchestrator-Deployer-parameters-us-west-2.json \ --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \ --disable-rollback
AWS 管理员

验证部署。

如果 AWS CloudFormation 命令成功运行,它将返回以下输出:

Successfully created/updated stack - dr-orchestrator

或者,您可以导航到 AWS CloudFormation 控制台并验证dr-orchestrator堆栈的状态。

AWS 管理员
任务描述所需技能

创建数据库子网和安全组。

在您的中VPC,在主 (us-east-1) 和辅助 (us-west-2) 区域中为数据库实例或全局数据库创建两个子网和一个安全组:

  • subnet-XXXXXX

  • subnet-XXXXXX

  • sg-XXXXXXXXXX

AWS 管理员

更新主数据库实例或集群的参数文件。

<YOUR LOCAL GIT FOLDER>/App-Stack文件夹中,更新主区域的参数文件。

Amazon RDS

RDS-MySQL-parameter-us-east-1.json文件中SubnetIdsDBSecurityGroup使用您创建的资源的名称更新和:

{ "Parameters": { "SubnetIds": "subnet-xxxxxx,subnet-xxxxxx", "DBSecurityGroup": "sg-xxxxxxxxxx", "MySqlGlobalIdentifier":"rds-mysql-instance", "InitialDatabaseName": "mysqldb", "DBPortNumber": "3789", "PrimaryRegion": "us-east-1", "SecondaryRegion": "us-west-2", "KMSKeyAliasName": "rds/rds-mysql-instance-KmsKeyId" } }

Amazon Aurora

Aurora-MySQL-parameter-us-east-1.json文件中SubnetIdsDBSecurityGroup使用您创建的资源的名称更新和:

{ "Parameters": { "SubnetIds": "subnet1-xxxxxx,subnet2-xxxxxx", "DBSecurityGroup": "sg-xxxxxxxxxx", "GlobalClusterIdentifier":"dr-globaldb-cluster-mysql", "DBClusterName":"dbcluster-01", "SourceDBClusterName":"dbcluster-02", "DBPortNumber": "3787", "DBInstanceClass":"db.r5.large", "InitialDatabaseName": "sampledb", "PrimaryRegion": "us-east-1", "SecondaryRegion": "us-west-2", "KMSKeyAliasName": "rds/dr-globaldb-cluster-mysql-KmsKeyId" } }

亚马逊 ElastiCache (RedisOSS)

ElastiCache-parameter-us-east-1.json文件中SubnetIdsDBSecurityGroup使用您创建的资源的名称更新和。

{ "Parameters": { "CacheNodeType": "cache.m5.large", "DBSecurityGroup": "sg-xxxxxxxxxx", "SubnetIds": "subnet-xxxxxx,subnet-xxxxxx", "EngineVersion": "5.0.6", "GlobalReplicationGroupIdSuffix": "demo-redis-global-datastore", "NumReplicas": "1", "NumShards": "1", "ReplicationGroupId": "demo-redis-cluster", "DBPortNumber": "3788", "TransitEncryption": "true", "KMSKeyAliasName": "elasticache/demo-redis-global-datastore-KmsKeyId", "PrimaryRegion": "us-east-1", "SecondaryRegion": "us-west-2" } }
AWS 管理员

在主区域部署您的数据库实例或集群。

要在主区域 (us-east-1) 中部署您的实例或集群,请根据您的数据库引擎运行以下命令。

Amazon RDS

cd <YOUR-LOCAL-GIT-FOLDER>/App-Stack aws cloudformation deploy \ --region us-east-1 \ --stack-name rds-mysql-app-stack \ --template-file RDS-MySQL-Primary.yaml \ --parameter-overrides file://RDS-MySQL-parameter-us-east-1.json \ --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \ --disable-rollback

Amazon Aurora

cd <YOUR-LOCAL-GIT-FOLDER>/App-Stack aws cloudformation deploy \ --region us-east-1 \ --stack-name aurora-mysql-app-stack \ --template-file Aurora-MySQL-Primary.yaml \ --parameter-overrides file://Aurora-MySQL-parameter-us-east-1.json \ --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \ --disable-rollback

亚马逊 ElastiCache (RedisOSS)

cd <YOUR-LOCAL-GIT-FOLDER>/App-Stack aws cloudformation deploy \ --region us-east-1 --stack-name elasticache-ds-app-stack \ --template-file ElastiCache-Primary.yaml \ --parameter-overrides file://ElastiCache-parameter-us-east-1.json \ --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \ --disable-rollback

验证 AWS CloudFormation 资源是否成功部署。

AWS 管理员

更新辅助数据库实例或集群的参数文件。

<YOUR LOCAL GIT FOLDER>/App-Stack文件夹中,更新辅助区域的参数文件。

Amazon RDS

RDS-MySQL-parameter-us-west-2.json文件中SubnetIDsDBSecurityGroup使用您创建的资源的名称更新和。PrimaryRegionKMSKeyArn使用MySQLKmsKeyId从主数据库实例 AWS CloudFormation 堆栈的 O ut puts 部分中获取的值更新:

{ "Parameters": { "SubnetIds": "subnet-aaaaaaaaa,subnet-bbbbbbbbb", "DBSecurityGroup": "sg-cccccccccc", "MySqlGlobalIdentifier":"rds-mysql-instance", "InitialDatabaseName": "mysqldb", "DBPortNumber": "3789", "PrimaryRegion": "us-east-1", "SecondaryRegion": "us-west-2", "KMSKeyAliasName": "rds/rds-mysql-instance-KmsKeyId", "PrimaryRegionKMSKeyArn":"arn:aws:kms:us-east-1:xxxxxxxxx:key/mrk-xxxxxxxxxxxxxxxxxxxxx" } }

Amazon Aurora

Aurora-MySQL-parameter-us-west-2.json文件中,DBSecurityGroup使用您创建的资源的名称更新SubnetIDs和。PrimaryRegionKMSKeyArn使用AuroraKmsKeyId从主数据库实例 AWS CloudFormation 堆栈的 O ut puts 部分中获取的值更新:

{ "Parameters": { "SubnetIds": "subnet1-aaaaaaaaa,subnet2-bbbbbbbbb", "DBSecurityGroup": "sg-cccccccccc", "GlobalClusterIdentifier":"dr-globaldb-cluster-mysql", "DBClusterName":"dbcluster-01", "SourceDBClusterName":"dbcluster-02", "DBPortNumber": "3787", "DBInstanceClass":"db.r5.large", "InitialDatabaseName": "sampledb", "PrimaryRegion": "us-east-1", "SecondaryRegion": "us-west-2", "KMSKeyAliasName": "rds/dr-globaldb-cluster-mysql-KmsKeyId" } }

亚马逊 ElastiCache (RedisOSS)

ElastiCache-parameter-us-west-2.json文件中SubnetIDsDBSecurityGroup使用您创建的资源的名称更新和。PrimaryRegionKMSKeyArn使用ElastiCacheKmsKeyId从主数据库实例 AWS CloudFormation 堆栈的 O ut puts 部分中获取的值更新:

{ "Parameters": { "CacheNodeType": "cache.m5.large", "DBSecurityGroup": "sg-cccccccccc", "SubnetIds": "subnet-aaaaaaaaa,subnet-bbbbbbbbb", "EngineVersion": "5.0.6", "GlobalReplicationGroupIdSuffix": "demo-redis-global-datastore", "NumReplicas": "1", "NumShards": "1", "ReplicationGroupId": "demo-redis-cluster", "DBPortNumber": "3788", "TransitEncryption": "true", "KMSKeyAliasName": "elasticache/demo-redis-global-datastore-KmsKeyId", "PrimaryRegion": "us-east-1", "SecondaryRegion": "us-west-2" } }
AWS 管理员

在辅助区域部署您的数据库实例或集群。

根据您的数据库引擎运行以下命令。

Amazon RDS

cd <YOUR-LOCAL-GIT-FOLDER>/App-Stack aws cloudformation deploy \ --region us-west-2 \ --stack-name rds-mysql-app-stack \ --template-file RDS-MySQL-DR.yaml \ --parameter-overrides file://RDS-MySQL-parameter-us-west-2.json \ --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \ --disable-rollback

Amazon Aurora

cd <YOUR-LOCAL-GIT-FOLDER>/App-Stack aws cloudformation deploy \ --region us-west-2 \ --stack-name aurora-mysql-app-stack \ --template-file Aurora-MySQL-DR.yaml \ --parameter-overrides file://Aurora-MySQL-parameter-us-west-2.json \ --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \ --disable-rollback

亚马逊 ElastiCache (RedisOSS)

cd <YOUR-LOCAL-GIT-FOLDER>/App-Stack aws cloudformation deploy \ --region us-west-2 \ --stack-name elasticache-ds-app-stack \ --template-file ElastiCache-DR.yaml \ --parameter-overrides file://ElastiCache-parameter-us-west-2.json \ --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \ --disable-rollback

验证 AWS CloudFormation 资源是否成功部署。

AWS 管理员

相关资源