openstack 3.14.3 虛擬機器增加指定IP網絡卡
阿新 • • 發佈:2021-09-01
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"