我通过将 shell 脚本粘贴到用户数据字段来初始化运行标准 Ubuntu 13.04 AMI 的衍生产品的现场实例。
这行得通。脚本运行。但是调试起来很困难,因为我不知道脚本的输出记录在哪里,如果在任何地方的话。
我查看了 /var/log/cloud-init.log,它似乎包含一堆与调试 cloud-init 本身相关的内容,但与我的脚本无关。我在 /var/log 中搜索并没有发现任何东西。
我需要做一些特别的事情来打开登录吗?
我通过将 shell 脚本粘贴到用户数据字段来初始化运行标准 Ubuntu 13.04 AMI 的衍生产品的现场实例。
这行得通。脚本运行。但是调试起来很困难,因为我不知道脚本的输出记录在哪里,如果在任何地方的话。
我查看了 /var/log/cloud-init.log,它似乎包含一堆与调试 cloud-init 本身相关的内容,但与我的脚本无关。我在 /var/log 中搜索并没有发现任何东西。
我需要做一些特别的事情来打开登录吗?
云初始化用户数据的默认位置已经/var/log/cloud-init-output.log
在 AWS、DigitalOcean 和大多数其他云提供商中。您无需设置任何其他日志记录即可查看输出。
您可以为您的用户数据创建一个云配置文件(顶部带有“#cloud-config”),使用 runcmd 调用脚本,然后像这样启用输出日志记录:
output: {all: '| tee -a /var/log/cloud-init-output.log'}
so I tried to replicate your problem. Usually I work in Cloud Config and therefore I just created a simple test user-data script like this:
#!/bin/sh
echo "Hello World. The time is now $(date -R)!" | tee /root/output.txt
echo "I am out of the output file...somewhere?"
yum search git # just for fun
ls
exit 0
Notice that, with CloudInit shell scripts, the user-data "will be executed at rc.local-like level during first boot. rc.local-like means 'very late in the boot sequence'" After logging in into my instance (a Scientific Linux machine) I first went to /var/log/boot.log and there I found:
Hello World. The time is now Wed, 11 Sep 2013 10:21:37 +0200! I am
out of the file. Log file somewhere? Loaded plugins: changelog, kernel-module, priorities, protectbase, security, : tsflags, versionlock 126 packages excluded due to repository priority protections 9 packages excluded due to repository protections ^Mepel/pkgtags
| 581 kB 00:00=============================== N/S Matched: git =============================== ^[[1mGit^[[0;10mPython.noarch : Python ^[[1mGit^[[0;10m Library c^[[1mgit^[[0;10m.x86_64 : A fast web interface for ^[[1mgit^[[0;10m
...
... (more yum search output)
...
bin etc lib lost+found mnt proc sbin srv tmp var
boot dev home lib64 media opt root selinux sys usr
(other unrelated stuff)
So, as you can see, my script ran and was rightly logged. Also, as expected, I had my forced log 'output.txt' in /root/output.txt with the content:
Hello World. The time is now Wed, 11 Sep 2013 10:21:37 +0200!
So...I am not really sure what is happening in you script. Make sure you're exiting the script with
exit 0 #or some other code
If it still doesn't work, you should provide more info, like your script, your boot.log, your /etc/rc.local, and your cloudinit.log. btw: what is your cloudinit version?