深刻理解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網絡架構中大量使用,理解這些組件有助於咱們理解不一樣的網絡場景。下篇文章中,咱們會了解虛擬機之間/虛擬機與外部網絡之間如何進行通訊。

相關文章
相關標籤/搜索