从 Auto Scaling 组中分离 EC2 实例
您可以从 Auto Scaling 组中移除(分离)处于 InService 状态的实例。分离实例之后,可以独立于 Auto Scaling 组的其余部分管理这些实例。通过分离实例,您可以:
-
将实例从一个 Auto Scaling 组移出,然后将其附加到其他组。有关更多信息,请参阅将 EC2 实例附上 Auto Scaling 组。。
-
使用运行应用程序的现有实例创建 Auto Scaling 组,以此来对其进行测试。随后,您可以在测试完成后从 Auto Scaling 组中分离这些实例。
在分离实例时,请注意以下事项:
-
如果要分离的实例数将 Auto Scaling 组的大小降到最小容量以下,您必须先减少该组的最小容量,然后才能分离实例。
-
分离实例时,您可以选择按分离的实例数减少 Auto Scaling 组的所需容量。如果您选择不减少容量,Amazon EC2 Auto Scaling 会启动新实例以替换分离的实例。如果减少容量,但将多个实例从同一可用区分离,则除非暂停
AZRebalance流程,否则 Amazon EC2 Auto Scaling 可以重新平衡可用区。有关更多信息,请参阅暂停和恢复 Auto Scaling 组的进程。 -
如果您将实例从已附加负载均衡器目标组或经典负载均衡器的 Auto Scaling 组分离,则将从该负载均衡器取消注册实例。如果为负载均衡器启用了连接耗尽(取消注册延迟),则 Amazon EC2 Auto Scaling 会等待未送达请求完成。
注意
如果您要分离的实例位于 Standby 状态,请谨慎行事。在将实例置于 Standby 状态后尝试分离实例可能会导致其他实例意外终止。
分离实例(控制台)
使用以下步骤将实例与 Auto Scaling 组分离。
将实例与现有 Auto Scaling 组分离
访问 https://console.aws.amazon.com/ec2/
,打开 Amazon EC2 控制台,然后从导航窗格中选择 Auto Scaling Groups(Auto Scaling 组)。 -
选中您的 Auto Scaling 组旁边的复选框。
这时将在 Auto Scaling groups(Auto Scaling 组)页面底部打开一个拆分窗格。
-
在 Instance management(实例管理)选项卡上的 Instances(实例)中,选择一个实例,然后选择 Actions(操作)、Detach(分离)。
-
在 Detach instance(分离实例)对话框中,选中该复选框可启动替换实例,取消选中该复选框可减少所需容量。选择 Detach instance(分离实例)。
分离实例(Amazon CLI)
使用以下步骤将实例与 Auto Scaling 组分离。
这些示例使用具有以下配置的 Auto Scaling 组:
-
Auto Scaling 组名称 =
my-asg -
最小容量 =
1 -
最大容量 =
5 -
所需容量 =
4
将实例与现有 Auto Scaling 组分离
-
使用以下 describe-auto-scaling-instances 命令列出当前实例。
aws autoscaling describe-auto-scaling-instances以下示例响应显示该组有 4 个正在运行的实例。
{ "AutoScalingInstances": [ { "ProtectedFromScaleIn": false, "AvailabilityZone": "us-west-2a", "LaunchTemplate": { "LaunchTemplateName": "my-launch-template", "Version": "1", "LaunchTemplateId": "lt-050555ad16a3f9c7f" }, "InstanceId": "i-05b4f7d5be44822a6", "AutoScalingGroupName": "my-asg", "HealthStatus": "HEALTHY", "LifecycleState": "InService" }, { "ProtectedFromScaleIn": false, "AvailabilityZone": "us-west-2a", "LaunchTemplate": { "LaunchTemplateName": "my-launch-template", "Version": "1", "LaunchTemplateId": "lt-050555ad16a3f9c7f" }, "InstanceId": "i-0c20ac468fa3049e8", "AutoScalingGroupName": "my-asg", "HealthStatus": "HEALTHY", "LifecycleState": "InService" }, { "ProtectedFromScaleIn": false, "AvailabilityZone": "us-west-2a", "LaunchTemplate": { "LaunchTemplateName": "my-launch-template", "Version": "1", "LaunchTemplateId": "lt-050555ad16a3f9c7f" }, "InstanceId": "i-0787762faf1c28619", "AutoScalingGroupName": "my-asg", "HealthStatus": "HEALTHY", "LifecycleState": "InService" }, { "ProtectedFromScaleIn": false, "AvailabilityZone": "us-west-2a", "LaunchTemplate": { "LaunchTemplateName": "my-launch-template", "Version": "1", "LaunchTemplateId": "lt-050555ad16a3f9c7f" }, "InstanceId": "i-0f280a4c58d319a8a", "AutoScalingGroupName": "my-asg", "HealthStatus": "HEALTHY", "LifecycleState": "InService" } ] } -
使用以下 detach-instances 命令分离实例并减小所需容量。
aws autoscaling detach-instances --instance-idsi-05b4f7d5be44822a6\ --auto-scaling-group-namemy-asg--should-decrement-desired-capacity -
使用以下 describe-auto-scaling-instances 命令确认已分离实例。
aws autoscaling describe-auto-scaling-instances以下示例响应显示现在有 3 个正在运行的实例。
{ "AutoScalingInstances": [ { "ProtectedFromScaleIn": false, "AvailabilityZone": "us-west-2a", "LaunchTemplate": { "LaunchTemplateName": "my-launch-template", "Version": "1", "LaunchTemplateId": "lt-050555ad16a3f9c7f" }, "InstanceId": "i-0c20ac468fa3049e8", "AutoScalingGroupName": "my-asg", "HealthStatus": "HEALTHY", "LifecycleState": "InService" }, { "ProtectedFromScaleIn": false, "AvailabilityZone": "us-west-2a", "LaunchTemplate": { "LaunchTemplateName": "my-launch-template", "Version": "1", "LaunchTemplateId": "lt-050555ad16a3f9c7f" }, "InstanceId": "i-0787762faf1c28619", "AutoScalingGroupName": "my-asg", "HealthStatus": "HEALTHY", "LifecycleState": "InService" }, { "ProtectedFromScaleIn": false, "AvailabilityZone": "us-west-2a", "LaunchTemplate": { "LaunchTemplateName": "my-launch-template", "Version": "1", "LaunchTemplateId": "lt-050555ad16a3f9c7f" }, "InstanceId": "i-0f280a4c58d319a8a", "AutoScalingGroupName": "my-asg", "HealthStatus": "HEALTHY", "LifecycleState": "InService" } ] }