From 18b5229b41c95c21358b2cb31f1515ef55a2d873 Mon Sep 17 00:00:00 2001 From: qitan Date: Sun, 7 Apr 2024 17:26:32 +0800 Subject: [PATCH] add technical solution 112 --- README-CN.md | 17 +- README.md | 13 +- .../database/migrate-database-to-cloud.yml | 317 ++++++++++++++++++ 3 files changed, 333 insertions(+), 14 deletions(-) create mode 100644 documents/solution/database/migrate-database-to-cloud.yml diff --git a/README-CN.md b/README-CN.md index 1845b603..c6daee2b 100644 --- a/README-CN.md +++ b/README-CN.md @@ -465,14 +465,15 @@ ROS 模板的示例和最佳实践。模板分类如下: - database -| 模板 | 说明 | -|-----------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------| -| [automatic-database-scaling-and-SQL-optimization.yml](documents/solution/database/automatic-database-scaling-and-SQL-optimization.yml) | 数据库自动扩缩容和自动SQL优化。 | [解决方案](https://aliyun.com/solution/tech-solution/adsa_sql) | -| [wordpress-website-database-on-the-cloud.yml](documents/solution/database/wordpress-website-database-on-the-cloud.yml) | WordPress网站数据库上云。 | -| [dts-cache-synchronization.yml](documents/solution/database/dts-cache-synchronization.yml) | 通过DTS实现MySQL与Redis缓存同步一致性方案。 | [解决方案](https://aliyun.com/solution/tech-solution/rtsorarctebcc) | -| [migrate-rds-mysql-to-polardb-mysql.yml](documents/solution/database/migrate-rds-mysql-to-polardb-mysql.yml) | 在不修改应用程序任何代码和配置的情况下,将RDS MySQL在线一键升级至PolarDB MySQL版。 | [解决方案](https://www.aliyun.com/solution/tech-solution/rds_polardb) | -| [one-stop-htap-service.yml](documents/solution/database/one-stop-htap-service.yml) | RDS+ClickHouse构建一站式HTAP。 | [解决方案](https://aliyun.com/solution/tech-solution/rdsclickhouse_htap) | -| [data-transmission-from-ECS-to-RDS.yml](documents/solution/database/data-transmission-from-ECS-to-RDS.yml) | 网站数据库平滑迁移上云。 | [解决方案](https://www.aliyun.com/solution/tech-solution/smowdttc) | +| 模板 | 说明 | +|-----------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------| +| [automatic-database-scaling-and-SQL-optimization.yml](documents/solution/database/automatic-database-scaling-and-SQL-optimization.yml) | 数据库自动扩缩容和自动SQL优化。 | [解决方案](https://aliyun.com/solution/tech-solution/adsa_sql) | +| [wordpress-website-database-on-the-cloud.yml](documents/solution/database/wordpress-website-database-on-the-cloud.yml) | WordPress网站数据库上云。 | +| [dts-cache-synchronization.yml](documents/solution/database/dts-cache-synchronization.yml) | 通过DTS实现MySQL与Redis缓存同步一致性方案。 | [解决方案](https://aliyun.com/solution/tech-solution/rtsorarctebcc) | +| [migrate-rds-mysql-to-polardb-mysql.yml](documents/solution/database/migrate-rds-mysql-to-polardb-mysql.yml) | 在不修改应用程序任何代码和配置的情况下,将RDS MySQL在线一键升级至PolarDB MySQL版。 | [解决方案](https://www.aliyun.com/solution/tech-solution/rds_polardb) | +| [one-stop-htap-service.yml](documents/solution/database/one-stop-htap-service.yml) | RDS+ClickHouse构建一站式HTAP。 | [解决方案](https://aliyun.com/solution/tech-solution/rdsclickhouse_htap) | +| [data-transmission-from-ECS-to-RDS.yml](documents/solution/database/data-transmission-from-ECS-to-RDS.yml) | 网站数据库平滑迁移上云。 | [解决方案](https://www.aliyun.com/solution/tech-solution/smowdttc) | +| [migrate-database-to-cloud.yml](documents/solution/database/migrate-database-to-cloud.yml) | 自建数据库迁移到云数据库。 | - iot diff --git a/README.md b/README.md index d01eaee2..69538dcb 100644 --- a/README.md +++ b/README.md @@ -469,14 +469,15 @@ Examples and best practices of ROS templates. The templates are categorized as f - database -| Template | Description | -|------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| +| Template | Description | +|---------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | [automatic-database-scaling-and-SQL-optimization.yml](documents/solution/database/automatic-database-scaling-and-SQL-optimization.yml) | Automatic database scaling and SQL optimization| | [wordpress-website-database-on-the-cloud.yml](documents/solution/database/wordpress-website-database-on-the-cloud.yml) | WordPress website database on the cloud. | -| [dts-cache-synchronization.yml](documents/solution/database/dts-cache-synchronization.yml) | The consistency scheme of cache synchronization between MySQL and Redis is implemented by DTS . | -| [migrate-rds-mysql-to-polardb-mysql.yml](documents/solution/database/migrate-rds-mysql-to-polardb-mysql.yml) | Online one-click upgrade of RDS MySQL to PolarDB MySQL version without modifying any code and configuration of the application. | -| [one-stop-htap-service.yml](documents/solution/database/one-stop-htap-service.yml) | Build a one-stop HTAP service based on RDS and ClickHouse. | -| [data-transmission-from-ECS-to-RDS.yml](documents/solution/database/data-transmission-from-ECS-to-RDS.yml) | Data transmission from ECS self-built database to RDS database. | +| [dts-cache-synchronization.yml](documents/solution/database/dts-cache-synchronization.yml) | The consistency scheme of cache synchronization between MySQL and Redis is implemented by DTS . | +| [migrate-rds-mysql-to-polardb-mysql.yml](documents/solution/database/migrate-rds-mysql-to-polardb-mysql.yml) | Online one-click upgrade of RDS MySQL to PolarDB MySQL version without modifying any code and configuration of the application. | +| [one-stop-htap-service.yml](documents/solution/database/one-stop-htap-service.yml) | Build a one-stop HTAP service based on RDS and ClickHouse. | +| [data-transmission-from-ECS-to-RDS.yml](documents/solution/database/data-transmission-from-ECS-to-RDS.yml) | Data transmission from ECS self-built database to RDS database. | +| [migrate-database-to-cloud.yml](documents/solution/database/migrate-database-to-cloud.yml) | Migrate self-built database to cloud database. | - iot diff --git a/documents/solution/database/migrate-database-to-cloud.yml b/documents/solution/database/migrate-database-to-cloud.yml new file mode 100644 index 00000000..2ebaf0a8 --- /dev/null +++ b/documents/solution/database/migrate-database-to-cloud.yml @@ -0,0 +1,317 @@ +ROSTemplateFormatVersion: '2015-09-01' +Description: + zh-cn: 自建数据库迁移到云数据库 + en: Migrate self-built database to cloud database +Parameters: + Zone: + AssociationProperty: ALIYUN::ECS::Instance::ZoneId + Type: String + Description: + zh-cn: 用于创建ECS和RDS的可用区。 + en: Availability zone. + Label: + zh-cn: 可用区 + en: Availability Zone. + EcsInstanceType: + Type: String + Description: + zh-cn: 运行Wordpress及自建数据库的ECS实例类型。 + en: ECS instance which runs WordPress and on-premises database. + Label: + zh-cn: ECS实例类型 + en: ECS instance type. + AssociationProperty: ALIYUN::ECS::Instance::InstanceType + AssociationPropertyMetadata: + SystemDiskCategory: cloud_essd + InstanceChargeType: PostPaid + ZoneId: ${Zone} + Default: ecs.e-c1m1.large + InstancePassword: + NoEcho: true + Type: String + Description: + en: Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in). + zh-cn: 服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)。 + Label: + zh-cn: 实例密码 + en: Instance Password + ConstraintDescription: 长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)。 + AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$' + DBInstanceEngineAndVersion: + Type: String + Description: + zh-cn: 数据库引擎类型及版本,默认为MySQL 8.0 + en: 'Database instance engine type and version, default: MySQL 8.0' + Label: + zh-cn: 引擎类型及版本 + en: Engine And Version + Default: MySQL 8.0 + AllowedValues: + - MySQL 8.0 + DBInstanceClass: + Type: String + Description: '在模拟数据迁移体验中,您可以选择最小规格的数据库实例作为迁移目标实例,以减少成本。在生产环境中选择迁移目标实例,需要确保其规格满足您的业务需求。关于RDS实例规格详情,请参考:云数据库RDS MySQL产品规格。' + Label: + en: Target RDS Instance Class + zh-cn: 迁移目标RDS实例规格 + AssociationProperty: ALIYUN::RDS::Instance::InstanceType + AssociationPropertyMetadata: + ZoneId: + Ref: Zone + EngineVersion: '8.0' + DBInstanceStorageType: cloud_essd + Engine: MySQL + Category: Basic + Default: mysql.n2e.small.1 + DBUserName: + Type: String + Description: + en: Username of RDS database + zh-cn: RDS数据库账号 + ConstraintDescription: + en: Consist of 2 to 16 characters of lowercase letters, underline. Must begin with a letter and be end with an alphanumeric character + zh-cn: 由 2 到 16 个小写字母组成,下划线。必须以字母开头,以字母数字字符结尾 + Label: + zh-cn: RDS数据库账号 + en: RDS DB Username + Default: dbuser + MaxLength: 16 + MinLength: 2 + DBPassword: + Type: String + Description: + en: RDS database password, consisting of letters, numbers, and underline(_), is 8 to 32 characters long + zh-cn: RDS数据库密码,由字母、数字、下划线(_)组成,长度为8~32个字符 + ConstraintDescription: + en: '[8, 32] characters consist of alphanumeric characters, hyphen and underline' + zh-cn: '[8, 32] 个字符由字母数字字符、连字符和下划线组成' + Label: + zh-cn: RDS数据库密码 + en: RDS DB Password + MaxLength: 32 + MinLength: 8 + NoEcho: true +Resources: + RosWaitCondition: + Type: ALIYUN::ROS::WaitCondition + Properties: + Count: 1 + Handle: + Ref: RosWaitConditionHandle + Timeout: 3600 + RosWaitConditionHandle: + Type: ALIYUN::ROS::WaitConditionHandle + VSwitch: + Type: ALIYUN::ECS::VSwitch + Properties: + CidrBlock: 192.168.0.0/24 + ZoneId: + Ref: Zone + VpcId: + Fn::GetAtt: + - Vpc + - VpcId + Vpc: + Type: ALIYUN::ECS::VPC + Properties: + CidrBlock: 192.168.0.0/16 + VpcName: database-migration-test + SecurityGroup: + Type: ALIYUN::ECS::SecurityGroup + Properties: + SecurityGroupName: SG-DTS-GROUP-20220101 + VpcId: + Fn::GetAtt: + - Vpc + - VpcId + Database: + Type: ALIYUN::RDS::DBInstance + Properties: + DBInstanceClass: + Ref: DBInstanceClass + ZoneId: + Ref: Zone + DBInstanceDescription: Test for database migration + DBInstanceStorage: 20 + Category: Basic + DBInstanceStorageType: cloud_essd + VSwitchId: + Ref: VSwitch + Engine: MySQL + VpcId: + Ref: Vpc + SlaveZoneIds: + - Auto + EngineVersion: '8.0' + SecurityIPList: + Fn::GetAtt: + - WebServer + - PrivateIp + MasterUsername: + Ref: DBUserName + MasterUserPassword: + Ref: DBPassword + MasterUserType: Super + SecurityGroupIngress: + Type: ALIYUN::ECS::SecurityGroupIngress + Properties: + SourceCidrIp: 0.0.0.0/0 + SecurityGroupId: + Ref: SecurityGroup + IpProtocol: all + PortRange: '-1/-1' + WebServer: + Type: ALIYUN::ECS::Instance + Properties: + IoOptimized: optimized + ImageId: aliyun_3_x64_20G_alibase_ + SecurityGroupId: + Ref: SecurityGroup + Password: + Ref: InstancePassword + InternetMaxBandwidthOut: 80 + UserData: + Fn::Replace: + - ros-notify: + Fn::GetAtt: + - RosWaitConditionHandle + - CurlCli + - Fn::Join: + - '' + - - '#!/bin/sh' + - |+ + + - | + DatabaseUser='wordpressuser' + - | + DatabasePwd='password' + - | + DatabaseName='wordpressdb' + - | + DatabaseHost='localhost' + - | + yum update -y + - | + yum install -y unzip zip + - | + yum install -y mysql-server + - | + systemctl start mysqld + - | + systemctl enable mysqld + - | + mysql -e "CREATE DATABASE wordpressdb;" + - | + mysql -e "CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';" + - | + mysql -e "GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wordpressuser'@'localhost';" + - | + mysql -e "FLUSH PRIVILEGES;" + - | + mysql -e "CREATE USER dtssync1 IDENTIFIED BY 'P@ssw0rd';" + - | + mysql -e "GRANT ALL ON *.* TO 'dtssync1'@'%';" + - | + mysql -e "FLUSH PRIVILEGES;" + - | + mysql -e "SET GLOBAL binlog_format = 'ROW';" + - | + yum install -y nginx + - | + systemctl start nginx + - | + systemctl enable nginx + - | + yum install -y php php-fpm php-mysqlnd + - | + systemctl start php-fpm + - | + systemctl enable php-fpm + - | + cd /usr/share/nginx/html + - | + wget http://wordpress.org/latest.tar.gz + - | + tar xzvf latest.tar.gz + - | + cp -R wordpress/* . + - | + rm -R wordpress + - | + rm -R wordpress + - | + cp wp-config-sample.php wp-config.php + - | + sed -i "s/database_name_here/$DatabaseName/" wp-config.php + - | + sed -i "s/username_here/$DatabaseUser/" wp-config.php + - | + sed -i "s/password_here/${DatabasePwd:-$DatabasePwdDef}/" wp-config.php + - | + sed -i "s/localhost/$DatabaseHost/" wp-config.php + - | + systemctl restart nginx + - | + systemctl restart php-fpm + - | + ros-notify + VSwitchId: + Ref: VSwitch + VpcId: + Ref: Vpc + InstanceType: + Ref: EcsInstanceType + SystemDiskCategory: cloud_essd + AllocatePublicIP: true + ZoneId: + Ref: Zone +Outputs: + ECSInstanceUser: + Description: Username and password for logging in to ECS instance + Value: + Fn::Join: + - '' + - - 'USERNAME: root ; PASSWORD: ' + - Ref: InstancePassword + WPUserForSQL: + Description: ECS-hosted database username and password for executing SQL + Value: 'USERNAME: wordpressuser ; PASSWORD: password' + WPUserForDTS: + Description: ECS-hosted database username and password for connecting to DTS + Value: 'USERNAME: dtssync1 ; PASSWORD: P@ssw0rd' + RDSUserDTS: + Description: RDS username and password for connecting to DTS + Value: + Fn::Join: + - '' + - - 'USERNAME: ' + - Ref: DBUserName + - ' ' + - 'PASSWORD: ' + - Ref: DBPassword + ECSWordPressUrl: + Description: WordPress default address. + Value: + Fn::Join: + - '' + - - http:// + - Fn::GetAtt: + - WebServer + - PublicIp +Metadata: + ALIYUN::ROS::Interface: + ParameterGroups: + - Parameters: + - EcsInstanceType + - InstancePassword + Label: + default: ECS + - Parameters: + - DBInstanceEngineAndVersion + - DBInstanceClass + - DBUserName + - DBPassword + Label: + default: RDS + TemplateTags: + - acs:technical-solution:database:自建数据库迁移到云数据库-tech_solu_112