龍君芳
RHEL7 Network Teaming(網(wǎng)卡綁定)配置與測試
龍君芳
(廣東技術(shù)師范學(xué)院天河學(xué)院,廣東 廣州 510540)
本文重點介紹Network Teaming的兩種模式(輪循與主備)的原理與配置。本文采用命令行設(shè)置與修改配置文件兩種不同的方法對Network Teaming進行配置,其中用命令行的方式配置了輪循模式,用修改配置文件的方式來配置主備模式。
Network Teaming;輪循;主備
現(xiàn)在的服務(wù)器至少都有兩個網(wǎng)卡,如何同時充分利用這兩張網(wǎng)卡,RHEL7推出了它的應(yīng)用Network Teaming。Network Teaming是將多個網(wǎng)卡綁定在一起,在邏輯上來講就相當(dāng)于一個網(wǎng)卡,它可以提高網(wǎng)絡(luò)的容錯與吞吐量。在RHEL7中使用的是Teaming技術(shù),而在RHEL6使用的是Bonding技術(shù)。Teaming是一項新的實現(xiàn)技術(shù),不影響老的Bonding技術(shù)的應(yīng)用。配置Teaming有兩種方式,第一種是使用nmcli命令,第二種是直接修改配置文件。
Teaming模式有 broadcast、roundrobin、activebackup、loadbalance、lacp幾種,下面介紹最常用的兩種模式。
2.1 roundrobin模式
roundrobin模式也稱為輪循模式,它是基于每一個包的,當(dāng)某一臺服務(wù)器的兩個網(wǎng)卡設(shè)置為roundrobin模式的Teaming,此時服務(wù)器發(fā)出的數(shù)據(jù)包,就會在兩個物理網(wǎng)卡上進行輪循,即第一個數(shù)據(jù)包走第一個網(wǎng)卡,第二個數(shù)據(jù)包走第二個網(wǎng)卡,第三個數(shù)據(jù)包走第一個網(wǎng)卡,第四個數(shù)據(jù)包走第二個網(wǎng)卡,依此輪循。這種模式需要交換機的支持,必須要在交換機上做以太通道。拓撲設(shè)計圖如1所示:
圖1 roundrobin模式拓撲設(shè)計圖
該模式配置步驟如下:
(1)服務(wù)器上的配置
步驟1:查看網(wǎng)卡
[root@localhost~]#ip addr
通過上面的命令,發(fā)現(xiàn)有兩個網(wǎng)卡,ens33與ens37
步驟2:創(chuàng)建team接口team0,同時設(shè)置teaming模式為roundrobin
[root@localhost~]#nmcli connection add type team con-name team0 ifnameteam0 config '{"runner":{"name":"roundrobin"}}'
步驟3:給接口team0設(shè)置IP地址
[root@localhost~]#nmcli connection modify team0 ipv4.a(chǎn)ddresses 192.168.1.1/24
[root@localhost~]#nmcli connection modify team0 ipv4.method manual
步驟4:把物理接口加入到team0
[root@localhost~]#nmcli connection add type team-slave conname team0-port1 ifname ens33 master team0
[root@localhost~]#nmcli connection add type team-slave conname team0-port2 ifname ens37 master team0
(2)查看team0狀態(tài)
可以看出,teaming的模式為roundrobin,同時有兩個物理接口,分別是ens33與ens37,都是up的狀態(tài)。
[root@localhost~]#teamdctl team0 state
setup:
runner:roundrobin
ports:
ens33
link watches:
link summary:up
instance[link_watch_0]:
name:ethtool
link:up
ens37
link watches:
link summary:up
instance[link_watch_0]:
name:ethtool
link:up
(3)交換機上配置以太通道,可以參考交換機的配置手冊
(4)測試
從兩方面進行測試,首先測試禁用其中某一塊網(wǎng)卡,別一塊網(wǎng)卡會不會照常工作,測試如下:
在一臺windows主機上ping服務(wù)器的時候,加上-t參數(shù),也就是說一直ping下去,然后在服務(wù)器上禁用某一個網(wǎng)卡,執(zhí)行命令:
[root@localhost network-scripts]#nmcli device disconnect ens33,
查看在windows主機上還是能ping通服務(wù)器的。
測試的另一方面是看它們之間有沒有輪循,可以采用抓包的方式,比如ping四個包,如果第一塊網(wǎng)卡上面有兩個請求包,第二塊網(wǎng)卡上有兩個請求包,就說明它們之間有輪循。
2.2 activebackup模式
activebackup是主備模式,不需要交換機的支持,當(dāng)網(wǎng)卡綁定成這種模式之后,此時一個物理網(wǎng)卡的狀態(tài)是主的,一個物理網(wǎng)卡的狀態(tài)是備的,平時是利用主的網(wǎng)卡傳輸數(shù)據(jù)包,當(dāng)主網(wǎng)卡失效之后,備用的網(wǎng)卡就會接管主網(wǎng)卡,進行工作。
拓撲同上,配置步驟如下:
(1)服務(wù)器上的配置
步驟1:配置team0的配置文件
[root@localhost~]#cd/etc/sysconfig/network-scripts
[root@localhost network-scripts]#cat ifcfg-team0
DEVICE=team0
TEAМ_CONFIG="{"runner":{"name":"activebackup"}}"
DEVICETYPE=Team
BOOTPROTO=none
NAМE=team0
ONBOOT=yes
IPADDR0=192.168.1.1
PREFIX0=24
步驟2:配置team0-port1與team0-port2
[root@localhost network-scripts]#cat ifcfg-team0-port1
NAМE=team0-port1
DEVICE=ens33
ONBOOT=yes
TEAМ_МASTER=team0
DEVICETYPE=TeamPort
[root@localhost network-scripts]#
[root@localhost network-scripts]#cat ifcfg-team0-port2
NAМE=team0-port2
DEVICE=ens37
ONBOOT=yes
TEAМ_МASTER=team0
DEVICETYPE=TeamPort
步驟3:啟動team0
[root@localhost network-scripts]#systemctl restart network
(2)查看teaming
[root@localhost network-scripts]#teamdctl team0 state
setup:
runner:activebackup
ports:
ens33
link:up
ens37
link:up
runner:
active port:ens33
(3)測試
1)可以在另外一臺主機來ping此臺服務(wù)器,當(dāng)禁用主網(wǎng)卡ens33的時候,另一個備用網(wǎng)卡ens37就會接管工作。
[root@localhost network-scripts]#nmcli device disconnect ens33
[root@localhost network-scripts]#teamdctl team0 state
<輸出省略>
active port:ens37
2)啟用網(wǎng)卡ens33,為了高可用性,ens37還處于active狀態(tài)。
[root@localhost network-scripts]#nmcli connection up team0-port1
[root@localhost network-scripts]#teamdctl team0 state
<輸出省略>
active port:ens37
RHEL7的網(wǎng)卡綁定技術(shù),不僅可以實現(xiàn)冗余,還可以提高網(wǎng)絡(luò)的吞吐量。而且還有多種模式可以選擇,有效地利用了兩塊網(wǎng)卡。
[1]Otto.接觸Linux RedHat7.3[N].電腦報,2012-07-29.
[2]黃秀麗.基于嵌入式Linux的實時性改進的研究與應(yīng)用[J].遼寧師專學(xué)報(自然科學(xué)版),2005,(02).
The Configuration and Test of RHEL7 Network Teaming(network card binding)
Long Junfang
(Tianhe College of Guangdong Polytechnic Normal University,Guangzhou 510540,Guangdong)
tract】 This paper focuses on the principle and configuration of two modes of Network Teaming(roundrobin and activebackup).It uses the command line setup and configuration files modification to configure the Network Teaming.The command line setup is used for roundrobin,while the configuration file modification is used for activebackup.
words】 network teaming;roundrobin;activebackup
龍君芳,女,湖南衡陽人,學(xué)士,講師,研究方向:計算機科學(xué)與技術(shù)。