【AWS AMI跨境备份】跨境使用 S3 备份和还原 AMI 镜像

devtools/2024/10/21 11:29:29/

文章目录

    • 一、实验场景
    • 二、实验目标
    • 三、实验架构图
    • 四、涉及到AWS服务
    • 五、演示操作
      • 5.1 创建EC2实例
      • 5.2 创建映像
      • 5.3 备份AMI至Global S3
      • 5.4 复制AMI从Global S3至 CN S3
      • 5.5 还原AMI
      • 5.6 测试AMI
    • 六、参考链接

一、实验场景

将 AWS Global区域的EC2实例备份至 AWS CN区域。

备份方式:通过 AMI 镜像的方式;

备份频率:2次/月;

备份镜像:可能涉及镜像许可问题;

二、实验目标

  1. 跨境备份和还原所需要的AMI镜像(包括但不限于Windows、Linux等映像);
  2. 利用S3 存储的生命周期管理功能,每周备份一次 AMI 镜像至CN区的 S3 指定的存储桶中;
  3. 还原S3中备份的AMI镜像,查看该 AMI 是否能够正常使用;

三、实验架构图

image-20241016122037963

四、涉及到AWS服务

S3、EC2、AWS CLI2

五、演示操作

5.1 创建EC2实例

1️⃣以美国东部 (弗吉尼亚北部) us-east-1为例;

2️⃣EC2名称:EC2-AMI-Backup;

3️⃣Amazon Machine Image (AMI) 名称:Amazon Linux 2023 AMI;

Amazon Linux 2023 是基于 Linux 的现代化通用操作系统,提供 5 年的长期支持。它针对 AWS 进行了优化,旨在提供一个安全、稳定和高性能的执行环境来开发和运行您的云应用程序。

4️⃣Amazon Machine Image (AMI) ID:ami-06b21ccaeff8cd686 (64 位(x86), uefi-preferred) / ami-02801556a781a4499 (64 位(ARM), uefi)

image-20241015111342053

image-20241015111355697

image-20241016111441837

  • 安装Docker
Step 1: Update AL2023 Packages
sudo dnf updateStep 2. Installing Docker on Amazon Linux 2023
sudo dnf install dockerStep 3: Start and Enable its Service
sudo systemctl start docker && sudo systemctl enable docker && sudo systemctl status dockerStep 4: Allow docker to run without sudo
sudo usermod -aG docker $USERStep 5: Docker Uninstallation (optional)
sudo dnf remove docker
  • 安装Docker-Compose
Step 1: To download and install Compose standalone, run:
curl -SL https://github.com/docker/compose/releases/download/v2.29.6/docker-compose-linux-x86_64 -o /usr/local/bin/docker-composeStep 2: Apply executable permissions to the standalone binary in the target path for the installation.
cd /usr/local/bin/docker-compose
chmod +x docker-composeStep 3: Test and execute compose commands using docker-compose.
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
  • 安装WordPress

image-20241015231141948

  • 访问WordPress

image-20241016103112484

5.2 创建映像

依次点击操作——映像和模板——创建映像

image-20241015232855692

填写映像名称。

image-20241015233010655

查看确认AMI状态,是否是“可用”。

image-20241015233234361

确认该状态已经变为可用

image-20241015233915205

在快照一栏中,我们也可以发现该EC2快照。

image-20241015233807189


以下是使用CLI命令进行操作:

注意:需要提前在运行环境中配置好AWS CLI命令运行配置信息。

aws ec2 create-image --instance-id <id> --name <name>C:\Users\xyb>aws ec2 create-image --instance-id i-0625f12dd36562e05 --name EC2-AMI-Backup-CLI
{"ImageId": "ami-0d3ffbc792ff21ba9"
}

image-20241015235228484

5.3 备份AMI至Global S3

# 创建s3存储桶
aws s3api create-bucket \--bucket my-bucket \--region us-east-1# 备份镜像至S3存储桶🪣中
aws ec2 create-store-image-task \--image-id ami-1234567890abcdef0 \--bucket my-ami-bucket
aws s3api create-bucket --bucket my-ami-bucket-xybdiy --region us-east-1aws ec2 create-store-image-task --image-id ami-03263c5d606a74023 --bucket my-ami-bucket-xybdiy

报错提示:提示该存储桶名称已存在,需要重新选择新的存储桶名称进行尝试。

image-20241016000400169

  • 执行如下命令,备份AMI镜像至Globa区域的指定的S3存储桶里。
C:\Users\xyb>aws ec2 create-store-image-task --image-id ami-03263c5d606a74023 --bucket my-ami-bucket-xybdiy
{"ObjectKey": "ami-03263c5d606a74023.bin"
}

截图示例:

image-20241016000605519

  • 执行命令,查看该AMI镜像任务进度。
aws ec2 describe-store-image-tasks
C:\Users\xyb>aws ec2 describe-store-image-tasks
{"StoreImageTaskResults": [{"AmiId": "ami-03263c5d606a74023","TaskStartTime": "2024-10-15T16:05:39.813000+00:00","Bucket": "my-ami-bucket-xybdiy","S3objectKey": "ami-03263c5d606a74023.bin","ProgressPercentage": 100,"StoreTaskState": "Completed","StoreTaskFailureReason": ""}]
}

查看该镜像已经打包上传至存储桶中。

image-20241016001414905

5.4 复制AMI从Global S3至 CN S3

# 登录AWS境内账号,创建存储桶。
aws s3api create-bucket --bucket my-bucket-cn-xybdiy --region cn-northwest-1 --create-bucket-configuration LocationConstraint=cn-northwest-1
{"Location": "http://my-bucket-cn-xybdiy.s3.cn-northwest-1.amazonaws.com.cn/"
}

Global 区域存储桶:

image-20241016100157530

  • 执行如下命令,上传.bin至CN区域存储桶。
aws s3 cp ami-03263c5d606a74023.bin s3://my-bucket-cn-xybdiy

截图示例:
image-20241016101310838

  • 上传完成。

image-20241016101835242

CN 区域存储桶:

image-20241016101904035

5.5 还原AMI

# 示例
aws ec2 create-restore-image-task \--object-key ami-03263c5d606a74023.bin   \--bucket my-ami-bucket-xybdiy \--name "AMI-CN"
  • 执行如下命令,还原AMI。
aws ec2 create-restore-image-task --object-key ami-03263c5d606a74023.bin --bucket my-bucket-cn-xybdiy --name EC2-AMI-CN-Backup

image-20241016102258540

  • 在控制台中,我们可以查看到AMI镜像。

image-20241016102508444

5.6 测试AMI

  • 选择从 AMI 启动实例

image-20241016102614595

image-20241016102753618

image-20241016102808130

image-20241016103022280

测试WordPress服务是否能够正常访问。

image-20241016103631181

六、参考链接

💻 https://docs.aws.amazon.com/zh_cn/AWSEC2/latest/UserGuide/ami-store-restore.html

🔆 AWS CLI Command Reference — AWS CLI 2.18.7 Command Reference

📍 https://megazone.com/cn/ec2-instance-migration/


http://www.ppmy.cn/devtools/127550.html

相关文章

【存储设备专栏 2.8 -- linux 下挂载命令 mount 与 gio mount】

> 请阅读【嵌入式及芯片开发学必备专栏】< 文章目录 mount 命令步骤卸载&#xff08;可选&#xff09; gio mountgio mount -d 详细介绍用法示例示例 1: 挂载 U 盘示例 2: 查看挂载的设备示例 3: 卸载设备 注意事项总结 mount 命令 要将插入到 Linux 系统的 U 盘&#x…

Ascend C算子编程和C++基础 Lesson3-2 矩阵编程

一、矩阵乘基础知识 二、矩阵乘的核函数 三、矩阵乘的Tiling

计算机网络基本架构示例2

一、企业内部网络架构 在一个中型企业中&#xff0c;通常会有以下的网络架构&#xff1a; - 核心层&#xff1a;由高性能的核心交换机组成&#xff0c;负责快速转发大量数据。例如采用具有高带宽和冗余功能的三层交换机&#xff0c;确保整个网络的稳定运行。它连接着各个部门的…

【玩转 JS 函数式编程_013】4.1 JavaScript 纯函数的相关概念(中):函数副作用的几种具体表现

文章目录 4.1.2. 副作用 Side effects1 常见副作用 Usual side effects&#xff08;详见上篇&#xff09;2 全局状态下的副作用 Global state3 内部状态下的副作用 Inner state4 改变参数导致的副作用 Argument mutation5 一些棘手的函数 Troublesome functions (接上篇内容) …

Go语言中的错误处理:使用自定义错误类型和panic/recover机制

package mainimport ("fmt" )// 定义一个 DivideError 结构&#xff0c;用于表示除法错误 type DivideError struct {dividee int // 被除数divider int // 除数 }// 实现 error 接口 // 这个方法返回一个描述错误的字符串 func (de *DivideError) Error() string {s…

测试教程分享

前几年在腾讯课堂上发布了不少课程&#xff0c;后来腾讯课堂改革&#xff0c;要收会员费&#xff0c;课程还要抽提程&#xff0c;这么下来就相当于白干了。就放弃了在上面发课程&#xff0c;再后来腾讯课堂就关闭了&#xff0c;以前发布的视频就没有地方发了&#xff0c;于是我…

什么是ASC广告?Facebook ASC广告使用技巧

ASC广告全称AdvantageShopping Campaign&#xff0c;即进阶赋能型智能购物广告&#xff0c;许多投放Facebook广告的小伙伴听过这个词&#xff0c;但每用过这个功能&#xff0c;Facebook推出ASC广告已经有两年了&#xff0c;不少实例证明ASC广告在降低转化成本上有一定效果&…

QT QML 练习7-在QML中创建自定义可重用按钮

在本教程中&#xff0c;我们将学习如何在 QML 中创建自定义的可重用按钮。这个例子将引导你创建一个可以在用户界面中多次使用的 MyButton 组件。通过本教程&#xff0c;你将了解如何创建自包含的 QML 组件、处理按钮点击事件以及自定义按钮的外观和行为。 步骤 1&#xff1a;…