深入理解openstack網絡架構(1) :基礎講解
前言
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隔離,進而提供租戶和網絡隔離,下圖展示了我們如何進行配置和部署:
***篇文章會略長,我們將聚焦于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的結構,使用如下命令:
- # ovs-vsctl show
- 7ec51567-ab42-49e8-906d-b854309c9edf
- Bridge br-int
- Port br-int
- Interface br-int
- type: internal
- Port "int-br-eth2"
- Interface "int-br-eth2"
- Bridge "br-eth2"
- Port "br-eth2"
- Interface "br-eth2"
- type: internal
- Port "eth2"
- Interface "eth2"
- Port "phy-br-eth2"
- Interface "phy-br-eth2"
- ovs_version: "1.11.0"
我們看到標準的部署在compute node上的OVS,擁有兩個網橋,每個有若干相關聯的port。上邊的例子是在一個沒有任何虛擬機的計算節點上。我們可以看到eth2連接到個叫br- eth2的網橋上,我們還看到兩個叫“int-br-eth2"和”phy-br-eth2“的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-eth2"
- Interface "int-br-eth2"
- Port br-int
- Interface br-int
- type: internal
- Port "qvocb64ea96-9f"
- tag: 1
- Interface "qvocb64ea96-9f"
- Bridge "br-eth2"
- Port "phy-br-eth2"
- Interface "phy-br-eth2"
- Port "br-eth2"
- Interface "br-eth2"
- type: internal
- Port "eth2"
- Interface "eth2"
- 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。然后虛擬機網絡(eth2)上的port使用tag1000。OVS會修改VM和物理網口間所有package的vlan。在openstack中,OVS agent 控制open vswitch中的flows,用戶不需要進行操作。如果你想了解更多的如何控制open vswitch中的流,可以參考http://openvswitch.org中對ovs-ofctl的描述。
#p#
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 veth1
- # 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)
- veth1 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 => 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,從而測試網絡聯通性:
- # brctl addbr br-eth3
- # brctl addif br-eth3 eth3
- # brctl addif br-eth3 veth1
- # brctl show
- bridge name bridge id STP enabled interfaces
- br-eth3 8000.00505682e7f6 no eth3
- veth1
- # 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 veth1NIC 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 veth1
- NIC statistics:
- peer_ifindex: 12
- # ip link
- .
- .
- 12: veth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
總結
文章中,我們快速了解了OVS/網絡namespaces/Linux bridges/veth對。這些組件在openstack網絡架構中大量使用,理解這些組件有助于我們理解不同的網絡場景。
原文出自:http://blog.csdn.net/halcyonbaby/article/details/41524447