OpenStack Self-service networks with OpenvSwitch

作者:Maxwell Li
日期:2018/08/17
未经作者允许,禁止转载本文任何内容。如需转载请留言。


Overview

之前进行了 OpenStack Newton 版本的手动部署,部署文档请参考:OpenStack Newton Install Guid For Ubuntu
Xenial
,当时为了部署方便,采用了 Provider networks + Linux Bridge 方案。为了学习 OpenvSwitch 和 VXLAN 网络模式,现将之前环境的 Provide networks 改为 Self-service Networks,并使用 OVS 来创建网桥。

注:本文基于已有 Provide networks 进行修改,部分操作已经执行过,在此省略。

清除现有网络

root@controller:~# neutron net-list
+--------------------------------------+----------+-----------------------------------------------------+
| id                                   | name     | subnets                                             |
+--------------------------------------+----------+-----------------------------------------------------+
| c9f0bdc7-72c8-469c-baae-21243e2b50d0 | provider | 3c96c886-aec3-4104-bfe8-7497228a442d 192.168.1.0/24 |
+--------------------------------------+----------+-----------------------------------------------------+
root@controller:~# neutron subnet-list
+--------------------------------------+----------+----------------+----------------------------------------------------+
| id                                   | name     | cidr           | allocation_pools                                   |
+--------------------------------------+----------+----------------+----------------------------------------------------+
| 3c96c886-aec3-4104-bfe8-7497228a442d | provider | 192.168.1.0/24 | {"start": "192.168.1.100", "end": "192.168.1.200"} |
+--------------------------------------+----------+----------------+----------------------------------------------------+
root@controller:~# neutron subnet-delete provider
Deleted subnet(s): provider
root@controller:~# neutron net-delete provider
Deleted network(s): provider

Install And Configure Controller Node

1、安装 Neutron

$ apt install neutron-l3-agent neutron-openvswitch-agent

跟之前相比多了 neutron-l3-agentneutron-openvswitch-agent 安装包。

2、修改 /etc/neutron/neutron.conf 配置文件:

[DEFAULT] 部分,启用 Modular Layer 2 (ML2)、router service 和 overlapping IP addresses 插件:

[DEFAULT]
...
core_plugin = ml2
service_plugins = router
allow_overlapping_ips = True

3、配置 Modular Layer 2 (ML2) 插件:
ML2 插件使用 Linux 网桥为实例构建 L2 虚拟网络设施。

修改 /etc/neutron/plugins/ml2/ml2_conf.ini 配置文件:

[ml2] 部分,启用 flat、VLAN、VXLAN 网络:

[ml2]
...
type_drivers = flat,vlan,vxlan

[ml2] 部分,启用 VXLAN self-service 网络:

[ml2]
...
tenant_network_types = vxlan

[ml2] 部分,启用 OpenvSwitch 和 layer-2 population 机制:

[ml2]
...
mechanism_drivers = openvswitch,l2population

[ml2_type_vxlan] 部分,配置 self-service networks 中的 VXLAN 网络标识符范围:

[ml2_type_vxlan]
...
vni_ranges = 1:1000

4、配置 OpenvSwitch 代理:

修改 /etc/neutron/plugins/ml2/openvswitch_agent.ini 配置文件:

[ovs]
bridge_mappings = provider:br-provider
local_ip = OVERLAY_INTERFACE_IP_ADDRESS

[agent]
tunnel_types = vxlan
l2_population = True

[securitygroup]
firewall_driver = iptables_hybrid

注:将 OVERLAY_INTERFACE_IP_ADDRESS 替换为 Controller Node Management Network IP 地址 10.0.0.11。

5、配置 L3(Layer-3) 代理

修改 /etc/neutron/l3_agent.ini 配置文件:

[DEFAULT]
...
interface_driver = openvswitch
external_network_bridge =

6、将配置信息重新写入 neutron 数据库:

$ su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neutron.conf \
  --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head" neutron

7、创建 Provider 网桥:

$ ovs-vsctl add-br br-provider

8、重启 Compute API Service:

$ service nova-api restart

9、重启 Networking Services:

$ service neutron-server restart
$ service neutron-linuxbridge-agent restart
$ service neutron-openvswitch-agent restart
$ service neutron-dhcp-agent restart
$ service neutron-metadata-agent restart
$ service neutron-l3-agent restart

Install And Configure Compute Node

1、安装 Neutron

$ apt install neutron-openvswitch-agent

2、修改 /etc/neutron/plugins/ml2/openvswitch_agent.ini 配置文件:

[ovs]
local_ip = OVERLAY_INTERFACE_IP_ADDRESS

[agent]
tunnel_types = vxlan
l2_population = True

注:将 OVERLAY_INTERFACE_IP_ADDRESS 替换为 Compute Node Management Network IP 地址 10.0.0.21。

3、重启 Compute Service:

$ service nova-compute restart

3、重启 Neutron 服务:

$ service neutron-openvswitch-agent restart
$ service neutron-linuxbridge-agent restart

Verify Operation

设置 OpenStack 中 Admin User 环境变量:

$ source ~/openstack/admin-openrc

创建网络

1、创建 Provider 网络:

root@controller:~# neutron net-create provider \
> --shared \
> --provider:physical_network provider \
> --provider:network_type flat \
> --router:external "True"
Created a new network:
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | True                                 |
| availability_zone_hints   |                                      |
| availability_zones        |                                      |
| created_at                | 2018-08-17T08:25:04Z                 |
| description               |                                      |
| id                        | f20694bf-1a63-4317-b292-99e46c74718a |
| ipv4_address_scope        |                                      |
| ipv6_address_scope        |                                      |
| is_default                | False                                |
| mtu                       | 1500                                 |
| name                      | provider                             |
| port_security_enabled     | True                                 |
| project_id                | a0032382f4024e409f236fe922d2ee8f     |
| provider:network_type     | flat                                 |
| provider:physical_network | provider                             |
| provider:segmentation_id  |                                      |
| revision_number           | 4                                    |
| router:external           | True                                 |
| shared                    | True                                 |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tags                      |                                      |
| tenant_id                 | a0032382f4024e409f236fe922d2ee8f     |
| updated_at                | 2018-08-17T08:25:04Z                 |
+---------------------------+--------------------------------------+

其中,--shared 设置允许所有项目访问该虚拟网络,--provider:physical_network provider--provider:network_type flat 将扁平虚拟网络通过 Controller 节点的 eth0 连接到扁平物理网络。

2、创建 Provider 子网:

$ openstack subnet create --network provider \
  --allocation-pool start=START_IP_ADDRESS,end=END_IP_ADDRESS \
  --dns-nameserver DNS_RESOLVER --gateway PROVIDER_NETWORK_GATEWAY \
  --subnet-range PROVIDER_NETWORK_CIDR provider
  • START_IP_ADDRESSEND_IP_ADDRESS 是将分配给实例的子网的起始和结束 IP 地址,需要替换为实际起始结束 IP地址(这个IP地址范围不能包括任何已存在的活动IP);
  • DNS_RESOLVER 是域名服务器,需替换为实际 DNS 服务器 IP;
  • PROVIDER_NETWORK_GATEWAY 是外部网络网关 IP,替换为实际网关 IP。

本指南使用以下命令创建子网:

root@controller:~# neutron subnet-create \
> --name sub-provider \
> --allocation-pool start=192.168.1.100,end=192.168.1.200 \
> --dns-nameserver 192.168.1.1 \
> --gateway 192.168.1.1 \
> provider 192.168.1.0/24
Created a new subnet:
+-------------------+----------------------------------------------------+
| Field             | Value                                              |
+-------------------+----------------------------------------------------+
| allocation_pools  | {"start": "192.168.1.100", "end": "192.168.1.200"} |
| cidr              | 192.168.1.0/24                                     |
| created_at        | 2018-08-17T08:26:34Z                               |
| description       |                                                    |
| dns_nameservers   | 192.168.1.1                                        |
| enable_dhcp       | True                                               |
| gateway_ip        | 192.168.1.1                                        |
| host_routes       |                                                    |
| id                | f2d22768-0dc0-46f1-a757-70037f39db31               |
| ip_version        | 4                                                  |
| ipv6_address_mode |                                                    |
| ipv6_ra_mode      |                                                    |
| name              | sub-provider                                       |
| network_id        | f20694bf-1a63-4317-b292-99e46c74718a               |
| project_id        | a0032382f4024e409f236fe922d2ee8f                   |
| revision_number   | 2                                                  |
| service_types     |                                                    |
| subnetpool_id     |                                                    |
| tenant_id         | a0032382f4024e409f236fe922d2ee8f                   |
| updated_at        | 2018-08-17T08:26:34Z                               |
+-------------------+----------------------------------------------------+

3、创建 Self-Service 网络:

root@controller:~# neutron net-create selfservice
Created a new network:
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | True                                 |
| availability_zone_hints   |                                      |
| availability_zones        |                                      |
| created_at                | 2018-08-17T08:27:36Z                 |
| description               |                                      |
| id                        | 3f3b67bb-db40-4e36-9f93-768f45c48257 |
| ipv4_address_scope        |                                      |
| ipv6_address_scope        |                                      |
| mtu                       | 1450                                 |
| name                      | selfservice                          |
| port_security_enabled     | True                                 |
| project_id                | a0032382f4024e409f236fe922d2ee8f     |
| provider:network_type     | vxlan                                |
| provider:physical_network |                                      |
| provider:segmentation_id  | 17                                   |
| revision_number           | 3                                    |
| router:external           | False                                |
| shared                    | False                                |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tags                      |                                      |
| tenant_id                 | a0032382f4024e409f236fe922d2ee8f     |
| updated_at                | 2018-08-17T08:27:36Z                 |
+---------------------------+--------------------------------------+

4、创建 Self-Service 子网:

$ openstack subnet create --network selfservice \
  --dns-nameserver DNS_RESOLVER --gateway SELFSERVICE_NETWORK_GATEWAY \
  --subnet-range SELFSERVICE_NETWORK_CIDR selfservice
  • DNS_RESOLVER 是域名服务器,需替换为实际 DNS 服务器 IP;
  • SELFSERVICE_NETWORK_GATEWAY 是 self-service network 网关 IP。
  • SELFSERVICE_NETWORK_CIDR 是你想创建的 self-service network CIDR。

本指南使用以下命令创建子网:

root@controller:~# neutron subnet-create \
> --name sub-selfservice \
> --dns-nameserver 192.168.1.1 \
> --gateway 8.8.8.1 \
> selfservice 8.8.8.0/24
Created a new subnet:
+-------------------+------------------------------------------+
| Field             | Value                                    |
+-------------------+------------------------------------------+
| allocation_pools  | {"start": "8.8.8.2", "end": "8.8.8.254"} |
| cidr              | 8.8.8.0/24                               |
| created_at        | 2018-08-17T08:33:00Z                     |
| description       |                                          |
| dns_nameservers   | 192.168.1.1                              |
| enable_dhcp       | True                                     |
| gateway_ip        | 8.8.8.1                                  |
| host_routes       |                                          |
| id                | 8ff3e88a-4708-48c7-adde-d3adb99a5270     |
| ip_version        | 4                                        |
| ipv6_address_mode |                                          |
| ipv6_ra_mode      |                                          |
| name              | sub-selfservice                          |
| network_id        | 3f3b67bb-db40-4e36-9f93-768f45c48257     |
| project_id        | a0032382f4024e409f236fe922d2ee8f         |
| revision_number   | 2                                        |
| service_types     |                                          |
| subnetpool_id     |                                          |
| tenant_id         | a0032382f4024e409f236fe922d2ee8f         |
| updated_at        | 2018-08-17T08:33:00Z                     |
+-------------------+------------------------------------------+

5、此时,在 Controller Node 上执行 ip netns 命令,可以看到创建了两条 dhcp,且 id 号与 network 相同:

root@controller:~# ip netns
qdhcp-3f3b67bb-db40-4e36-9f93-768f45c48257 (id: 1)
qdhcp-f20694bf-1a63-4317-b292-99e46c74718a (id: 0)
root@controller:~# openstack network list
+--------------------------------------+-------------+--------------------------------------+
| ID                                   | Name        | Subnets                              |
+--------------------------------------+-------------+--------------------------------------+
| 3f3b67bb-db40-4e36-9f93-768f45c48257 | selfservice | 8ff3e88a-4708-48c7-adde-d3adb99a5270 |
| f20694bf-1a63-4317-b292-99e46c74718a | provider    | f2d22768-0dc0-46f1-a757-70037f39db31 |
+--------------------------------------+-------------+--------------------------------------+

创建路由

1、创建配置虚拟路由器

Self-Service networks 通过虚拟路由器连接到 Provider 网络。每个虚拟路由器包含至少一个连接到 Self-Service networks 的接口和一个位于 Provider 网络的网关。Provider 网络必须包含 router:external 设置项,以便 Self-Service networks 虚拟路由器可连接到外部网络。

root@controller:~# openstack router create router
+-------------------------+--------------------------------------+
| Field                   | Value                                |
+-------------------------+--------------------------------------+
| admin_state_up          | UP                                   |
| availability_zone_hints |                                      |
| availability_zones      |                                      |
| created_at              | 2018-08-17T08:42:28Z                 |
| description             |                                      |
| distributed             | False                                |
| external_gateway_info   | null                                 |
| flavor_id               | None                                 |
| ha                      | False                                |
| headers                 |                                      |
| id                      | 2b3647c7-b403-42cb-a12c-73067f9aa676 |
| name                    | router                               |
| project_id              | a0032382f4024e409f236fe922d2ee8f     |
| project_id              | a0032382f4024e409f236fe922d2ee8f     |
| revision_number         | 3                                    |
| routes                  |                                      |
| status                  | ACTIVE                               |
| updated_at              | 2018-08-17T08:42:28Z                 |
+-------------------------+--------------------------------------+
root@controller:~# neutron router-interface-add router sub-selfservice
Added interface d326333b-145a-46ba-8867-b71bb1998848 to router router.
root@controller:~# neutron router-gateway-set router provider
Set gateway for router router

2、在 Controller Node 上执行 ip netns,可以发现多了一条路由:

root@controller:~# ip netns
qrouter-2b3647c7-b403-42cb-a12c-73067f9aa676
qdhcp-3f3b67bb-db40-4e36-9f93-768f45c48257 (id: 1)
qdhcp-f20694bf-1a63-4317-b292-99e46c74718a (id: 0)

问题

OpenStack Self-service networks 架构如下图所示:

network2-connectivity.png

查看 OVS 网桥,发现在 br-int 上少了一个 tap 口:

root@controller:~# ovs-vsctl show
...
    Bridge br-int
        Controller "tcp:127.0.0.1:6633"
            is_connected: true
        fail_mode: secure
        Port patch-tun
            Interface patch-tun
                type: patch
                options: {peer=patch-int}
        Port int-br-provider
            Interface int-br-provider
                type: patch
                options: {peer=phy-br-provider}
        Port "qr-d326333b-14"
            tag: 1
            Interface "qr-d326333b-14"
                type: internal
        Port "qg-acdea044-7e"
            tag: 2
            Interface "qg-acdea044-7e"
                type: internal
        Port br-int
            Interface br-int
                type: internal
...

这个 tap 口应该是用来连接 DHCP 和 br-int,没有这个口,导致在名字空间内也无法 ping 通网关:

root@controller:~# ip netns exec qdhcp-3f3b67bb-db40-4e36-9f93-768f45c48257 ping 8.8.8.1
PING 8.8.8.1 (8.8.8.1) 56(84) bytes of data.
From 8.8.8.2 icmp_seq=1 Destination Host Unreachable
From 8.8.8.2 icmp_seq=2 Destination Host Unreachable
From 8.8.8.2 icmp_seq=3 Destination Host Unreachable
^C
--- 8.8.8.1 ping statistics ---
6 packets transmitted, 0 received, +3 errors, 100% packet loss, time 5029ms
pipe 3

暂未解决。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,117评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,328评论 1 293
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,839评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,007评论 0 206
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,384评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,629评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,880评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,593评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,313评论 1 243
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,575评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,066评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,392评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,052评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,082评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,844评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,662评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,575评论 2 270

推荐阅读更多精彩内容