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

问题描述

如果该实例在中间,我想通过Auto Scaling 功能阻止 EC2 实例终止某种处理.

背景:
假设我有一个 Auto Scaling 组,目前有 5 个实例在运行.我创建了一个关于平均 CPU 使用率的警报...假设 4 个实例处于空闲状态,一个正在执行一些繁重的处理...平均 CPU 负载将触发警报,从而执行缩减策略.

如何让 Auto Scaling 终止空闲实例之一而不是正在处理的实例?

解决方案

更新

正如 Ryan Walls 指出的 (+1),AWS 同时提供了 实例保护 控制 Auto Scaling 是否可以在以下情况下终止特定实例扩展(请参阅介绍性博客文章 Auto Scaling 的实例保护 了解一下):

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

值得注意的是,此实例保护仅适用于事件中的常规 Auto Scaling 规模:

实例保护不保护 Auto Scaling 实例免受通过 Amazon EC2 控制台手动终止,terminate-instances 命令,或 TerminateInstances API.实例保护不会保护 Auto Scaling 实例免于终止如果它未通过健康检查并且必须更换.另外,实例保护不保护 Auto Scaling 组中的 Spot 实例免打扰.

与往常一样,该功能可通过 AWS 管理控制台(菜单操作->实例保护->设置扩展保护)、AWS CLI(set-instance-protection 命令)和 API(SetInstanceProtection API 操作).

后两个选项允许手头的场景自动化,即需要在运行繁重处理"作业之前启用实例保护,并在完成后禁用实例保护,以便实例有资格再次终止.

初始答案

此功能目前不适用于 Auto Scaling/aws.amazon.com/ec2/" rel="nofollow noreferrer">Amazon EC2 实例 - 而您确实能够为您的 Auto Scaling 组配置 [an] 实例终止策略可用政策 不包括这样一个(相当先进的)概念:>

Auto Scaling 为您提供以下终止策略选项从中选择.您可以在您的文件中指定一个或多个这些选项终止政策.

  • OldestInstance — 如果您希望终止 Auto Scaling 组中最早的实例,请指定此项.[...]

  • NewestInstance — 如果您希望终止上次启动的实例,请指定此项.[...]

  • OldestLaunchConfiguration — 如果您希望使用最旧的启动配置启动的实例为终止.[...]

  • ClosestToNextInstanceHour — 如果您希望最接近完成计费小时的实例成为终止.[...]

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

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

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.

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?

解决方案

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):

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

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.


Initial Answer

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 终止 EC2 实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-10 07:52