AWS EC2 UserData脚本在t3实例上不触发

问题描述 投票:0回答:1

我有一个漂亮的simple userdata script,它在ubuntu上安装了CodeDeploy代理,然后向CloudFormation发出一个信号,指示实例运行状况良好。我的堆栈是使用CloudFormation部署的,它会设置ASG,LaunchTemplate,TargetGroup等。目标实例类型为t3.small实例上的Ubuntu 18.04(ami-07ebfd5b3428b6f4d AMI)。我以前在不同的AMI上也遇到了同样的问题,但是升级到ami-07ebfd5b3428b6f4d似乎可以暂时解决此问题...它工作了几个星期。

最近,我的ASG试图替换一些不正常的实例,但是新实例没有出现。在进一步调查中,我发现我又回到了同样的问题-用户数据脚本未触发。 cloud-init.log结尾于此行:

2020-03-20 01:23:56,741 - util.py[DEBUG]: Running command ['/var/lib/cloud/instance/scripts/part-001'] with allowed return codes [0] (shell=False, capture=False)

但是似乎挂在这里,系统日志中没有任何活动。日志中的该文件正确包含了按脚本,如果我手动调用该脚本,则该脚本将成功执行(无需任何交互)。

更改我的CloudFormation堆栈以改为使用t2实例即可解决此问题。我已经保留了t3的容量,因此我需要回到t3。

有想法/想法吗?

根据评论进行更新。这是cloud-init-output.log的最后几行:

Setting up apport (2.20.9-0ubuntu7.12) ...
Installing new version of config file /etc/init.d/apport ...
apport-autoreport.service is a disabled or a static unit, not starting it.
Setting up ubuntu-standard (1.417.4) ...
Setting up grub-pc (2.02-2ubuntu8.15) ...
ESC[1;24rESC[4lESC)0ESC[mESC(BESC[1;24rESC[HESC[JESC[1;1HPackage configurationESC[3;2H┌──────────────────────────┤ Configuring grub-pc ├──────────────────────────┐ESC[4;2H│ESC[75C│ESC[5;2H│ The GRUB boot loader was previously installed to a disk that is noESC[8C│ESC[6;2H│ longer present, or whose unique identifier has ch
amazon-web-services ubuntu amazon-ec2 amazon-cloudformation aws-code-deploy
1个回答
0
投票

事实证明,非交互模式要求进行交互。不知道为什么会这样,或者为什么随后手动调用脚本没有表现出相同的行为。提示是cloud-init-output.log末尾出现乱码的日志消息(感谢@Marcin推动此操作)。

解决方法是将脚本顶部修改为如下所示:

export DEBIAN_FRONTEND=noninteractive
apt-get update 
apt-get -y upgrade 
apt-get install awscli python-pip -y
pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
apt-get autoremove 
apt-get autoclean
© www.soinside.com 2019 - 2024. All rights reserved.