Ref>
http://www.vpsee.com/2011/11/how-to-solve-datasourceec2-pywarning-http169-254-169-254-failed-url-error-problem/
解决 DataSourceEc2.py[WARNING]: ‘http://169.254.169.254′ failed: url error 问题
2011年11月1日 | 标签: openstack nova | 作者:vpsee
上周在一台 Ubuntu 11.10 服务器上安装和配置 OpenStack Nova 后,上传一个从 Ubuntu 官方下载的 oneiric-server-cloudimg-amd64.tar.gz 模板,然后启动一个 Ubuntu 11.10 实例(instance)的时候过了很长时间才能从 vnc 看到 Ubuntu login: 界面,打印出终端输出结果如下,貌似系统多次尝试从 http://169.254.169.254 得到 metadata 失败:
# euca-run-instances -k vpsee -t m1.tiny ami-00000002
# euca-get-console-output i-00000128
...
[ 0.980222] init: lxcguest pre-start process (57) terminated with status 1
cloud-init start-local running: Mon, 24 Oct 2011 13:19:49 +0000. up 2.61 seconds
no instance data found in start-local
ci-info: lo : 1 127.0.0.1 255.0.0.0
ci-info: eth0 : 1 172.16.38.2 255.255.254.0 02:16:3e:4f:61:4e
ci-info: route-0: 0.0.0.0 172.16.38.1 0.0.0.0 eth0 UG
ci-info: route-1: 172.16.38.0 0.0.0.0 255.255.254.0 eth0 U
cloud-init start running: Mon, 24 Oct 2011 13:19:52 +0000. up 5.23 seconds
2011-10-24 13:19:55,312 - DataSourceEc2.py[WARNING]: 'http://169.254.169.254' failed: url error [timed out]
2011-10-24 13:19:59,321 - DataSourceEc2.py[WARNING]: 'http://169.254.169.254' failed: url error [timed out]
2011-10-24 13:20:31,944 - DataSourceEc2.py[CRITICAL]: giving up on md after 208 seconds
...
找了一下资料发现网上有人用绑定 169.254.169.254 到 eth0 的办法,不过 VPSee 试了行不通。
$ sudo ip addr add 169.254.169.254/32 scope link dev eth0
metadata 的转发需要网关来完成,但是从下面的代码(nova/network/linux_net.py)来看,nova 只在 FlatDHCPManager 和 VlanManager 网络模式下调用 metadata_forward() 函数,nova 在 FlatManager 网络模式下不做任何设置,所以需要手动配置 iptable 转发 169.254.169.254 的 80 端口到 nova api 服务器上(网关)。
def metadata_forward():
"""Create forwarding rule for metadata"""
_confirm_rule("PREROUTING", "-t nat -s 0.0.0.0/0 "
"-d 169.254.169.254/32 -p tcp -m tcp --dport 80 -j DNAT "
"--to-destination %s:%s" % (FLAGS.ec2_dmz_host, FLAGS.ec2_port))
所以解决办法有两个,要么在网关(nova api 所运行的服务器)上手动运行 iptable 定向端口:
$ sudo iptables -t nat -A PREROUTING -d 169.254.169.254/32 -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.39.110:8773
要么改变 nova.conf 配置使用 FlatDHCPManager 模式:
$ sudo vi /etc/nova/nova.conf
--daemonize=1
--dhcpbridge_flagfile=/etc/nova/nova.conf
--dhcpbridge=/usr/bin/nova-dhcpbridge
--logdir=/var/log/nova
--state_path=/var/lib/nova
--lock_path=/var/lock/nova
--verbose
--ec2_host=http://172.16.39.110
--osapi_host=http://172.16.39.110
--rabbit_host=172.16.39.110
--glance_api_server=172.16.39.110:9292
--routing_source_ip=172.16.39.110
--sql_connection=mysql://vpsee:vpsee@172.16.39.110/nova
--image_service=nova.image.glance.GlanceImageService
--network_manager=nova.network.manager.FlatDHCPManager
--fixed_range=172.16.38.0/23
--flat_interface=dummy0
--public_interface=eth0
重启 nova 各个服务以后再重新启动一个新 instance 并输出 console:
# euca-run-instances -k vpsee -t m1.tiny ami-00000002
# euca-describe-instances
RESERVATION r-0xzn6el3 cloud default
INSTANCE i-00000215 ami-00000002 172.16.39.121 172.16.39.121 running vpsee (cloud, cloud00) 0 m1.tiny 2011-10-28T12:46:52Z nova aki-00000001 ami-00000000
# euca-get-console-output i-00000215
...
cloud-init start-local running: Fri, 28 Oct 2011 12:47:05 +0000. up 2.94 seconds
no instance data found in start-local
ci-info: lo : 1 127.0.0.1 255.0.0.0
ci-info: eth0 : 1 172.16.39.121 255.255.254.0 02:16:3e:6d:9b:b6
ci-info: route-0: 0.0.0.0 172.16.38.1 0.0.0.0 eth0 UG
ci-info: route-1: 172.16.38.0 0.0.0.0 255.255.254.0 eth0 U
cloud-init start running: Fri, 28 Oct 2011 12:47:08 +0000. up 5.49 seconds
found data source: DataSourceEc2
Generating public/private rsa key pair.
...
最后用 ssh 登录刚启动的 instance 测试一下,很多朋友在这篇文章的 评论里问到“我的 instance 可以 ping 通,为啥不能 ssh?”的问题,可能是 ssh 的时候忘了带上 key。需要注意的是 cloud-init 这个脚本在启动 instance 后自动把 ssh 密钥注射到了 instance,ssh 的时候需要带上 vpsee.pem(还记得启动的时候用了 # euca-run-instances -k vpsee …吗?),还需要注意的是 Ubuntu 官方下载的 oneiric-server-cloudimg-amd64.tar.gz 模板的默认用户名是 ubuntu(不是 root),不需要密码登录(用 ssh key 登录):
# ssh -i vpsee.pem ubuntu@172.16.39.121
Welcome to Ubuntu 11.10 (GNU/Linux 3.0.0-12-virtual x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Fri Oct 28 10:29:14 UTC 2011
System load: 0.0 Processes: 54
Usage of /: 46.2% of 1.35GB Users logged in: 0
Memory usage: 8% IP address for eth0: 172.16.39.121
Swap usage: 0%
Graph this data and manage this system at https://landscape.canonical.com/
Get cloud support with Ubuntu Advantage Cloud Guest
http://www.ubuntu.com/business/services/cloud
To run a command as administrator (user "root"), use "sudo ".
See "man sudo_root" for details.
ubuntu@server-24:~$
沒有留言:
張貼留言