有没有办法在 AWS 中使用自动缩放来停止而不是终止实例? [英] Is there a way to STOP not TERMINATE instances using auto-scaling in AWS?

查看:18
本文介绍了有没有办法在 AWS 中使用自动缩放来停止而不是终止实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用 AWS 自动扩展来根据各种性能指标(CPU 等)扩展和缩减我的基础设施.我了解如何设置;但是,我不喜欢实例在缩小时终止而不是停止.这意味着当我进行扩展时,我必须从头开始使用一个新实例并重新安装我的软件等.我宁愿根据需要启动/停止我的实例,而不是创建/终止.有没有办法做到这一点?

I am looking at using AWS auto-scaling to scale my infrastructure up and down based on various performance metrics (CPU, etc.). I understand how to set this up; however, I don't like that instances are terminated rather than stopped when it is scaled down. This means that when I scale back up, I have to start from scratch with a new instance and re-install my software, etc. I'd rather just start/stop my instances as needed rather than create/terminate. Is there a way to do this?

推荐答案

不,不能在 Auto Scaling 下停止实例.当 Scaling Policy 触发删除实例时,Auto Scaling 将始终终止该实例.

No, it is not possible to Stop an instance under Auto Scaling. When a Scaling Policy triggers the removal of an instance, Auto Scaling will always Terminate the instance.

然而,这里有一些想法来应对终止的概念......

However, here's some ideas to cope with the concept of Termination...

选项 1:使用预先配置的 AMI

您可以使用所需的软件、数据和设置来配置 Amazon EC2 实例.然后,在管理控制台中选择 EC2 实例并选择创建映像行动.这将创建一个新的 亚马逊系统映像 (AMI).然后,您可以将 Auto Scaling 配置为在启动新实例时使用此 AMI.每个新实例将包含完全相同的磁盘内容.

You can configure an Amazon EC2 instance with your desired software, data and settings. Then, select the EC2 instance in the Management Console and choose the Create Image action. This will create a new Amazon Machine Image (AMI). You can then configure Auto Scaling to use this AMI when launching a new instance. Each new instance will contain exactly the same disk contents.

值得一提的是,EBS 从 AMI 启动非常快.它不是将整个 AMI 复制到引导磁盘,而是在首次访问"时将其复制.这意味着新实例可以立即启动,而不是等待整个磁盘被复制.

It's worth mentioning that EBS starts up very quickly from an AMI. Instead of copying the whole AMI to the boot disk, it copies it across on "first access". This means the new instance can start-up immediately rather than waiting for the whole disk to be copied.

选项 2:使用启动(用户数据)脚本

每个 Amazon EC2 实例都有一个 用户数据 字段,可从实例访问该字段.可以通过用户数据字段传递一个脚本,然后在实例启动.该脚本可用于安装软件、下载数据和配置实例.

Each Amazon EC2 instance has a User Data field, which is accessible from the instance. A script can be passed through the User Data field, which is then executed when the instance starts. The script could be used to install software, download data and configure the instance.

脚本可以做一些非常简单的事情,比如从源代码存储库下载配置脚本,然后执行脚本.这意味着机器配置可以集中管理和版本控制.想要更新您的应用程序?只需使用更新后的脚本启动一个新实例并丢弃旧实例(这比更新"应用程序要容易得多).

The script could do something very simple, like download a configuration script from a source code repository, then execute the script. This means that machine configuration can be centrally managed and version-controlled. Want to update your app? Just launch a new instance with the updated script and throw away the old instance (which is much easier than "updating" an app).

选项 3:向 Auto Scaling 组添加/删除实例

不是使用扩展策略来启动/终止 Auto Scaling 组的实例,而是可以附加/分离特定实例.因此,您可以模拟"自动缩放:

Rather than using Scaling Policies to Launch/Terminate instances for an Auto Scaling group, it is possible to attach/detach specific instances. Thus, you could 'simulate' auto scaling:

  • When you want to scale-down, detach an instance from the Auto Scaling group, then stop it.
  • When you want to add an instance, start the instance then attach it to the Auto Scaling group.

这将需要您自己的代码,但它非常简单(基本上是两个 API 调用).您将负责跟踪要附加/分离的实例.

This would require your own code, but it is very simple (basically two API calls). You would be responsible for keeping track of which instance to attach/detach.

这篇关于有没有办法在 AWS 中使用自动缩放来停止而不是终止实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆