由于userdata脚本,AWS自动缩放启动了未就绪的实例 [英] AWS autoscaling starts not ready instances because of userdata script

查看:145
本文介绍了由于userdata脚本,AWS自动缩放启动了未就绪的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很好的自动缩放功能,它具有启动配置,其中我定义了一个在新实例启动时执行的userdata脚本。

I have an autoscaling that works great, with a launchconfiguration where i defined a userdata script that is executed on a new instance launch.

该用户脚本会更新基本代码并生成缓存,这需要几秒钟。但是,一旦实例被创建(而不是就绪),自动缩放就会将其添加到负载均衡器中。

The userscript updates basecode and generate cache, this takes some seconds. But as soon as the instance is "created" (and not "ready"), the autoscaling adds it to the load balancer.

这是一个问题,因为在使用userdata脚本时执行后,实例将无法获得良好的响应(基本上会抛出500个错误)。

It's a problem because while the userdata script is executed, the instance does not answer with a good response (basically, 500 errors are throw).

我想避免这种情况,当然我看到了以下文档: http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/InstallingAdd

I would like to avoid that, of course I saw this documentation : http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/InstallingAdd


与独立EC2实例一样,您可以选择使用用户数据配置启动到Auto Scaling组中的实例。例如,您可以使用AWS管理控制台中的用户数据字段或AWS CLI中的--userdata参数指定配置脚本。

As with a standalone EC2 instance, you have the option of configuring instances launched into an Auto Scaling group using user data. For example, you can specify a configuration script using the User data field in the AWS Management Console, or the --userdata parameter in the AWS CLI.

如果您有软件不能使用配置脚本安装的软件,或者如果您需要在Auto Scaling将实例添加到组之前手动修改软件,请向Auto Scaling组添加生命周期挂钩,以在Auto Scaling组启动实例时通知您。在安装和配置其他软件时,该挂钩将实例保持在Pending:Wait状态。

If you have software that can't be installed using a configuration script, or if you need to modify software manually before Auto Scaling adds the instance to the group, add a lifecycle hook to your Auto Scaling group that notifies you when the Auto Scaling group launches an instance. This hook keeps the instance in the Pending:Wait state while you install and configure the additional software.

看起来像我不在这个案例。同样,修改userdata脚本上的挂起钩子也很复杂。必须有一个简单的解决方案来解决我的问题。

Looks like i'm not in this case. Also, modify the pending hook on the userdata script is complicated. There must be a simple solution to fix my problem.

谢谢您的帮助!

推荐答案

@Brooks说,在ELB服务实例之前等待的最简单方法是处理ELB的健康状况。

@Brooks said the easiest way to "wait" before the ELB serve the instance is to deal with ELB health status.

我解决了我的问题通过在userdata脚本的开头关闭http服务器。因此ELB不会具有绿色的健康状态,并且不会将客户端发送到该实例。我在脚本结尾重新启动了http服务器,由于运行状况良好,因此ELB可以为它提供服务。

I solved my problem by shutting down the http server at the start of the userdata script. So the ELB can't have a green health status, and it does not send clients to the instance. I re-start the http server at the end of the script, the health is good so the ELB serve it.

这篇关于由于userdata脚本,AWS自动缩放启动了未就绪的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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