1、查看 openstack版本信息,以下命令是在 queen版本下执行没有问题。
[root@node151 ~]# openstack --version openstack 3.14.3
2、查看网络接口信息
[root@node151 ~]# neutron port-list
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
+--------------------------------------+------+----------------------------------+-------------------+--------------------------------------------------------------------------------------+
| id | name | tenant_id | mac_address | fixed_ips |
+--------------------------------------+------+----------------------------------+-------------------+--------------------------------------------------------------------------------------+
| 07e18a76-75c2-484e-8303-ee46b3807432 | | fd005a957841453589dbe446e4a5698b | fa:16:3e:1c:ad:ad | {"subnet_id": "b8a9d01c-f547-45c3-a0d4-da7ae1494766", "ip_address": "192.168.1.158"} |
| 37b84033-584e-4fca-b66b-29784ab1cc6b | | 8e4dd46886834371b71984245a143f58 | fa:16:3e:10:c5:81 | {"subnet_id": "b8a9d01c-f547-45c3-a0d4-da7ae1494766", "ip_address": "192.168.1.159"} |
| 90f0a883-5baf-4b38-b9a6-739e5fd0e5d2 | | 8e4dd46886834371b71984245a143f58 | fa:16:3e:b7:03:80 | {"subnet_id": "b8a9d01c-f547-45c3-a0d4-da7ae1494766", "ip_address": "192.168.1.157"} |
| f3bebead-0e94-4909-8a00-ce43a2fc243a | | 8e4dd46886834371b71984245a143f58 | fa:16:3e:56:46:33 | {"subnet_id": "b8a9d01c-f547-45c3-a0d4-da7ae1494766", "ip_address": "192.168.1.156"} |
| fc2b1a37-4486-4516-96cd-bedc6f585395 | | 8e4dd46886834371b71984245a143f58 | fa:16:3e:09:e9:cc | {"subnet_id": "b8a9d01c-f547-45c3-a0d4-da7ae1494766", "ip_address": "192.168.1.155"} |
+--------------------------------------+------+----------------------------------+-------------------+--------------------------------------------------------------------------------------+
3、查看网络信息
[root@node151 ~]# neutron net-list neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead. +--------------------------------------+----------+----------------------------------+-----------------------------------------------------+ | id | name | tenant_id | subnets | +--------------------------------------+----------+----------------------------------+-----------------------------------------------------+ | b79db6a0-b74d-48b8-95e8-8260eaf81b70 | provider | 8e4dd46886834371b71984245a143f58 | b8a9d01c-f547-45c3-a0d4-da7ae1494766 192.168.1.0/24 | +--------------------------------------+----------+----------------------------------+-----------------------------------------------------+
4、创建网络接口指定ip地址、网络信息
neutron port-create --fixed-ip subnet_id=<替换为上一步获取到的 subnets>,ip_address=<替换为指定的IP> <替换为上一步的网络ID>
[root@node151 ~]# neutron port-create --fixed-ip subnet_id=b8a9d01c-f547-45c3-a0d4-da7ae1494766,ip_address=192.168.1.168 b79db6a0-b74d-48b8-95e8-8260eaf81b70
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
Created a new port:
+-----------------------+--------------------------------------------------------------------------------------+
| Field | Value |
+-----------------------+--------------------------------------------------------------------------------------+
| admin_state_up | True |
| allowed_address_pairs | |
| binding:host_id | |
| binding:profile | {} |
| binding:vif_details | {} |
| binding:vif_type | unbound |
| binding:vnic_type | normal |
| created_at | 2021-08-31T05:56:35Z |
| description | |
| device_id | |
| device_owner | |
| extra_dhcp_opts | |
| fixed_ips | {"subnet_id": "b8a9d01c-f547-45c3-a0d4-da7ae1494766", "ip_address": "192.168.1.168"} |
| id | cd86f69a-4779-4a46-a0ea-eed76f176237 |
| mac_address | fa:16:3e:e9:76:dc |
| name | |
| network_id | b79db6a0-b74d-48b8-95e8-8260eaf81b70 |
| port_security_enabled | True |
| project_id | 8e4dd46886834371b71984245a143f58 |
| revision_number | 6 |
| security_groups | c1e53d26-8525-4ebb-8305-e82e54b27ed5 |
| status | DOWN |
| tags | |
| tenant_id | 8e4dd46886834371b71984245a143f58 |
| updated_at | 2021-08-31T05:56:35Z |
+-----------------------+--------------------------------------------------------------------------------------+
5、将新增加的接口,绑定到对应的vm上
5.1 查看虚拟机信息
[root@node151 ~]# nova list +--------------------------------------+---------------+---------+------------+-------------+------------------------+ | ID | Name | Status | Task State | Power State | Networks | +--------------------------------------+---------------+---------+------------+-------------+------------------------+ | a02050c0-ed9a-4fb1-93e9-595a57bb654e | centos-1 | ACTIVE | - | Running | provider=192.168.1.156 | | de86908f-91fb-48a7-8b69-1d07d8c3aea0 | centos-2 | SHUTOFF | - | NOSTATE | provider=192.168.1.159 | | 371fe316-7db5-4781-987f-e0b514d525bd | centos-3 | ACTIVE | - | Running | | +--------------------------------------+---------------+---------+------------+-------------+------------------------+
5.2 绑定vm机
nova interface-attach --port-id <替换为上一步的网络接口ID> <替换为上一步的虚拟机的ID>
[root@node151 ~]# nova interface-attach --port-id cd86f69a-4779-4a46-a0ea-eed76f176237 371fe316-7db5-4781-987f-e0b514d525bd [root@node151 ~]# nova list +--------------------------------------+---------------+---------+------------+-------------+------------------------+ | ID | Name | Status | Task State | Power State | Networks | +--------------------------------------+---------------+---------+------------+-------------+------------------------+ | a02050c0-ed9a-4fb1-93e9-595a57bb654e | centos-1 | ACTIVE | - | Running | provider=192.168.1.156 | | de86908f-91fb-48a7-8b69-1d07d8c3aea0 | centos-2 | SHUTOFF | - | NOSTATE | provider=192.168.1.159 | | 371fe316-7db5-4781-987f-e0b514d525bd | centos-3 | ACTIVE | - | Running | provider=192.168.1.168 | | f3419061-97ca-4846-b667-0672ea2f8ca4 | centos6.9-tpl | SHUTOFF | - | Shutdown | provider=192.168.1.157 | +--------------------------------------+---------------+---------+------------+-------------+------------------------+
6、重启查看虚拟机,网络接口已经绑定上
如果网卡信息显示不一致,通过console登录修改网卡名称 ,以centos6 为列
[root@t168 ~]# more /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x1af4:0x1000 (virtio-pci)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="fa:16:3e:b7:03:80", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"