深刻理解openstack网络架构(1)

原文地址: https://blogs.oracle.com/ronen/entry/diving_into_openstack_network_architecturenode

译文转载自:http://blog.csdn.net/halcyonbaby/article/details/41524447linux

前言

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所提供的一种配置。安装它很是简单,而且它是一个很好的参考。在这种配置中,咱们在全部服务器上使用eth2做为虚拟机的网络,全部虚拟机流量使用这个网卡。Oracle OpenStack Tech Preview使用VLAN进行L2隔离,进而提供租户和网络隔离,下图展现了咱们如何进行配置和部署:   cookie

 

第一篇文章会略长,咱们将聚焦于openstack网络的一些基本概念。咱们将讨论open vswitch、network namespaces、linux bridge、veth pairs等几个组件。注意这里不打算全面介绍这些组件,只是为了理解openstack网络架构。能够经过网络上的其余资源进一步了解这些组件。网络

 

Open vSwitch (OVS)

在Oracle OpenStack Tech Preview中用于链接虚拟机和物理网口(如上例中的eth2),就像上边部署图所示。OVS包含bridages和ports,OVS bridges不一样于与linux bridge(使用brctl命令建立)。让咱们先看下OVS的结构,使用以下命令:架构

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. # ovs-vsctl show  
  2. 7ec51567-ab42-49e8-906d-b854309c9edf  
  3.     Bridge br-int  
  4.         Port br-int  
  5.             Interface br-int  
  6.                 type: internal  
  7.         Port "int-br-eth2"  
  8.             Interface "int-br-eth2"  
  9.     Bridge "br-eth2"  
  10.         Port "br-eth2"  
  11.             Interface "br-eth2"  
  12.                 type: internal  
  13.         Port "eth2"  
  14.             Interface "eth2"  
  15.         Port "phy-br-eth2"  
  16.             Interface "phy-br-eth2"  
  17. ovs_version: "1.11.0"  

 

咱们看到标准的部署在compute node上的OVS,拥有两个网桥,每一个有若干相关联的port。上边的例子是在一个没有任何虚拟机的计算节点上。咱们能够看到eth2链接到个叫br-eth2的网桥上,咱们还看到两个叫“int-br-eth2"和”phy-br-eth2“的port,事实上是一个veth pair,做为虚拟网线链接两个bridages。咱们会在后边讨论veth paris。oracle

当咱们建立一个虚拟机,br-int网桥上会建立一个port,这个port最终链接到虚拟机(咱们会在后边讨论这个链接)。这里是启动一个虚拟机后的OVS结构:  ssh

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. # ovs-vsctl show  
  2. efd98c87-dc62-422d-8f73-a68c2a14e73d  
  3.     Bridge br-int  
  4.         Port "int-br-eth2"  
  5.             Interface "int-br-eth2"  
  6.         Port br-int  
  7.             Interface br-int  
  8.                 type: internal  
  9.         Port "qvocb64ea96-9f"  
  10.             tag: 1  
  11.             Interface "qvocb64ea96-9f"  
  12.     Bridge "br-eth2"  
  13.         Port "phy-br-eth2"  
  14.             Interface "phy-br-eth2"  
  15.         Port "br-eth2"  
  16.             Interface "br-eth2"  
  17.                 type: internal  
  18.         Port "eth2"  
  19.             Interface "eth2"  
  20. ovs_version: "1.11.0"  


”br-int“网桥如今有了一个新的port"qvocb64ea96-9f" 链接VM,而且被标记为vlan1。虚拟机的每一个网卡都须要对应在"br-int”网桥上建立一个port。工具

 

OVS中另外一个有用的命令是dump-flows,如下为例子: 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. # ovs-ofctl dump-flows br-int  
  2. NXST_FLOW reply (xid=0x4):  
  3. 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  
  4. 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  
  5. 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。而后虚拟机网络(eth2)上的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:

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. # ip netns add my-ns  
  2. # ip netns list  
  3. my-ns  



 

咱们说过namespace是一个隔离的容器,咱们能够在namspace中进行各类操做,好比ifconfig命令。

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. # ip netns exec my-ns ifconfig -a  
  2. lo        Link encap:Local Loopback  
  3.           LOOPBACK  MTU:16436 Metric:1  
  4.           RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
  5.           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0  
  6. collisions:0 txqueuelen:0  
  7.           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中。

 

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. # ip netns exec my-ns ifconfig -a  
  2. lo        Link encap:Local Loopback  
  3.           LOOPBACK  MTU:65536 Metric:1  
  4.           RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
  5.           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0  
  6. collisions:0 txqueuelen:0  
  7.           RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)  
  8.   
  9. my-port   Link encap:Ethernet HWaddr 22:04:45:E2:85:21  
  10.           BROADCAST  MTU:1500 Metric:1  
  11.           RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
  12.           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0  
  13. collisions:0 txqueuelen:0  
  14.           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对,注意咱们定义了两端的名字:

 

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. # ip link add veth0 type veth peer name veth1  
  2.   
  3. # ifconfig -a  
  4.   
  5. .  
  6.   
  7. .  
  8.   
  9. veth0     Link encap:Ethernet HWaddr 5E:2C:E6:03:D0:17  
  10.   
  11.           BROADCAST MULTICAST  MTU:1500 Metric:1  
  12.   
  13.           RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
  14.   
  15.           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0  
  16.   
  17. collisions:0 txqueuelen:1000  
  18.   
  19.           RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)  
  20.   
  21. veth1     Link encap:Ethernet HWaddr E6:B6:E2:6D:42:B8  
  22.   
  23.           BROADCAST MULTICAST  MTU:1500 Metric:1  
  24.   
  25.           RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
  26.   
  27.           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0  
  28.   
  29. collisions:0 txqueuelen:1000  
  30.   
  31.           RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)  
  32.   
  33. .  
  34.   
  35. .  

为了让例子更有意义,咱们将建立以下配置:

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. veth0 => veth1 =>br-eth3 => eth3 ======> eth2 on another Linux server  


br-eht3: 一个基本的Linux bridge,链接veth1和eth3eth3: 一个没有设定IP的物理网口,该网口链接着斯有网络eth2: 远端Linux服务器上的一个物理网口,链接着私有网络而且被配置了IP(50.50.50.1)一旦咱们建立了这个配置,咱们将经过veth0 ping 50.50.50.1这个远端IP,从而测试网络联通性:

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. # brctl addbr br-eth3  
  2.   
  3. # brctl addif br-eth3 eth3  
  4.   
  5. # brctl addif br-eth3 veth1  
  6.   
  7. # brctl show  
  8.   
  9. bridge name     bridge id               STP enabled     interfaces  
  10.   
  11. br-eth3         8000.00505682e7f6       no              eth3  
  12.   
  13.                                                         veth1  
  14.   
  15. # ifconfig veth0 50.50.50.50  
  16.   
  17. # ping -I veth0 50.50.50.51  
  18.   
  19. PING 50.50.50.51 (50.50.50.51) from 50.50.50.50 veth0: 56(84) bytes of data.  
  20.   
  21. 64 bytes from 50.50.50.51: icmp_seq=1 ttl=64 time=0.454 ms  
  22.   
  23. 64 bytes from 50.50.50.51: icmp_seq=2 ttl=64 time=0.298 ms  
  24.   
  25. # ethtool -S veth1NIC statistics:peer_ifindex: 12# ip link..12: veth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000  


若是命名不像例子中这么显而易见,致使咱们没法支持veth设备的两端,咱们可使用ethtool命令查询。ethtool命令返回index号,经过ip link命令查看对应的设备:

[plain]  view plain copy 在CODE上查看代码片 派生到个人代码片
 
  1. # ethtool -S veth1  
  2.   
  3. NIC statistics:  
  4.   
  5. peer_ifindex: 12  
  6.   
  7. # ip link  
  8.   
  9. .  
  10.   
  11. .  
  12.   
  13. 12: veth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000  



总结

文章中,咱们快速了解了OVS/网络namespaces/Linux bridges/veth对。这些组件在openstack网络架构中大量使用,理解这些组件有助于咱们理解不一样的网络场景。下篇文章中,咱们会了解虚拟机之间/虚拟机与外部网络之间如何进行通讯。

相关文章
相关标签/搜索