用户数据的脚本是不是在我的自定义AMI运行,但在标准的Linux亚马逊工作 [英] User-data scripts is not running on my custom AMI, but working in standard Amazon linux

查看:210
本文介绍了用户数据的脚本是不是在我的自定义AMI运行,但在标准的Linux亚马逊工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了很多话题关于用户数据的脚本不能正常工作,在这几天里,但到现在为止,我还没有得到有关我的情况下,任何的想法呢,请大家帮我弄清楚发生了什么,谢谢很多!

I searched a lot of topic about "user-data script is not working" in these few days, but until now, I haven't gotten any idea about my case yet, please help me to figure out what happened, thanks a lot!

据AWS 用户数据的解释:

当你推出的Amazon EC2实例,你必须传递用户数据,可用于执行常见自动配置任务,甚至运行脚本实例启动后,该实例的选项。

When you launch an instance in Amazon EC2, you have the option of passing user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts.

所以,我想通过我自己的用户数据时,例如推出,这是我的用户数据:

So I tried to pass my own user-data when instance launch, this is my user-data:

#!/斌/ bash的

#!/bin/bash

回声测试> /home/ec2-user/user-script-output.txt

echo 'test' > /home/ec2-user/user-script-output.txt

但是,在这个路径中没有文件:/home/ec2-user/user-script-output.txt

But there is no file in this path: /home/ec2-user/user-script-output.txt

我查/var/lib/cloud/instance/user-data.txt,该文件存在,并且同我的用户数据的脚本。

I checked /var/lib/cloud/instance/user-data.txt, the file is exist and same as my user-data script.

此外,我查了日志中/var/log/cloud-init.log,没有错误消息。

Also I checked the log in /var/log/cloud-init.log, there is no error message.

但用户数据脚本工作,如果我启动与亚马逊的Linux(2014年9月1日),一个新的实例,但我不知道有什么区别我的AMI之间(根据亚马逊的Linux)和Amazon Linux操作系统。

But the user-data script is working if I launch an new instance with Amazon linux(2014.09.01), but I'm not sure what difference between my AMI(based on Amazon linux) and Amazon linux.

唯一的不同部分,我看到的是,如果我运行此脚本:

The only different part I saw is if I run this script:

须藤yum的安装列表| grep的云初始化

sudo yum list installed | grep cloud-init

我的AMI:

云init.noarch 0.7.2-8.33.amzn1 @ AMZN-主

cloud-init.noarch 0.7.2-8.33.amzn1 @amzn-main

亚马逊的Linux:

云init.noarch 0.7.2-8.33.amzn1安装

cloud-init.noarch 0.7.2-8.33.amzn1 installed

我不知道这是什么原因呢?

I'm not sure this is the reason?

如果您需要更多的信息,我很高兴提供,请让我知道发生了什么事我自己的AMI,以及如何解决它?

If you need more information, I'm glad to provide, please let me know what happened in my own AMI and how to fix it?

非常感谢

更新

刚刚发现这个答案<一href="http://stackoverflow.com/questions/25497689/how-to-make-ec2-user-data-work-on-freshly-built-ami-made-with-packer">post,

如果我的用户数据文件的顶部添加#云boothook,它的作品!

If I add #cloud-boothook in the top of user-data file, it works!

#cloud-boothook
#!/bin/bash
echo 'test' > /home/ec2-user/user-script-output.txt

但还是不知道为什么。

But still not sure why.

推荐答案

据我测试过,有在的/ var / lib中/云目录中的一些引导数据。 之后我清除该目录,用户数据脚本正常工作。

As I tested, there were some bootstrap data in /var/lib/cloud directory. After I cleared that directory, User Data script worked normally.

rm -rf /var/lib/cloud/*

这篇关于用户数据的脚本是不是在我的自定义AMI运行,但在标准的Linux亚马逊工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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