OpenStack重启节点导致实例获取不到IP地址

时间:2023-01-09 00:21:12

问题描述:完成环境搭建后实例访问外网正常,但重启openstack所有节点后实例IP地址丢失,而且无法自动获取,各个代理组件正常,日志未发现异常error。
原因分析:虚拟机mac地址跟其他设备冲突,导致交换上出错?关于mac地址,使用neutron port-list 可以看到所有port的mac地址。
解决方法:删除实例对应的网络,然后新建网络,重新把实例连接到新建网络上,并且修改实例IP地址,对于centos.qcow2创建的实例直接console登录虚拟机改为静态IP地址即可,对于cirros镜像创建的虚拟机我使用下面的方法修改IP地址:

1.首先根据虚拟机名称,查找一下虚拟机ID


[root@controller ~]# 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

[root@controller ~]# 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>
[root@controller ~]# 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地址

[root@controller ~]# 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登录实例测试外网连通性

[root@controller ~]# ssh cirros@192.168.92.85
$ 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