10 云计算系列之创建多网络给云主机使用

preface

这章我们要实现的是创建类似阿里云ECS多flat网络。

动手操作

前提条件:每个服务器至少2块网卡,如果你的是VM虚拟机,那么每个虚拟机至少也是2块网卡。
下面是我的环境:

主机名 eth0 eth1
linux-node1.example.com 192.168.56.11 192.168.57.11
linux-node2.example.com 192.168.56.12 192.168.57.12

以上环境都是在之前做Openstack的基础上增加了一块eth1网卡而已。
配置IP的步骤非常简单,在此省略:

配置Neutron

1.我们在配置完成eth1的IP,就可以修改neutron的配置文件了.
linux-node1

[root@linux-node1 network-scripts]# vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = public:eth0,internal:eth1

[root@linux-node1 network-scripts]# vim /etc/neutron/plugins/ml2/ml2_conf.ini
[ml2_type_flat]
flat_networks = public,internal

[root@linux-node1 network-scripts]# systemctl restart neutron-server
[root@linux-node1 network-scripts]# systemctl restart neutron-linuxbridge-agent

linux-node2

[root@linux-node2 network-scripts]# vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = public:eth0,internal:eth1

[root@linux-node1 network-scripts]# systemctl restart neutron-linuxbridge-agent
  1. 创建网络:
[root@linux-node1 network-scripts]# source /root/admin_openrc
[root@linux-node1 network-scripts]# openstack network create --share --provider-physical-network internal --provider-network-type flat internal
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | UP                                   |
| availability_zone_hints   |                                      |
| availability_zones        |                                      |
| created_at                | 2017-02-11T08:50:58Z                 |
| description               |                                      |
| headers                   |                                      |
| id                        | 836b0b92-37d9-4527-b49e-053f9938b08b |
| ipv4_address_scope        | None                                 |
| ipv6_address_scope        | None                                 |
| mtu                       | 1500                                 |
| name                      | internal                             |
| port_security_enabled     | True                                 |
| project_id                | 6197e636277d41ce8b0a835fbca4f87a     |
| project_id                | 6197e636277d41ce8b0a835fbca4f87a     |
| provider:network_type     | flat                                 |
| provider:physical_network | internal                             |
| provider:segmentation_id  | None                                 |
| revision_number           | 3                                    |
| router:external           | Internal                             |
| shared                    | True                                 |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tags                      | []                                   |
| updated_at                | 2017-02-11T08:50:58Z                 |
+---------------------------+--------------------------------------+
[root@linux-node1 network-scripts]# openstack subnet create --network internal \
>    --allocation-pool start=192.168.57.100,end=192.168.57.200 \
>    --dns-nameserver 192.168.56.2 --gateway 192.168.57.2 \
>    --subnet-range 192.168.57.0/24 internal-subnet
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| allocation_pools  | 192.168.57.100-192.168.57.200        |
| cidr              | 192.168.57.0/24                      |
| created_at        | 2017-02-11T08:59:26Z                 |
| description       |                                      |
| dns_nameservers   | 192.168.56.2                         |
| enable_dhcp       | True                                 |
| gateway_ip        | 192.168.57.2                         |
| headers           |                                      |
| host_routes       |                                      |
| id                | 9eb5e89f-c07e-4f34-ae8b-e01fa177b642 |
| ip_version        | 4                                    |
| ipv6_address_mode | None                                 |
| ipv6_ra_mode      | None                                 |
| name              | internal-subnet                      |
| network_id        | 836b0b92-37d9-4527-b49e-053f9938b08b |
| project_id        | 6197e636277d41ce8b0a835fbca4f87a     |
| project_id        | 6197e636277d41ce8b0a835fbca4f87a     |
| revision_number   | 2                                    |
| service_types     | []                                   |
| subnetpool_id     | None                                 |
| updated_at        | 2017-02-11T08:59:27Z                 |
+-------------------+--------------------------------------+

3.验证网络是否创建成功

[root@linux-node1 network-scripts]# neutron net-list
+--------------------------------------+----------+------------------------------------------------------+
| id                                   | name     | subnets                                              |
+--------------------------------------+----------+------------------------------------------------------+
| 33b9ef50-354b-457b-8ea2-8498ec64835b | public   | 66e18ef3-08cd-4bd2-b12d-4660fb240b59 192.168.56.0/24 |
| 836b0b92-37d9-4527-b49e-053f9938b08b | internal | 9eb5e89f-c07e-4f34-ae8b-e01fa177b642 192.168.57.0/24 |
+--------------------------------------+----------+------------------------------------------------------+
[root@linux-node1 network-scripts]# neutron sub-net list
Unknown command [u'sub-net', u'list']
[root@linux-node1 network-scripts]# neutron subnet-list
+--------------------------------------+-----------------+-----------------+------------------------------------------------------+
| id                                   | name            | cidr            | allocation_pools                                     |
+--------------------------------------+-----------------+-----------------+------------------------------------------------------+
| 66e18ef3-08cd-4bd2-b12d-4660fb240b59 | public-subnet   | 192.168.56.0/24 | {"start": "192.168.56.100", "end": "192.168.56.200"} |
| 9eb5e89f-c07e-4f34-ae8b-e01fa177b642 | internal-subnet | 192.168.57.0/24 | {"start": "192.168.57.100", "end": "192.168.57.200"} |
+--------------------------------------+-----------------+-----------------+------------------------------------------------------+

4.创建双网络的云主机
这里需要说明的是,添加网络的时候先后顺序是有区别的,如下图所示,先添加internal的话,那么云主机eth0就是internal的网段的IP,eth1就是public网段的IP
image

创建成功后的云主机具有两个网段的IP

image

posted @ 2017-02-13 10:28  温柔易淡  阅读(620)  评论(0编辑  收藏  举报