深入理解openstack網(wǎng)絡(luò)架構(gòu)(1) :基礎(chǔ)講解
前言
openstack網(wǎng)絡(luò)功能強大同時也相對更復(fù)雜。本系列文章通過Oracle OpenStack TechPreview介紹openstack的配置,通過各種場景和例子說明openstack各種不同的網(wǎng)絡(luò)組件。本文的目的在于提供openstack網(wǎng)絡(luò)架構(gòu)的全景圖并展示各個模塊是如何一起協(xié)作的。這對openstack的初學(xué)者以及希望理解openstack網(wǎng)絡(luò)原理的人會非常有幫助。首先,我們先講解下一些基礎(chǔ)并舉例說明。
根據(jù)***的icehouse版用戶調(diào)查,基于open vswitch插件的Neutron在生產(chǎn)環(huán)境和POC環(huán)境都被廣泛使用,所以在這個系列的文章中我們主要分析這種openstack網(wǎng)絡(luò)的配置。當(dāng)然,我們知道openstack網(wǎng)絡(luò)支持很多種配置,盡管neutron+open vswitch是最常用的配置,但是我們從未說它是***或者***效的一種方式。Neutron+open vswitch僅僅是一個例子,對任何希望理解openstack網(wǎng)絡(luò)的人是一個很好的切入點。即使你打算使用其他類型的網(wǎng)絡(luò)配置比如使用不同的neutron插件或者根本不使用neutron,這篇文章對你理解openstack網(wǎng)絡(luò)仍是一個很好的開始。
我們在例子中使用的配置是Oracle OpenStack Tech Preview所提供的一種配置。安裝它非常簡單,并且它是一個很好的參考。在這種配置中,我們在所有服務(wù)器上使用eth2作為虛擬機的網(wǎng)絡(luò),所有虛擬機流量使用這個網(wǎng)卡。Oracle OpenStack Tech Preview使用VLAN進(jìn)行L2隔離,進(jìn)而提供租戶和網(wǎng)絡(luò)隔離,下圖展示了我們?nèi)绾芜M(jìn)行配置和部署:
***篇文章會略長,我們將聚焦于openstack網(wǎng)絡(luò)的一些基本概念。我們將討論open vswitch、network namespaces、linux bridge、veth pairs等幾個組件。注意這里不打算全面介紹這些組件,只是為了理解openstack網(wǎng)絡(luò)架構(gòu)。可以通過網(wǎng)絡(luò)上的其他資源進(jìn)一步了解這些組件。
Open vSwitch (OVS)
在Oracle OpenStack Tech Preview中用于連接虛擬機和物理網(wǎng)口(如上例中的eth2),就像上邊部署圖所示。OVS包含bridages和ports,OVS bridges不同于與linux bridge(使用brctl命令創(chuàng)建)。讓我們先看下OVS的結(jié)構(gòu),使用如下命令:
- # 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"
我們看到標(biāo)準(zhǔn)的部署在compute node上的OVS,擁有兩個網(wǎng)橋,每個有若干相關(guān)聯(lián)的port。上邊的例子是在一個沒有任何虛擬機的計算節(jié)點上。我們可以看到eth2連接到個叫br- eth2的網(wǎng)橋上,我們還看到兩個叫“int-br-eth2"和”phy-br-eth2“的port,事實上是一個veth pair,作為虛擬網(wǎng)線連接兩個bridages。我們會在后邊討論veth paris。
當(dāng)我們創(chuàng)建一個虛擬機,br-int網(wǎng)橋上會創(chuàng)建一個port,這個port最終連接到虛擬機(我們會在后邊討論這個連接)。這里是啟動一個虛擬機后的OVS結(jié)構(gòu):
- # 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“網(wǎng)橋現(xiàn)在有了一個新的port"qvocb64ea96-9f" 連接VM,并且被標(biāo)記為vlan1。虛擬機的每個網(wǎng)卡都需要對應(yīng)在"br-int”網(wǎng)橋上創(chuàng)建一個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。然后虛擬機網(wǎng)絡(luò)(eth2)上的port使用tag1000。OVS會修改VM和物理網(wǎng)口間所有package的vlan。在openstack中,OVS agent 控制open vswitch中的flows,用戶不需要進(jìn)行操作。如果你想了解更多的如何控制open vswitch中的流,可以參考http://openvswitch.org中對ovs-ofctl的描述。
#p#
Network Namespaces (netns)
網(wǎng)絡(luò)namespace是linux上一個很cool的特性,它的用途很多。在openstack網(wǎng)絡(luò)中被廣泛使用。網(wǎng)絡(luò)namespace是擁有獨立的網(wǎng)絡(luò)配置隔離容器,并且該網(wǎng)絡(luò)不能被其他名字空間看到。網(wǎng)絡(luò)名字空間可以被用于封裝特殊的網(wǎng)絡(luò)功能或者在對網(wǎng)絡(luò)服務(wù)隔離的同時完成一個復(fù)雜的網(wǎng)絡(luò)設(shè)置。在Oracle OpenStack Tech Preview中我們使用***的R3企業(yè)版內(nèi)核,該內(nèi)核提供給了對netns的完整支持。
通過如下例子我們展示如何使用netns命令控制網(wǎng)絡(luò)namespaces。定義一個新的namespace:
- # ip netns add my-ns
- # ip netns list
- my-ns
我們說過namespace是一個隔離的容器,我們可以在namspace中進(jìn)行各種操作,比如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和網(wǎng)絡(luò)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)
現(xiàn)在我們可以增加更多的ports到OVS bridge,并且連接到其他namespace或者其他設(shè)備比如物理網(wǎng)卡。Neutron使用網(wǎng)絡(luò)namespace來實現(xiàn)網(wǎng)絡(luò)服務(wù),如DHCP、routing、gateway、firewall、load balance等。下一篇文章我們會討論更多細(xì)節(jié) 。
Linux bridge and veth pairs
Linux bridge用于連接OVS port和虛擬機。ports負(fù)責(zé)連通OVS bridge和linux bridge或者兩者與虛擬機。linux bridage主要用于安全組增強。安全組通過iptables實現(xiàn),iptables只能用于linux bridage而非OVS bridage。
Veth對在openstack網(wǎng)絡(luò)中大量使用,也是debug網(wǎng)絡(luò)問題的很好工具。Veth對是一個簡單的虛擬網(wǎng)線,所以一般成對出現(xiàn)。通常Veth對的一端連接到bridge,另一端連接到另一個bridge或者留下在作為一個網(wǎng)口使用。
這個例子中,我們將創(chuàng)建一些veth對,把他們連接到bridge上并測試聯(lián)通性。這個例子用于通常的Linux服務(wù)器而非openstack節(jié)點:創(chuàng)建一個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)
- .
- .
為了讓例子更有意義,我們將創(chuàng)建如下配置:
- veth0 => veth1 =>br-eth3 => eth3 ======> eth2 on another Linux server
br-eht3: 一個基本的Linux bridge,連接veth1和eth3eth3: 一個沒有設(shè)定IP的物理網(wǎng)口,該網(wǎng)口連接著斯有網(wǎng)絡(luò)eth2: 遠(yuǎn)端Linux服務(wù)器上的一個物理網(wǎng)口,連接著私有網(wǎng)絡(luò)并且被配置了IP(50.50.50.1)一旦我們創(chuàng)建了這個配置,我們將通過veth0 ping 50.50.50.1這個遠(yuǎn)端IP,從而測試網(wǎng)絡(luò)聯(lián)通性:
- # 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
如果命名不像例子中這么顯而易見,導(dǎo)致我們無法支持veth設(shè)備的兩端,我們可以使用ethtool命令查詢。ethtool命令返回index號,通過ip link命令查看對應(yīng)的設(shè)備:
- # ethtool -S veth1
- NIC statistics:
- peer_ifindex: 12
- # ip link
- .
- .
- 12: veth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
總結(jié)
文章中,我們快速了解了OVS/網(wǎng)絡(luò)namespaces/Linux bridges/veth對。這些組件在openstack網(wǎng)絡(luò)架構(gòu)中大量使用,理解這些組件有助于我們理解不同的網(wǎng)絡(luò)場景。
原文出自:http://blog.csdn.net/halcyonbaby/article/details/41524447