当前位置: > 其它学习 > OpenStack >

openstack 实例增加网卡

时间:2019-12-22 16:36来源:csdn.net 作者:IT
openstack中某个实例新增加一个网卡有两种方式

一种是用通过openstack增加

这种增加不但会增加一个虚拟网卡,还会自动分配一个ip

##设置环境变量

source .admin_openrc.sh

##查看网络

    neutron net-list
    neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
    +--------------------------------------+-------------+----------------------------------+------------------------------------------------------+
    | id                                   | name        | tenant_id                        | subnets                                              |
    +--------------------------------------+-------------+----------------------------------+------------------------------------------------------+
    | 763b1b5b-85d7-4101-a51b-d621931d15b8 | selfservice | 6f4b66aa95e84d7191d989a940830a95 | 936bc613-2c2c-447e-9936-137e3cd182fc 172.16.1.0/24   |
    | e035ec48-c7b7-414b-bc0c-117f0900e915 | provider    | 6f4b66aa95e84d7191d989a940830a95 | 3bc9c2bf-d4ed-4e61-88d5-2be2b4cc073e 192.168.96.0/21 |
    +--------------------------------------+-------------+----------------------------------+------------------------------------------------------+

##增加网络端口

    neutron port-create 763b1b5b-85d7-4101-a51b-d621931d15b8  ###可以指定ip哦
     
    +-----------------------+-----------------------------------------------------------------------------------+
    | Field                 | Value                                                                             |
    +-----------------------+-----------------------------------------------------------------------------------+
    | admin_state_up        | True                                                                              |
    | allowed_address_pairs |                                                                                   |
    | binding:host_id       | compute                                                                           |
    | binding:profile       | {}                                                                                |
    | binding:vif_details   | {"port_filter": true}                                                             |
    | binding:vif_type      | bridge                                                                            |
    | binding:vnic_type     | normal                                                                            |
    | created_at            | 2018-07-13T03:09:54Z                                                              |
    | description           |                                                                                   |
    | device_id             | 706d5c3b-0511-4bbf-b101-e1780c893b79                                              |
    | device_owner          | compute:nova                                                                      |
    | extra_dhcp_opts       |                                                                                   |
    | fixed_ips             | {"subnet_id": "936bc613-2c2c-447e-9936-137e3cd182fc", "ip_address": "172.16.1.7"} |
    | id                    | 4dfaaf48-0fd0-4a9d-82eb-a2190c5b8ff4                                              |
    | mac_address           | fa:16:3e:f4:50:fb                                                                 |
    | name                  |                                                                                   |
    | network_id            | 763b1b5b-85d7-4101-a51b-d621931d15b8                                              |
    | port_security_enabled | True                                                                              |
    | project_id            | 6f4b66aa95e84d7191d989a940830a95                                                  |
    | revision_number       | 7                                                                                 |
    | security_groups       | 48747bda-428d-423e-8a9f-b34d8c9318f8                                              |
    | status                | ACTIVE                                                                            |
    | tags                  |                                                                                   |
    | tenant_id             | 6f4b66aa95e84d7191d989a940830a95                                                  |
    | updated_at            | 2018-07-13T03:15:09Z                                                              |
    +-----------------------+-----------------------------------------------------------------------------------+

##查看看实例

    nova list --all
    +--------------------------------------+-----------+----------------------------------+--------+------------+-------------+-------------------------+
    | ID                                   | Name      | Tenant ID                        | Status | Task State | Power State | Networks                |
    +--------------------------------------+-----------+----------------------------------+--------+------------+-------------+-------------------------+
    | 1af14a6b-21e5-446c-b73e-0c1d73c293cb | 2         | 6f4b66aa95e84d7191d989a940830a95 | ACTIVE | -          | Running     | selfservice=172.16.1.10 |
    | 706d5c3b-0511-4bbf-b101-e1780c893b79 | centos7.3 | 6f4b66aa95e84d7191d989a940830a95 | ACTIVE | -          | Running     | selfservice=172.16.1.7  |
    +--------------------------------------+-----------+----------------------------------+--------+------------+-------------+-------------------------+

##为实例增加端口=增加虚拟网卡

nova interface-attach --port-id 4dfaaf48-0fd0-4a9d-82eb-a2190c5b8ff4 706d5c3b-0511-4bbf-b101-e1780c893b79^C

另外一种是直接用virsh attach-interface 增加

这种增加方式是跳过openstack ,直接kvm 方式增加,这种是单单增加一个虚拟网口,如果需要配置ip,得进入虚拟机增加ip

##查看看实例

    nova list --all
    +--------------------------------------+-----------+----------------------------------+--------+------------+-------------+-------------------------+
    | ID                                   | Name      | Tenant ID                        | Status | Task State | Power State | Networks                |
    +--------------------------------------+-----------+----------------------------------+--------+------------+-------------+-------------------------+
    | 1af14a6b-21e5-446c-b73e-0c1d73c293cb | 2         | 6f4b66aa95e84d7191d989a940830a95 | ACTIVE | -          | Running     | selfservice=172.16.1.10 |
    | 706d5c3b-0511-4bbf-b101-e1780c893b79 | centos7.3 | 6f4b66aa95e84d7191d989a940830a95 | ACTIVE | -          | Running     | selfservice=172.16.1.7  |
    +--------------------------------------+-----------+----------------------------------+--------+------------+-------------+-------------------------+

##查看实例详情,确定计算节点名称和实例名称

    nova show 706d5c3b-0511-4bbf-b101-e1780c893b79
    +--------------------------------------+---------------------------------------------------------------------------------+
    | Property                             | Value                                                                           |
    +--------------------------------------+---------------------------------------------------------------------------------+
    | OS-DCF:diskConfig                    | AUTO                                                                            |
    | OS-EXT-AZ:availability_zone          | nova                                                                            |
    | OS-EXT-SRV-ATTR:host                 | compute                                                                         |
    | OS-EXT-SRV-ATTR:hostname             | centos7.3                                                                       |
    | OS-EXT-SRV-ATTR:hypervisor_hostname  | compute                                                                         |
    | OS-EXT-SRV-ATTR:instance_name        | instance-00000004                                                               |
    | OS-EXT-SRV-ATTR:kernel_id            |                                                                                 |
    | OS-EXT-SRV-ATTR:launch_index         | 0                                                                               |
    | OS-EXT-SRV-ATTR:ramdisk_id           |                                                                                 |
    | OS-EXT-SRV-ATTR:reservation_id       | r-j4ydtu70                                                                      |
    | OS-EXT-SRV-ATTR:root_device_name     | /dev/vda                                                                        |
    | OS-EXT-SRV-ATTR:user_data            | -                                                                               |
    | OS-EXT-STS:power_state               | 1                                                                               |
    | OS-EXT-STS:task_state                | -                                                                               |
    | OS-EXT-STS:vm_state                  | active                                                                          |
    | OS-SRV-USG:launched_at               | 2018-07-13T03:15:10.000000                                                      |
    | OS-SRV-USG:terminated_at             | -                                                                               |
    | accessIPv4                           |                                                                                 |
    | accessIPv6                           |                                                                                 |
    | config_drive                         |                                                                                 |
    | created                              | 2018-07-13T03:09:50Z                                                            |
    | description                          | centos7.3                                                                       |
    | flavor:disk                          | 40                                                                              |
    | flavor:ephemeral                     | 0                                                                               |
    | flavor:extra_specs                   | {}                                                                              |
    | flavor:original_name                 | C4M4D40                                                                         |
    | flavor:ram                           | 4096                                                                            |
    | flavor:swap                          | 0                                                                               |
    | flavor:vcpus                         | 4                                                                               |
    | hostId                               | cf913d20310738e36074534cc0f334e429b26970a657ce7e207cea26                        |
    | host_status                          | UP                                                                              |
    | id                                   | 706d5c3b-0511-4bbf-b101-e1780c893b79                                            |
    | image                                | Attempt to boot from volume - no image supplied                                 |
    | key_name                             | mykey                                                                           |
    | locked                               | False                                                                           |
    | metadata                             | {}                                                                              |
    | name                                 | centos7.3                                                                       |
    | os-extended-volumes:volumes_attached | [{"id": "844554fa-4544-4880-8bba-fb2aa5903d19", "delete_on_termination": true}] |
    | progress                             | 0                                                                               |
    | security_groups                      | default                                                                         |
    | selfservice network                  | 172.16.1.7                                                                      |
    | status                               | ACTIVE                                                                          |
    | tags                                 | []                                                                              |
    | tenant_id                            | 6f4b66aa95e84d7191d989a940830a95                                                |
    | updated                              | 2018-07-13T03:15:10Z                                                            |
    | user_id                              | fe333bb8891446d79b727d11d55e2e32                                                |
    +--------------------------------------+---------------------------------------------------------------------------------+


 ##登录该计算节点
 ssh 192.168.97.10
##查看kvm 实例

    virsh list --all
     Id    Name                           State
    ----------------------------------------------------
     1     instance-00000002              running
     2     instance-00000004              running

###查看网络接口

    virsh domiflist instance-00000004
    Interface  Type       Source     Model       MAC
    -------------------------------------------------------
    tap4dfaaf48-0f bridge     brq763b1b5b-85 virtio      fa:16:3e:f4:50:fb

###增加网络接口

virsh attach-interface instance-00000004 --type bridge --source brq763b1b5b-85 --current


(责任编辑:IT)
------分隔线----------------------------