OpenStack安装流程(juno版)- 添加网络服务(neutron)- 创建初始网络

创建初始网络

在启动实例前,必须先创建必要的网络架构,让实例能连接之,这个架构包含外网(external network)和租户网络(tenant network)。下图为初始网络架构的示意图,展示了网络组件和从实例到外网的网络数据流线路:
初始网络示意图

External network

external network为实例提供访问Internet的入口。

以下操作在controller节点上完成。

创建external network

  1. 启动admin证书:

$ source admin-openrc.sh

  1. 创建网络:
    <pre>$ neutron net-create ext-net --router:external True \

--provider:physical_network external --provider:network_type flat

Created a new network:
FieldValue
admin_state_upTrue
ide6f3606d-2bf6-4b01-8fb4-c10d299dbe75
nameext-net
provider:network_typeflat
provider:physical_networkexternal
provider:segmentation_id
router:externalTrue
sharedFalse
statusACTIVE
subnets
tenant_id4f7806287c9a437e9cd912504ff71727

+---------------------------+--------------------------------------+</pre>

跟物理网络一样,虚拟网络也需要指定一个子网(subnet)。外网和network节点上连接外部接口的物理网络共享同一个子网和网关(The external network shares the same subnet and gateway associated with the physical network connected to the external interface on the network node. )。需要给这个子网指定单独的路由和IP地址,以防和外网上的其他设备产生冲突。

创建外网的子网

创建子网:
<pre>$ neutron subnet-create ext-net --name ext-subnet \
--allocation-pool start=FLOATING_IP_START,end=FLOATING_IP_END \
--disable-dhcp --gateway EXTERNAL_NETWORK_GATEWAY EXTERNAL_NETWORK_CIDR
</pre>
FLOATING_IP_START和FLOATING_IP_END分别为预定分配的浮动IP地址范围内的第一个和最后一个的IP地址。EXTERNAL_NETWORK_CIDR替换为物理网络相应的子网(Replace EXTERNAL_NETWORK_CIDR with the subnet associated with the physical network.)。EXTERNAL_NETWORK_GATEWAY替换为物理网络相应的网关,一般是以“.1”结尾的IP地址。关闭子网的DHCP选项,因为实例并不直接连接外网,浮动IP地址需要手动指定(You should disable DHCP on this subnet because instances do not connect directly to the external network and floating IP addresses require manual assignment.)。

在本文的网络配置条件下,上述命令应如下:
<pre>$ neutron subnet-create ext-net --name ext-subnet \
--allocation-pool start=192.168.100.101,end=192.168.100.200 \
--disable-dhcp --gateway 192.168.100.1 192.168.100.0/24

Created a new subnet:
FieldValue
allocation_pools{"start": "192.168.100.101", "end": "192.168.100.200"}
cidr192.168.100.0/24
dns_nameservers
enable_dhcpFalse
gateway_ip192.168.100.1
host_routes
id963754fb-73c4-4a1b-93ee-27d2c2beb97a
ip_version4
ipv6_address_mode
ipv6_ra_mode
nameext-subnet
network_ide6f3606d-2bf6-4b01-8fb4-c10d299dbe75
tenant_id4f7806287c9a437e9cd912504ff71727

+-------------------+--------------------------------------------------------+</pre>

租户网络

租户网络为了实例提供了内部网络之间相互访问的功能。这个架构把各个租户的网络相互隔离了。例如,demo租户使用这种网络后,只有属于这个租户的实例可以访问这个网络。

以下操作在controller节点上完成。

创建租户网络

  1. 启动demo证书:

$ source demo-openrc.sh

  1. 创建网络:

<pre>$ neutron net-create demo-net

Created a new network:
FieldValue
admin_state_upTrue
id830379a4-cc69-4165-a18f-f9430d999d5f
namedemo-net
router:externalFalse
sharedFalse
statusACTIVE
subnets
tenant_idd1f7caccc65840b68258997a759da07f

+-----------------+--------------------------------------+</pre>
如同外网网络,租户网络也需要专属的子网。不过可以指定任意有效的子网,因为这个架构将各个租户网络隔离开了。默认这个子网会使用DHCP来分配实例的IP地址。

创建租户网络的子网

创建子网:
<pre>$ neutron subnet-create demo-net --name demo-subnet \
--gateway TENANT_NETWORK_GATEWAY TENANT_NETWORK_CIDR
</pre>
将TENANT_NETWORK_CIDR替换为分配给租户网络的子网,TENANT_NETWORK_GATEWAY替换为分配的子网的网关,一般是以“.1”结尾的IP地址。

本文的网络配置下,上述命令如下:
<pre>$ neutron subnet-create demo-net --name demo-subnet \
--gateway 192.162.1.1 192.162.1.0/24

Created a new subnet:
FieldValue
allocation_pools{"start": "192.162.1.2", "end": "192.162.1.254"}
cidr192.162.1.0/24
dns_nameservers
enable_dhcpTrue
gateway_ip192.162.1.1
host_routes
ida6593d6d-1992-4207-ae61-7784f0aa5a3c
ip_version4
ipv6_address_mode
ipv6_ra_mode
namedemo-subnet
network_id830379a4-cc69-4165-a18f-f9430d999d5f
tenant_idd1f7caccc65840b68258997a759da07f

+-------------------+--------------------------------------------------+</pre>

一个虚拟路由器可以让两个或多个虚拟网络之间通信。每个路由器需要一个或多个接口(或包括网关)来访问指定网络。在本文,创建一个路由器并把租户网络和外网连接到它上面。

创建路由器并将租户网络和外网连接到上面

  1. 创建路由器:
    <pre>$ neutron router-create demo-router
Created a new router:
FieldValue
admin_state_upTrue
external_gateway_info
id74be9215-abad-4d63-ad75-9d365ae6ad6a
namedemo-router
routes
statusACTIVE
tenant_idd1f7caccc65840b68258997a759da07f

+-----------------------+--------------------------------------+</pre>

  1. 把路由和demo租户网络子网连接起来:
    <pre>$ neutron router-interface-add demo-router demo-subnet

Added interface 0c38b462-9f15-4fc4-abdf-9039048c733d to router demo-router.</pre>

  1. 把路由和外网连接起来,通过把外网设为路由的网关(Attach the router to the external network by setting it as the gateway):
    <pre>$ neutron router-gateway-set demo-router ext-net

Set gateway for router demo-router</pre>

验证操作

外网的子网是192.168.100.0/24,由于租户路由网关理论上在其浮动IP地址范围中是占据了最小的(lowest)IP地址,即192.168.100.101。要验证外部物理网络和虚拟网络设置的正确与否,从任意的外部网络的主机上可以ping通192.168.100.101即可验证。

在创建虚拟机的主机上ping上述IP:
<pre>Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:UsersTiger>ping 192.168.100.101

正在 Ping 192.168.100.101 具有 32 字节的数据:
来自 192.168.100.101 的回复: 字节=32 时间=2ms TTL=64
来自 192.168.100.101 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.100.101 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.100.101 的回复: 字节=32 时间<1ms TTL=64

192.168.100.101 的 Ping 统计信息:

数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),

往返行程的估计时间(以毫秒为单位):

最短 = 0ms,最长 = 2ms,平均 = 0ms</code></pre>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值