如何通过Auto Scaling防止EC2实例终止? [英] How can I prevent EC2 instance termination by Auto Scaling?

查看:149
本文介绍了如何通过Auto Scaling防止EC2实例终止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果该实例位于中间,我想通过 Auto Scaling 功能来阻止EC2实例终止

I would like to prevent EC2 instance termination by Auto Scaling feature if that instance is in the middle of some sort of processing.

背景:

假设我有一个Auto Scaling组,当前正在运行5个实例。
我会创建有关平均CPU使用率的警报...
假设有4个实例处于空闲状态,并且一个实例正在执行大量处理...
平均CPU负载将触发警报,并且结果将执行缩小策略。

Background:
Suppose I have an Auto Scaling group that currently has 5 instances running. I create an alarm on average CPU usage... Suppose 4 of the instances are idle and one is doing some heavy processing... The average CPU load will trigger the alarm and as a result the scale-down policy will execute.

如何获得Auto Scaling来终止其中一个空闲实例,而不是正在处理中的实例?

How do I get Auto Scaling to terminate one of the idle instances and not the one that is in the middle of the processing?

推荐答案

更新



(+1)注意到的//stackoverflow.com/a/34604330/45773\">AWS同时提供了实例保护 用于控制Auto Scaling在扩展时是否可以终止特定实例(请参阅入门博客)发表 A的实例保护uto Scaling 进行遍历):

Update

As noted by Ryan Walls (+1), AWS meanwhile provides Instance Protection to control whether Auto Scaling can terminate a particular instance when scaling in (see the introductory blog post Instance Protection for Auto Scaling for a walk through):


您可以在Auto Scaling
组上启用实例保护设置或单个Auto Scaling实例。当Auto Scaling
启动实例时,该实例将继承Auto Scaling组的实例保护
设置。 [...]

You can enable the instance protection setting on an Auto Scaling group or an individual Auto Scaling instance. When Auto Scaling launches an instance, the instance inherits the instance protection setting of the Auto Scaling group. [...]

值得注意的是,这种实例保护仅适用于事件中的常规Auto Scaling标度:

It's worth noting that this instance protection only applies to regular Auto Scaling scale in events:


实例保护不能保护Auto Scaling实例免受
通过Amazon EC2控制台,
终止实例命令或TerminateInstances API。如果实例
保护运行状况检查失败且必须更换,则该实例无法保护Auto Scaling实例免受终止
的侵害。同样,实例
保护也不能保护Auto Scaling组
中的竞价型实例不受干扰。

Instance protection does not protect Auto Scaling instances from manual termination through the Amazon EC2 console, the terminate-instances command, or the TerminateInstances API. Instance protection does not protect an Auto Scaling instance from termination if it fails health checks and must be replaced. Also, instance protection does not protect Spot instances in an Auto Scaling group from interruption.

,该功能可通过AWS管理控制台(菜单操作->实例保护->设置保护级别),AWS CLI( set-instance-protection 命令)和API( SetInstanceProtection API操作)。

As usual, the feature is available via the AWS Management Console (menu Actions->Instance Protection->Set Scale In Protection)), the AWS CLI (set-instance-protection command), and the API (SetInstanceProtection API action).

后两个选项允许自动化例如,在运行大量处理作业之前,需要先启用实例保护,并在完成后禁用实例保护,以使实例有资格再次终止。

The latter two options allow automation of the scenario at hand, i.e. one would need to enable instance protection before running 'heavy processing' jobs, and disable instance protection once they are finished so that the instance is eligible for termination again.

此功能当前不适用于自动缩放 .com / ec2 / rel = nofollow noreferrer> Amazon EC2 实例-虽然您确实能够为您的Auto Scaling组配置[an]实例终止策略可用策略不包括这样的(相当高级的)概念:

This functionality is currently not available for Auto Scaling of Amazon EC2 instances - while you are indeed able to Configure [an] Instance Termination Policy for Your Auto Scaling Group, the available policies do not include such a (fairly advanced) concept:


Auto Scaling为您
提供以下终止策略选项。您可以在
终止政策中指定一个或多个这些选项。

Auto Scaling provides the following termination policy options for you to choose from. You can specify one or more of these options in your termination policy.


  • OldestInstance > —如果要终止Auto Scaling组中最旧的实例,请指定此选项。 [...]

  • OldestInstance — Specify this if you want the oldest instance in your Auto Scaling group to be terminated. [...]

NewestInstance —如果要终止上次启动的实例,请指定此项。 [...]

NewestInstance — Specify this if you want the last launched instance to be terminated. [...]

OldestLaunchConfiguration -如果您希望使用最早的启动配置启动的实例为$ b $,请指定此项b终止。 [...]

OldestLaunchConfiguration — Specify this if you want the instance launched using the oldest launch configuration to be terminated. [...]

ClosestToNextInstanceHour —如果您希望最接近完成计费时间的实例为$,请指定此项b $ b终止。 [...]

ClosestToNextInstanceHour — Specify this if you want the instance that is closest to completing the billing hour to be terminated. [...]

默认-如果您希望Auto Scaling使用默认终止策略来选择要终止的实例,请指定此项。

Default — Specify this if you want Auto Scaling to use the default termination policy to select instances for termination.

这篇关于如何通过Auto Scaling防止EC2实例终止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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