AWS自动伸缩组与非ELB健康检查

8
我们针对一个云形成堆栈设置了自动扩展组,该组具有基于 CPU 的警报来确定何时扩展实例。虽然这很好,但最近我们将其从一个节点扩展到三个节点,并且其中一个节点无法通过 cfn-init 引导。一旦工作负载降低并且组缩减为一个节点,它就会终止两个好的实例并留下部分引导失败的节点作为唯一剩下的实例。这意味着我们停止了工作直到有人登录并重新运行引导过程。显然,这不是理想的。当一个节点没有坐在 ELB 后面时,通知自动扩展组某个节点不健康的最佳方式是什么?由于这只是初始引导,我真正想要的是与自动扩展组通信,表明此节点已失败,并终止它,然后在其位置上启动新节点。
2个回答

8
一位同事向我展示了http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/as-configure-healthcheck.html,看起来很方便。

如果您有自己的健康检查系统,则可以使用来自健康检查系统的信息设置自动缩放组中实例的健康状态。

更新 - 我成功在启动期间完成了这个操作。

以下是ASG UserData部分的内容:

#!/bin/bash -v
set -x
export AWS_DEFAULT_REGION=us-west-1
cfn-init --region us-west-1 --stack bapi-prod --resource LaunchConfiguration -v
if [[ $? -ne 0 ]]; then
    export INSTANCE=`curl http://169.254.169.254/latest/meta-data/instance-id`
    aws autoscaling set-instance-health \
         --instance-id $INSTANCE \
         --health-status Unhealthy
fi

0
    cfn-init --region us-west-1 --stack bapi-prod --resource LaunchConfiguration -v
if [[ $? -ne 0 ]]; then
    export INSTANCE=`curl http://169.254.169.254/latest/meta-data/instance-id`
    aws autoscaling set-instance-health \
         --instance-id $INSTANCE \
         --health-status Unhealthy
fi

也可以写成一行代码。例如,我在Terraform中使用以下代码:

runcmd:
 - /tmp/runcmd-puppet.sh || { export INSTANCE=`curl http://169.254.169.254/latest/meta-data/instance-id`; aws autoscaling --region eu-west-1 set-instance-health --instance-id $INSTANCE --health-status Unhealthy; }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接