cloud-init 手动调试及问题解决
一. 参考资料
http://note.youdao.com/yws/public/redirect/share?id=6cd0a9dc3a6a19ad3821bff5b87e37df&type=false
使用cloud-init实现虚拟机信息管理
Pastedfrom <http://blog.csdn.net/jmppok/article/details/46521439>
OpenStack的 metadata 服务机制
Pastedfrom <http://www.ibm.com/developerworks/cn/cloud/library/1509_liukg_openstackmeta/index.html>
二. 手动调试cloud-init方法I
How to run cloud-init manually
1)
$rm -rf/var/lib/cloud/*
OR
$rm -rf/var/lib/cloud/sem/* /var/lib/cloud/instance /var/lib/cloud/instances/*
2)
$cloud-initinit
$cloud-initmodules -m final
3)
$tail -f/var/log/cloud-init.log
$tail -f/var/log/cloud-init-output.log
Pastedfrom <http://fosshelp.blogspot.com/2015/10/how-to-run-cloud-init-manually.html>
三. 手动调试cloud-init方法II
Re-execute or debugging
The script only runs at first boot of the machine viacloud-init. If you execute thecloud-init command again it will not execute the script because it already did it. Testing and debugging the script can be quite intensive if you need to bootup a machine every time.
We can however foolcloud-init by letting it think the machine did a fresh first boot. We need to remove thefollowing two files:
/var/lib/cloud/instances/$UUID/boot-finished
/var/lib/cloud/instances/$UUID/sem/config_scripts_user
Replace$UUID by your instance's UUID.
Execute thefollowing command to run the cloud-init final module again:
cloud-init modules --mode final
Thefinal module will execute ouruser_data script again. Before every newtest run you need to remove the two files listed above.
Keep in mind as wellthat if you for example touch a file and run the script again, the file willstill be there. Changes are persistent, build your code idempotent so that ithandles that.
If you've byaccident deleted to much cloud-init data you can re-initialize it with thefollowing command:
cloud-init init
四. cloud-init配置
cloud-init configuration
vi /etc/cloud.cfg
user: cloud
disable_root: 1
preserve_hostname: False
五. 数据源的选择
确认cloud-init使用的是“EC2"的data source(ubuntu only)
dpkg-reconfgure cloud-init
六. 遇到的问题
1. 无法把user-data中的内容写入虚机
通过route -n查看一下,路由表中是否有169.254.169.254这和条路由信息
如果没有,可以用下面的这命令加上:
route add -host 169.254.169.254 dev eth0(其中eth0是设备名字,可以根据实际情况选用)
上面这个命令在重启后会消失,故可以把上面的的命令加到/etc/rc.local中,避免重启机器后失效。
上面的命令也可以加到ifcfg-ethx的配置文件中,如下:
auto ethx
iface ethx inet dhcp
up route add -host 169.254.169.254 dev ethx