Cloud-Init

Cloud-init 找不到元數據伺服器(Openstack)

  • November 29, 2018

我試圖了解為什麼我的伺服器無法連接到元數據伺服器(因此無法使用 SSH 密鑰登錄)。

網上類似的問題似乎是由安全組問題引起的,我相信不是這裡的問題。

它是單個主機,IP 為192.168.160.100. 來賓被分配了一個固定的 IP 10.225.134.63。該網路有一個 neutron DHCP 伺服器,位於10.225.134.64.

在主機上,我執行了以下命令,

# curl http://192.168.160.100:8775
1.0
...
2008-09-01
2009-04-04

# curl http://169.254.169.254
curl: (7) Failed connect to 169.254.169.254:80; No route to host

/etc/neutron/metadata_agent.ini

nova_metadata_ip = 192.168.160.100

/etc/nova/nova.conf

metadata_host=192.168.160.100

啟動日誌

cloud-init[827]: Cloud-init v. 0.7.5 running 'init' at Fri, 29 Sep 2017 09:50:08 +0000. Up 6.40 seconds.
cloud-init[827]: ci-info: +++++++++++++++++++++++++++Net device info+++++++++++++++++++++++++++
cloud-init[827]: ci-info: +--------+------+---------------+---------------+-------------------+
cloud-init[827]: ci-info: | Device |  Up  |    Address    |      Mask     |     Hw-Address    |
cloud-init[827]: ci-info: +--------+------+---------------+---------------+-------------------+
cloud-init[827]: ci-info: |  lo:   | True |   127.0.0.1   |   255.0.0.0   |         .         |
cloud-init[827]: ci-info: | eth0:  | True | 10.225.134.63 | 255.255.240.0 | fa:16:3e:0b:36:43 |
cloud-init[827]: ci-info: +--------+------+---------------+---------------+-------------------+
cloud-init[827]: ci-info: ++++++++++++++++++++++++++++++++Route info+++++++++++++++++++++++++++++++++
cloud-init[827]: ci-info: +-------+--------------+--------------+---------------+-----------+-------+
cloud-init[827]: ci-info: | Route | Destination  |   Gateway    |    Genmask    | Interface | Flags |
cloud-init[827]: ci-info: +-------+--------------+--------------+---------------+-----------+-------+
cloud-init[827]: ci-info: |   0   |   0.0.0.0    | 10.225.128.1 |    0.0.0.0    |    eth0   |   UG  |
cloud-init[827]: ci-info: |   1   | 10.225.128.0 |   0.0.0.0    | 255.255.240.0 |    eth0   |   U   |
cloud-init[827]: ci-info: +-------+--------------+--------------+---------------+-----------+-------+

cloud-init[827]: url_helper.py[WARNING]: Calling 'http://169.254.169.254/2009-04-04/meta-data/instance-id' failed [50/120s]: unexpected error ['NoneType' object has no attribute 'status_code']
cloud-init[827]: url_helper.py[WARNING]: Calling 'http://169.254.169.254/2009-04-04/meta-data/instance-id' failed [101/120s]: unexpected error ['NoneType' object has no attribute 'status_code']
cloud-init[827]: url_helper.py[WARNING]: Calling 'http://169.254.169.254/2009-04-04/meta-data/instance-id' failed [119/120s]: unexpected error ['NoneType' object has no attribute 'status_code']
cloud-init[827]: DataSourceEc2.py[CRITICAL]: Giving up on md from ['http://169.254.169.254/2009-04-04/meta-data/instance-id'] after 120 seconds
cloud-init[827]: url_helper.py[WARNING]: Calling 'http://10.225.134.64//latest/meta-data/instance-id' failed [0/120s]: unexpected error ['NoneType' object has no attribute 'status_code']
cloud-init[827]: url_helper.py[WARNING]: Calling 'http://10.225.134.64//latest/meta-data/instance-id' failed [1/120s]: unexpected error ['NoneType' object has no attribute 'status_code']
cloud-init[827]: url_helper.py[WARNING]: Calling 'http://10.225.134.64//latest/meta-data/instance-id' failed [2/120s]: unexpected error ['NoneType' object has no attribute 'status_code']
...
cloud-init[827]: url_helper.py[WARNING]: Calling 'http://10.225.134.64//latest/meta-data/instance-id' failed [119/120s]: unexpected error ['NoneType' object has no attribute 'status_code']
cloud-init[827]: DataSourceCloudStack.py[CRITICAL]: Giving up on waiting for the metadata from   ['http://10.225.134.64//latest/meta-data/instance-id'] after 126 seconds

事實證明,管理網路命名空間中缺少一些路由。它們是使用以下命令添加的。

# Where,
#  Management network ID = qdhcp-88d57d45-e9y4-4b4c-ae8a-4d5d6654e7fa
#  Management network device = tap54ff6yfd-fb
#    from `sudo ip netns exec qdhcp-88d57d45-e9y4-4b4c-ae8a-4d5d6654e7fa ip addr`
sudo ip netns exec qdhcp-88d57d45-e9y4-4b4c-ae8a-4d5d6654e7fa ip route add 169.254.0.0/16 dev  tap54ff6yfd-fb  proto kernel  scope link  src 169.254.169.254
sudo ip netns exec qdhcp-88d57d45-e9y4-4b4c-ae8a-4d5d6654e7fa ip addr add 169.254.169.254/16 brd 169.254.255.255 scope global dev tap54ff6yfd-fb

引用自:https://serverfault.com/questions/876165