1. 程式人生 > >OpenStack重啟節點導致例項獲取不到IP地址

OpenStack重啟節點導致例項獲取不到IP地址

問題描述:完成環境搭建後例項訪問外網正常,但重啟openstack所有節點後例項IP地址丟失,而且無法自動獲取,各個代理元件正常,日誌未發現異常error。
原因分析:虛擬機器mac地址跟其他裝置衝突,導致交換上出錯?關於mac地址,使用neutron port-list 可以看到所有port的mac地址。
解決方法:刪除例項對應的網路,然後新建網路,重新把例項連線到新建網路上,並且修改例項IP地址,對於centos.qcow2建立的例項直接console登入虛擬機器改為靜態IP地址即可,對於cirros映象建立的虛擬機器我使用下面的方法修改IP地址:

1.首先根據虛擬機器名稱,查詢一下虛擬機器ID


[[email protected] ~]# nova list --all-tenant |grep vm2
| a53f8d1a-9d1f-4a81-bb04-94b8aef89adc | vm2                    | f3f0c1a2a9f74aa6ac030671f4c7ec33 | ACTIVE | -          | Running     | selfservice1=172.16.1.4, 192.168.92.81   |

2. 根據虛擬機器ID查詢虛擬機器的Port

[[email protected] ~]# nova interface-list a53f8d1a-9d1f-4a81-bb04-94b8aef89adc 
+------------+
--------------------------------------+--------------------------------------+--------------+-------------------+ | Port State | Port ID | Net ID | IP addresses | MAC Addr | +------------+--------------------------------------+--------------------------------------+--------------+-------------------+
| ACTIVE | b9e0b171-f80b-4545-8a2e-81450113cf12 | 0e728aa4-d9bd-456b-ba0b-dd7df5e15c96 | 172.16.1.4 | fa:16:3e:0d:15:46 | +------------+--------------------------------------+--------------------------------------+--------------+-------------------+

3. 將虛擬機器下電nova stop (server)

[root@controller ~]# nova stop a53f8d1a-9d1f-4a81-bb04-94b8aef89adc
Request to stop server a53f8d1a-9d1f-4a81-bb04-94b8aef89adc has been accepted.

4. detach 網口 命令格式:nova interface-detach (server) (port_id)

[root@controller ~]# nova interface-detach a53f8d1a-9d1f-4a81-bb04-94b8aef89adc b9e0b171-f80b-4545-8a2e-81450113cf12

5. 重新給虛擬機器attach網口。 使用net 熱插拔時,會重新建立port時,不會使用原來的mac地址。

nova interface-attach [--port-id <port_id>] [--net-id <net_id>]
                      [--fixed-ip <fixed_ip>]
                      <server>
[[email protected] ~]# nova interface-attach --net-id 0e728aa4-d9bd-456b-ba0b-dd7df5e15c96 --fixed-ip 172.16.1.5 a53f8d1a-9d1f-4a81-bb04-94b8aef89adc

這裡會重新建立 port,新建立port的mac地址會重新分配。

6. 虛擬機器上電

[root@controller ~]# nova start a53f8d1a-9d1f-4a81-bb04-94b8aef89adc
Request to start server a53f8d1a-9d1f-4a81-bb04-94b8aef89adc has been accepted.
nova start de4633b4-8a5d-4b00-9780-7d39a69cefa7

7檢視虛擬機器介面配置的IP地址

[[email protected] ~]# nova interface-list a53f8d1a-9d1f-4a81-bb04-94b8aef89adc 
+------------+--------------------------------------+--------------------------------------+--------------+-------------------+
| Port State | Port ID                              | Net ID                               | IP addresses | MAC Addr          |
+------------+--------------------------------------+--------------------------------------+--------------+-------------------+
| ACTIVE     | 2386a1a4-85d2-46de-9734-ef65290c436a | 0e728aa4-d9bd-456b-ba0b-dd7df5e15c96 | 172.16.1.5   | fa:16:3e:e8:82:27 |
+------------+--------------------------------------+--------------------------------------+--------------+-------------------+

8.繫結浮動ip192.168.92.85,ssh登入例項測試外網連通性

[[email protected] ~]# ssh [email protected]
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc pfifo_fast qlen 1000
    link/ether fa:16:3e:e8:82:27 brd ff:ff:ff:ff:ff:ff
    inet 172.16.1.5/24 brd 172.16.1.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fee8:8227/64 scope link 
       valid_lft forever preferred_lft forever
$ ping 192.168.92.2
PING 192.168.92.2 (192.168.92.2): 56 data bytes
64 bytes from 192.168.92.2: seq=0 ttl=127 time=1.135 ms
64 bytes from 192.168.92.2: seq=1 ttl=127 time=2.082 ms
64 bytes from 192.168.92.2: seq=2 ttl=127 time=1.929 ms
64 bytes from 192.168.92.2: seq=3 ttl=127 time=1.441 ms

參考來源:https://blog.csdn.net/u011211976/article/details/78496402