【发布时间】:2017-10-16 06:11:48
【问题描述】:
我有一个AWS ECS 集群,为了方便用户访问,我使用OpsWorks 来获得它的ssh 功能。为了使堆栈始终保持向上,即使实例因任何原因终止,我依赖于使用特定 Launch Configuration 的 EC2 Auto Scaling Group,并且我在 User Data 字段上设置了以下内容:
#!/bin/bash
# This works just fine!
echo ECS_CLUSTER=my-cluster-name >> /etc/ecs/ecs.config
# Given AWS CLI is not installed by default
yum install -y awscli
# This is copied and pasted from the OpsWorks' Register Instance Wizard
aws opsworks register --infrastructure-class ec2 --region us-east-1 --stack-id aaa-bbb-ccc-ddd --local
为了调试,我已经准备好了set -x,并在注册工作之前给出了所有命令,这里是关于特定命令输出的相关日志:
+ aws opsworks register --use-instance-profile --infrastructure-class ec2 --region us-east-1 --stack-id aaa-bbb-ccc-ddd --override-hostname abcdefgh --local
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 7800k 100 7800k 0 0 12.3M 0 --:--:-- --:--:-- --:--:-- 12.3M
opsworks-init: Initializing AWS OpsWorks environment
opsworks-init: Checking if OS is supported
opsworks-init: Running on supported OS
opsworks-init: Setup motd
opsworks-init: Executing: ln -sf --backup /etc/motd.opsworks-static /etc/motd
opsworks-init: Using assets bucket from environment: 'opsworks-instance-assets-us-east-1.s3.amazonaws.com'.
opsworks-init: Installing Ruby for the agent
opsworks-init: Executing: /tmp/opsworks-agent-installer.ggXxYyMmBBH/opsworks-agent-installer/opsworks-agent/bin/installer_wrapper.sh -r -R opsworks-instance-assets-us-east-1.s3.amazonaws.com
我在这里的印象是最后一个命令静默失败,因为我希望在那之后注册会更加冗长。
在确保所有 IAM 角色和安全组都经过修改并且看起来都清晰且启动日志上没有显示明显错误之后,实例将根本不会注册。我已经尝试过遵循此Auto Scaling AWS OpsWorks instances 指南,但即使使用从那里提取的以下代码(并且在尝试了许多变体之后)它也不会注册:
#!/bin/bash
sed -i'' -e 's/.*requiretty.*//' /etc/sudoers
pip install --upgrade awscli
/usr/bin/aws opsworks register --use-instance-profile --infrastructure-class ec2 --region us-east-1 --stack-id aaa-bbb-ccc-ddd --override-hostname $(tr -cd 'a-z' < /dev/urandom |head -c8) --local
为了将新实例注册到OpsWorks 堆栈,我可能缺少什么线索?
非常感谢!
【问题讨论】:
标签: amazon-web-services autoscaling amazon-ecs user-data aws-opsworks