怎样深入理解 openstack 网络架构,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
前言
openstack 网络功能强大同时也相对更复杂。本系列文章通过 Oracle OpenStack TechPreview 介绍 openstack 的配置,通过各种场景和例子说明 openstack 各种不同的网络组件。本文的目的在于提供 openstack 网络架构的全景图并展示各个模块是如何一起协作的。这对 openstack 的初学者以及希望理解 openstack 网络原理的人会非常有帮助。首先,我们先讲解下一些基础并举例说明。
根据最新的 icehouse 版用户调查,基于 open vswitch 插件的 Neutron 在生产环境和 POC 环境都被广泛使用,所以在这个系列的文章中我们主要分析这种 openstack 网络的配置。当然,我们知道 openstack 网络支持很多种配置,尽管 neutron+open vswitch 是最常用的配置,但是我们从未说它是最好或者最高效的一种方式。Neutron+open vswitch 仅仅是一个例子,对任何希望理解 openstack 网络的人是一个很好的切入点。即使你打算使用其他类型的网络配置比如使用不同的 neutron 插件或者根本不使用 neutron,这篇文章对你理解 openstack 网络仍是一个很好的开始。
我们在例子中使用的配置是 Oracle OpenStack Tech Preview 所提供的一种配置。安装它非常简单,并且它是一个很好的参考。在这种配置中,我们在所有服务器上使用 eth3 作为虚拟机的网络,所有虚拟机流量使用这个网卡。Oracle OpenStack Tech Preview 使用 VLAN 进行 L2 隔离,进而提供租户和网络隔离,下图展示了我们如何进行配置和部署:
第一篇文章会略长,我们将聚焦于 openstack 网络的一些基本概念。我们将讨论 open vswitch、network namespaces、linux bridge、veth pairs 等几个组件。注意这里不打算全面介绍这些组件,只是为了理解 openstack 网络架构。可以通过网络上的其他资源进一步了解这些组件。
Open vSwitch (OVS)
在 Oracle OpenStack Tech Preview 中用于连接虚拟机和物理网口(如上例中的 eth3),就像上边部署图所示。OVS 包含 bridages 和 ports,OVS bridges 不同于与 linux bridge(使用 brctl 命令创建)。让我们先看下 OVS 的结构,使用如下命令:
# ovs-vsctl show
7ec51567-ab42-49e8-906d-b854309c9edf
Bridge br-int
Port br-int
Interface br-int
type: internal
Port int-br-eth3
Interface int-br-eth3
Bridge br-eth3
Port br-eth3
Interface br-eth3
type: internal
Port eth3
Interface eth3
Port phy-br-eth3
Interface phy-br-eth3
ovs_version: 1.11.0
我们看到标准的部署在 compute node 上的 OVS,拥有两个网桥,每个有若干相关联的 port。上边的例子是在一个没有任何虚拟机的计算节点上。我们可以看到 eth3 连接到个叫 br-eth3 的网桥上,我们还看到两个叫“int-br-eth3 和”phy-br-eth3“的 port,事实上是一个 veth pair,作为虚拟网线连接两个 bridages。我们会在后边讨论 veth paris。
当我们创建一个虚拟机,br-int 网桥上会创建一个 port,这个 port 最终连接到虚拟机(我们会在后边讨论这个连接)。这里是启动一个虚拟机后的 OVS 结构:
# ovs-vsctl show
efd98c87-dc62-422d-8f73-a68c2a14e73d
Bridge br-int
Port int-br-eth3
Interface int-br-eth3
Port br-int
Interface br-int
type: internal
Port qvocb64ea96-9f
tag: 1
Interface qvocb64ea96-9f
Bridge br-eth3
Port phy-br-eth3
Interface phy-br-eth3
Port br-eth3
Interface br-eth3
type: internal
Port eth3
Interface eth3
ovs_version: 1.11.0
”br-int“网桥现在有了一个新的 port qvocb64ea96-9f 连接 VM,并且被标记为 vlan1。虚拟机的每个网卡都需要对应在 br-int”网桥上创建一个 port。
OVS 中另一个有用的命令是 dump-flows,以下为例子:
# ovs-ofctl dump-flows br-int
NXST_FLOW reply (xid=0x4):
cookie=0x0, duration=735.544s, table=0, n_packets=70, n_bytes=9976,idle_age=17, priority=3,in_port=1,dl_vlan=1000 actions=mod_vlan_vid:1,NORMAL
cookie=0x0, duration=76679.786s, table=0, n_packets=0, n_bytes=0,idle_age=65534, hard_age=65534, priority=2,in_port=1 actions=drop
cookie=0x0, duration=76681.36s, table=0, n_packets=68, n_bytes=7950,idle_age=17, hard_age=65534, priority=1 actions=NORMAL
如上所述,VM 相连的 port 使用了 Vlan tag 1。然后虚拟机网络(eth3) 上的 port 使用 tag1000。OVS 会修改 VM 和物理网口间所有 package 的 vlan。在 openstack 中,OVS agent 控制 open vswitch 中的 flows,用户不需要进行操作。如果你想了解更多的如何控制 open vswitch 中的流,可以参考 http://openvswitch.org 中对 ovs-ofctl 的描述。
Network Namespaces (netns)
网络 namespace 是 linux 上一个很 cool 的特性,它的用途很多。在 openstack 网络中被广泛使用。网络 namespace 是拥有独立的网络配置隔离容器,并且该网络不能被其他名字空间看到。网络名字空间可以被用于封装特殊的网络功能或者在对网络服务隔离的同时完成一个复杂的网络设置。在 Oracle OpenStack Tech Preview 中我们使用最新的 R3 企业版内核,该内核提供给了对 netns 的完整支持。
通过如下例子我们展示如何使用 netns 命令控制网络 namespaces。定义一个新的 namespace:
# ip netns add my-ns
# ip netns list
my-ns
我们说过 namespace 是一个隔离的容器,我们可以在 namspace 中进行各种操作,比如 ifconfig 命令。
# ip netns exec my-ns ifconfig -a
lo Link encap:Local Loopback
LOOPBACK MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
我们可以在 namespace 中运行任何命令,比如对 debug 非常有用的 tcddump 命令,我们使用 ping、ssh、iptables 命令。连接 namespace 和外部:连接到 namespace 和 namespace 直接连接的方式有很多,我们主要聚集在 openstack 中使用的方法。openstack 使用了 OVS 和网络 namespace 的组合。OVS 定义接口,然后我们将这些接口加入 namespace 中。
# ip netns exec my-ns ifconfig -a
lo Link encap:Local Loopback
LOOPBACK MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
my-port Link encap:Ethernet HWaddr 22:04:45:E2:85:21
BROADCAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
现在我们可以增加更多的 ports 到 OVS bridge,并且连接到其他 namespace 或者其他设备比如物理网卡。Neutron 使用网络 namespace 来实现网络服务,如 DHCP、routing、gateway、firewall、load balance 等。下一篇文章我们会讨论更多细节。
Linux bridge and veth pairs
Linux bridge 用于连接 OVS port 和虚拟机。ports 负责连通 OVS bridge 和 linux bridge 或者两者与虚拟机。linux bridage 主要用于安全组增强。安全组通过 iptables 实现,iptables 只能用于 linux bridage 而非 OVS bridage。
Veth 对在 openstack 网络中大量使用,也是 debug 网络问题的很好工具。Veth 对是一个简单的虚拟网线,所以一般成对出现。通常 Veth 对的一端连接到 bridge,另一端连接到另一个 bridge 或者留下在作为一个网口使用。
这个例子中,我们将创建一些 veth 对,把他们连接到 bridge 上并测试联通性。这个例子用于通常的 Linux 服务器而非 openstack 节点:创建一个 veth 对,注意我们定义了两端的名字:
# ip link add veth0 type veth peer name veth2
# ifconfig -a
veth0 Link encap:Ethernet HWaddr 5E:2C:E6:03:D0:17
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
veth2 Link encap:Ethernet HWaddr E6:B6:E2:6D:42:B8
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
.
为了让例子更有意义,我们将创建如下配置:
veth0 = veth2 = br-eth4 = eth4 ====== eth3 on another Linux server
br-eht3: 一个基本的 Linux bridge,连接 veth2 和 eth4eth4: 一个没有设定 IP 的物理网口,该网口连接着斯有网络 eth3: 远端 Linux 服务器上的一个物理网口,连接着私有网络并且被配置了 IP(50.50.50.1)一旦我们创建了这个配置,我们将通过 veth0 ping 50.50.50.1 这个远端 IP,从而测试网络联通性:
# brctl addbr br-eth4
# brctl addif br-eth4 eth4
# brctl addif br-eth4 veth2
# brctl show
bridge name bridge id STP enabled interfaces
br-eth4 8000.00505682e7f6 no eth4
veth2
# ifconfig veth0 50.50.50.50
# ping -I veth0 50.50.50.51
PING 50.50.50.51 (50.50.50.51) from 50.50.50.50 veth0: 56(84) bytes of data.
64 bytes from 50.50.50.51: icmp_seq=1 ttl=64 time=0.454 ms
64 bytes from 50.50.50.51: icmp_seq=2 ttl=64 time=0.298 ms
# ethtool -S veth2NIC statistics:peer_ifindex: 12# ip link..12: veth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
如果命名不像例子中这么显而易见,导致我们无法支持 veth 设备的两端,我们可以使用 ethtool 命令查询。ethtool 命令返回 index 号,通过 ip link 命令查看对应的设备:
# ethtool -S veth2
NIC statistics:
peer_ifindex: 12
# ip link
12: veth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
我们快速了解了 OVS/ 网络 namespaces/Linux bridges/veth 对。这些组件在 openstack 网络架构中大量使用,理解这些组件有助于我们理解不同的网络场景。
看完上述内容,你们掌握怎样深入理解 openstack 网络架构的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注丸趣 TV 行业资讯频道,感谢各位的阅读!