2017年底AWS宁夏区域正式开放运营,AWS宁夏区域部分实例价格比AWS北京区域降价近40%,出于成本原因考虑,很多客户希望把自己的业务迁移到AWS宁夏区域。
迁移范围如下:
- EC2
- EBS
- S3
- RDS
- ElastiCatch
- DynamoDB
1.将 EC2从 BJS 迁移至 ZHY
a)从实例创建AMI
在 EC2 控制台中,在左侧选择栏中点击 Instances,在迁移的实例上右键选择 Image -> Create Image。
可以使用 AWS 管理控制台或命令行创建 AMI。
下图总结了从正在运行的 EC2 实例创建 Amazon EBS 支持的 AMI 的过程。从现有 AMI 开始,启动一个实例,自定义该实例,从该实例创建新 AMI,并最终启动新 AMI 的实例。下图中的步骤与下面的过程中的步骤匹配。
从实例创建 AMI 的工作流程
具体操作步骤:
b)复制 AMI
可以使用 AWS 管理控制台、AWS Command Line Interface 或开发工具包、或者 Amazon EC2 API(三者都支持 CopyImage 操作)在 AWS 区域内或跨 AWS 区域复制 Amazon 系统映像 (AMI)。可以复制由 Amazon EBS 支持的 AMIs 和由实例存储支持的 AMIs。您可以复制带加密快照的 AMI,并在复制过程中更改加密状态。
复制源 AMI 将生成完全相同但独立的目标 AMI(具有自己的唯一标识符)。对于 Amazon EBS 支持的 AMI,默认情况下其每个支持快照将会复制到完全相同但独立的目标快照。(唯一的例外是在选择加密或重新加密快照时。) 您可以更改或取消注册源 AMI,这不会对目标 AMI 产生任何影响。反之亦然。
复制 AMI 没有任何费用。但要收取标准存储和数据传输费。
AWS 不会将启动许可、用户定义的标签或 Amazon S3 存储桶许可从源 AMI 复制到新 AMI。复制操作完成之后,可以将启动许可、用户定义的标签和 Amazon S3 存储桶权限应用于新 AMI。
复制实例存储支持的 AMI 的权限
如果您使用 IAM 用户复制实例存储支持的 AMI,则用户必须具有以下 Amazon S3 权限:s3:CreateBucket、s3:GetBucketAcl、s3:ListAllMyBuckets、s3:GetObject、s3:PutObject 和 s3:PutObjectAcl。
以下示例策略允许用户将指定的存储桶中的 AMI 源复制到指定的区域。
- {
- "Version": "2012-10-17",
- "Statement": [
- {
- "Effect": "Allow",
- "Action": "s3:ListAllMyBuckets",
- "Resource": [
- "arn:aws:s3:::*"
- ]
- },
- {
- "Effect": "Allow",
- "Action": "s3:GetObject",
- "Resource": [
- "arn:aws:s3:::ami-source-bucket/*"
- ]
- },
- {
- "Effect": "Allow",
- "Action": [
- "s3:CreateBucket",
- "s3:GetBucketAcl",
- "s3:PutObjectAcl",
- "s3:PutObject"
- ],
- "Resource": [
- "arn:aws:s3:::amis-for-123456789012-in-us-east-1*"
- ]
- }
- ]
- }
具体操作步骤:
c)在ZHY启动实例
从 AMI 启动实例,进入启动实例向导,最后在ZHY启动成功
2.将EBS从 BJS 迁移至 ZHY
a)创建快照
b)跨区域复制快照
c)在ZHY创建卷
3.将S3从 BJS 迁移至 ZHY
将S3从 BJS 迁移至 ZHY,您有以下两种迁移方案:
- 在宁夏区创建一个新的 S3 桶,将数据拷贝到该桶中。
- 删除原数据桶并在宁夏区(目标区)重新创建同名 S3 桶,该方案需要一个临时桶作为转移中转。
a)创建新的S3桶
在 S3 控制台中,点击 Create Bucket,选择宁夏作为桶的可用区,在 Copy settings from an existing bucket 选项中,选择您欲做迁移的 S3 桶,可同步两个桶的配置。
在 CLI 端运行以下命令行,开始复制桶内文件。
aws s3 sync s3://SOURCE_BUCKET_NAME s3://NEW_BUCKET_NAME
创建临时桶,步骤参见(1)。
在 CLI 端逐步运行以下命令行,将旧 S3 桶中的内容存入临时桶。
aws s3 sync s3://foobucket s3://tmpbucket
在控制台中旧 S3 桶删除,等待24小时后该命名重新生效。
重新在宁夏区注册同名 S3 桶。
在 CLI 端逐步运行以下命令行,将临时桶中的文件存入目标桶。
aws s3 sync s3://tmpbucket s3://foobucket
4.将RDS for MySQL从 BJS 迁移至 ZHY
将RDS迁移到ZHY有两种方案
方案一 创建快照部署到其他区域
具体操作步骤:
1.登录 AWS 管理控制台 并通过以下网址打开 Amazon RDS 控制台:https://console.amazonaws.cn/rds/。
2.在导航窗格中,选择 Databases (数据库)。
3.在数据库实例列表中,选择您想拍摄快照的数据库实例。
4.对于操作,选择拍摄快照。
此时会显示拍摄数据库快照窗口。
5.在快照名称框中,键入快照的名称。
在左侧导航栏中选择 Snapshot,选中刚创建的快照,Actions选择 Copy Snapshot 复制 RDS快照,并将宁夏区域作为快照复制的目标区域。
接下来就可以通过快照在宁夏区域恢复RDS服务了
方案二 使用DMS服务
使用DMS可以完成7*24 小时在线的数据库最小停机时间迁移,大致流程如下:
可以通过从 AWS 管理控制台选择正在运行的任务来查看任务的统计数据和监控信息,确认迁移完成情况。
5.将ElastiCatch for Redis从 BJS 迁移至 ZHY
迁移ElastiCatch服务分为两个步骤,将ElastiCatch备份到BJS的S3,复制到ZHY的S3后,进行备份恢复。
步骤一 备份 Redis 服务到S3
创建备份前需要停止写入操作。
在控制台选中希望迁移的 Redis 服务,点击上方的 Backup 按钮创建备份。
在控制台左侧选择栏中点击 Backups 选项,查看刚创建的备份。
- 创建一个 S3 桶用来存储 ElastiCache 备份。
- 依次选择 Permissions -> Access Control List。
- 在 Access for other AWS accounts 下, 选择 + Add account。
- 在窗口内添加对应区域的 canonical id
- 下述选项勾选Yes: List objects Write objects Read bucket permissions
- 选择 Save,授权 ElastiCache 读写 S3 桶内文件
步骤二 将备份部署到宁夏区域
- 将位于北京区的 S3 桶中的备份文件迁移至宁夏区,或下载后上传到宁夏的 S3 。
- 在宁夏区域建立新的 Redis 服务
- 在 Import data to cluster 项中填入位于宁夏 S3 桶中的备份文件路径
6. 将 DynamoDB 服务从 BJS 迁移至 ZHY
方案一 使用自定义 API
可以使用 API 将 BJS 的数据转移到 ZHY,根据需要脚本程序配置参数
具体操作步骤:
终端执行如下代码:
python transferDynamoDB.py -t [source table] -r [source region] -nr [destination region]
方案二 使用 EMR Hive迁移数据到宁夏区域
利用 Amazon EMR创建集群,使用 EMR Hive 将 BJS 数据迁移到 ZHY。
具体操作步骤:
启动 Amazon EMR 集群,并使用SSH连接集群
登入 Hive
在 Hive 创建2个 External table,location 分别指向 BJS 和 ZHY。
使用 query 将 BJS 数据复制到 ZHY,可使用 insert into 进行复制,以免覆盖原数据。
数据库迁移完毕后,请及时更改服务器配置。
At the end of 2017, the AWS Ningxia region officially opened for operation. Some instance prices in the AWS Ningxia region are nearly 40% lower than the AWS Beijing region. For cost reasons, many customers want to migrate their business to the AWS Ningxia region.
Migration scope includes:
- EC2
- EBS
- S3
- RDS
- ElastiCache
- DynamoDB
1. Migrate EC2 from BJS to ZHY
a) Create AMI from Instance
In the EC2 console, click Instances in the left selection bar, right-click on the instance to be migrated and select Image -> Create Image.
You can create an AMI using the AWS Management Console or command line.
The diagram below summarizes the process of creating an Amazon EBS-backed AMI from a running EC2 instance. Starting from an existing AMI, launch an instance, customize the instance, create a new AMI from that instance, and finally launch an instance of the new AMI.
Workflow for creating AMI from instance
Specific operation steps:
b) Copy AMI
You can copy Amazon Machine Images (AMIs) within or across AWS regions using the AWS Management Console, AWS Command Line Interface or SDKs, or the Amazon EC2 API. You can copy AMIs backed by Amazon EBS and AMIs backed by instance store. You can copy AMIs with encrypted snapshots and change the encryption status during the copy process.
Copying the source AMI generates an identical but independent target AMI (with its own unique identifier). For Amazon EBS-backed AMIs, each backing snapshot is copied to an identical but independent target snapshot by default. You can change or deregister the source AMI without any impact on the target AMI. The reverse is also true.
There is no charge for copying AMIs. However, standard storage and data transfer fees apply.
AWS does not copy launch permissions, user-defined tags, or Amazon S3 bucket permissions from the source AMI to the new AMI. After the copy operation completes, you can apply launch permissions, user-defined tags, and Amazon S3 bucket permissions to the new AMI.
Permissions for Copying Instance Store-Backed AMIs
If you use an IAM user to copy an instance store-backed AMI, the user must have the following Amazon S3 permissions: s3:CreateBucket, s3:GetBucketAcl, s3:ListAllMyBuckets, s3:GetObject, s3:PutObject, and s3:PutObjectAcl.
Specific operation steps:
c) Launch Instance in ZHY
Launch an instance from the AMI, enter the launch instance wizard, and successfully launch in ZHY
2. Migrate EBS from BJS to ZHY
a) Create Snapshot
b) Cross-region Copy Snapshot
c) Create Volume in ZHY
3. Migrate S3 from BJS to ZHY
To migrate S3 from BJS to ZHY, you have the following two migration options:
- Create a new S3 bucket in the Ningxia region and copy the data to that bucket.
- Delete the original data bucket and recreate an S3 bucket with the same name in the Ningxia region (target region). This option requires a temporary bucket as a transfer intermediate.
a) Create New S3 Bucket
In the S3 console, click Create Bucket, select Ningxia as the bucket's availability zone. In the Copy settings from an existing bucket option, select the S3 bucket you want to migrate.
Run the following command in CLI to start copying files in the bucket.
aws s3 sync s3://SOURCE_BUCKET_NAME s3://NEW_BUCKET_NAME
Create a temporary bucket, see step (1).
Run the following commands in CLI to store the contents of the old S3 bucket into the temporary bucket.
aws s3 sync s3://foobucket s3://tmpbucket
Delete the old S3 bucket in the console, wait 24 hours for the name to become effective again.
Re-register an S3 bucket with the same name in the Ningxia region.
Run the following commands in CLI to store files from the temporary bucket into the target bucket.
aws s3 sync s3://tmpbucket s3://foobucket
4. Migrate RDS for MySQL from BJS to ZHY
There are two options for migrating RDS to ZHY:
- Create snapshot and deploy to other region
- Use DMS service
Option 1: Create Snapshot and Deploy to Other Region
Specific operation steps:
1. Log in to the AWS Management Console and open the Amazon RDS console.
2. In the navigation pane, select Databases.
3. In the database instance list, select the database instance you want to take a snapshot of.
4. For Actions, select Take Snapshot.
5. In the Snapshot Name box, type a name for the snapshot.
In the left navigation bar, select Snapshot, select the snapshot just created, Actions select Copy Snapshot to copy the RDS snapshot, and set the Ningxia region as the target region for snapshot copy.
Next, you can restore the RDS service in the Ningxia region from the snapshot
Option 2: Use DMS Service
Using DMS, you can complete 7x24 online database migration with minimal downtime. The general process is as follows:
- Create replication instance
- Create target and source endpoints
- Create migration task for database
You can view task statistics and monitoring information by selecting the running task from the AWS Management Console to confirm migration completion.
5. Migrate ElastiCache for Redis from BJS to ZHY
Migrating ElastiCache service is divided into two steps: backup ElastiCache to BJS's S3, copy to ZHY's S3, then perform backup recovery.
Step 1: Backup Redis Service to S3
Stop write operations before creating a backup.
In the console, select the Redis service you want to migrate, click the Backup button above to create a backup.
In the console left selection bar, click the Backups option to view the backup just created.
- Create an S3 bucket to store ElastiCache backups.
- Select Permissions -> Access Control List in sequence.
- Under Access for other AWS accounts, select + Add account.
- Add the canonical id of the corresponding region in the window
- Check Yes for the following options: List objects Write objects Read bucket permissions
- Select Save to authorize ElastiCache to read and write files in the S3 bucket
Step 2: Deploy Backup to Ningxia Region
- Migrate the backup file from the S3 bucket in Beijing region to Ningxia region, or download and upload to Ningxia's S3.
- Create a new Redis service in Ningxia region
- Enter the backup file path in the Ningxia S3 bucket in the Import data to cluster item
6. Migrate DynamoDB Service from BJS to ZHY
Option 1: Use Custom API
You can use API to transfer data from BJS to ZHY, configure script parameters as needed
Execute the following code in terminal:
python transferDynamoDB.py -t [source table] -r [source region] -nr [destination region]
Option 2: Use EMR Hive to Migrate Data to Ningxia Region
Use Amazon EMR to create a cluster, use EMR Hive to migrate BJS data to ZHY.
Specific operation steps:
Launch Amazon EMR cluster and connect to the cluster using SSH
Log into Hive
In Hive, create 2 External tables with locations pointing to BJS and ZHY respectively.
Use query to copy BJS data to ZHY, you can use insert into to avoid overwriting original data.
After database migration is complete, please update server configuration in a timely manner.