CentOS6.5系統雙網卡綁定配置詳解

 

多網卡的7種bond模式原理  

 

 

Linux 多網卡綁定

網卡綁定mode共有七種(0~6) bond0、bond1、bond2、bond3、bond4、bond5、bond6

常用的有三種

mode=0:平衡負載模式,有自動備援,但需要”Switch”支援及設定。

mode=1:自動備援模式,其中一條線若斷線,其他線路將會自動備援。

mode=6:平衡負載模式,有自動備援,不必”Switch”支援及設定。

需要說明的是如果想做成mode 0的負載均衡,僅僅設置這裏options bond0 miimon=100 mode=0是不夠的,與網卡相連的交換機必須做特殊配置(這兩個端口應該採取聚合方式),因爲做bonding的這兩塊網卡是使用同一個MAC地址.從原理分析一下(bond運行在mode 0下):

mode 0下bond所綁定的網卡的IP都被修改成相同的mac地址,如果這些網卡都被接在同一個交換機,那麼交換機的arp表裏這個mac地址對應的端口就有多 個,那麼交換機接受到發往這個mac地址的包應該往哪個端口轉發呢?正常情況下mac地址是全球唯一的,一個mac地址對應多個端口肯定使交換機迷惑了。所以 mode0下的bond如果連接到交換機,交換機這幾個端口應該採取聚合方式(cisco稱爲 ethernetchannel,foundry稱爲portgroup),因爲交換機做了聚合後,聚合下的幾個端口也被捆綁成一個mac地址.我們的解 決辦法是,兩個網卡接入不同的交換機即可。

mode6模式下無需配置交換機,因爲做bonding的這兩塊網卡是使用不同的MAC地址。

七種bond模式說明:

第一種模式:mod=0 ,即:(balance-rr) Round-robin policy(平衡掄循環策略)

特點:傳輸數據包順序是依次傳輸(即:第1個包走eth0,下一個包就走eth1….一直循環下去,直到最後一個傳輸完畢),此模式提供負載平衡和容錯能力;但是我們知道如果一個連接或者會話的數據包從不同的接口發出的話,中途再經過不同的鏈路,在客戶端很有可能會出現數據包無序到達的問題,而無序到達的數據包需要重新要求被髮送,這樣網絡的吞吐量就會下降

 

第二種模式:mod=1,即: (active-backup) Active-backup policy(主-備份策略)

特點:只有一個設備處於活動狀態,當一個宕掉另一個馬上由備份轉換爲主設備。mac地址是外部可見得,從外面看來,bond的MAC地址是唯一的,以避免switch(交換機)發生混亂。此模式只提供了容錯能力;由此可見此算法的優點是可以提供高網絡連接的可用性,但是它的資源利用率較低,只有一個接口處於工作狀態,在有 N 個網絡接口的情況下,資源利用率爲1/N

 

第三種模式:mod=2,即:(balance-xor) XOR policy(平衡策略)

特點:基於指定的傳輸HASH策略傳輸數據包。缺省的策略是:(源MAC地址 XOR 目標MAC地址) % slave數量。其他的傳輸策略可以通過xmit_hash_policy選項指定,此模式提供負載平衡和容錯能力

 

第四種模式:mod=3,即:broadcast(廣播策略)

特點:在每個slave接口上傳輸每個數據包,此模式提供了容錯能力

 

第五種模式:mod=4,即:(802.3ad) IEEE 802.3ad Dynamic link aggregation(IEEE 802.3ad 動態鏈接聚合)

特點:創建一個聚合組,它們共享同樣的速率和雙工設定。根據802.3ad規範將多個slave工作在同一個激活的聚合體下。

外出流量的slave選舉是基於傳輸hash策略,該策略可以通過xmit_hash_policy選項從缺省的XOR策略改變到其他策略。需要注意的 是,並不是所有的傳輸策略都是802.3ad適應的,尤其考慮到在802.3ad標準43.2.4章節提及的包亂序問題。不同的實現可能會有不同的適應 性。

必要條件:

條件1:ethtool支持獲取每個slave的速率和雙工設定

條件2:switch(交換機)支持IEEE 802.3ad Dynamic link aggregation

條件3:大多數switch(交換機)需要經過特定配置才能支持802.3ad模式

 

第六種模式:mod=5,即:(balance-tlb) Adaptive transmit load balancing(適配器傳輸負載均衡)

特點:不需要任何特別的switch(交換機)支持的通道bonding。在每個slave上根據當前的負載(根據速度計算)分配外出流量。如果正在接受數據的slave出故障了,另一個slave接管失敗的slave的MAC地址。

該模式的必要條件:ethtool支持獲取每個slave的速率

 

第七種模式:mod=6,即:(balance-alb) Adaptive load balancing(適配器適應性負載均衡)

特點:該模式包含了balance-tlb模式,同時加上針對IPV4流量的接收負載均衡(receive load balance, rlb),而且不需要任何switch(交換機)的支持。接收負載均衡是通過ARP協商實現的。bonding驅動截獲本機發送的ARP應答,並把源硬件地址改寫爲bond中某個slave的唯一硬件地址,從而使得不同的對端使用不同的硬件地址進行通信。

來自服務器端的接收流量也會被均衡。當本機發送ARP請求時,bonding驅動把對端的IP信息從ARP包中複製並保存下來。當ARP應答從對端到達 時,bonding驅動把它的硬件地址提取出來,併發起一個ARP應答給bond中的某個slave。使用ARP協商進行負載均衡的一個問題是:每次廣播 ARP請求時都會使用bond的硬件地址,因此對端學習到這個硬件地址後,接收流量將會全部流向當前的slave。這個問題可以通過給所有的對端發送更新 (ARP應答)來解決,應答中包含他們獨一無二的硬件地址,從而導致流量重新分佈。當新的slave加入到bond中時,或者某個未激活的slave重新 激活時,接收流量也要重新分佈。接收的負載被順序地分佈(round robin)在bond中最高速的slave上

當某個鏈路被重新接上,或者一個新的slave加入到bond中,接收流量在所有當前激活的slave中全部重新分配,通過使用指定的MAC地址給每個 client發起ARP應答。下面介紹的updelay參數必須被設置爲某個大於等於switch(交換機)轉發延時的值,從而保證發往對端的ARP應答 不會被switch(交換機)阻截。

必要條件:

條件1:ethtool支持獲取每個slave的速率;

條件2:底層驅動支持設置某個設備的硬件地址,從而使得總是有個slave(curr_active_slave)使用bond的硬件地址,同時保證每個bond 中的slave都有一個唯一的硬件地址。如果curr_active_slave出故障,它的硬件地址將會被新選出來的 curr_active_slave接管

其實mod=6與mod=0的區別:mod=6,先把eth0流量佔滿,再佔eth1,….ethX;而mod=0的話,會發現2個口的流量都很穩定,基本一樣的帶寬。而mod=6,會發現第一個口流量很高,第2個口只佔了小部分流量

 

 

 

Linux網口綁定 

IMPORTANT
In Red Hat Enterprise Linux 6, interface-specificparameters for the bonding kernel
module must bespecified as a space-separated list in the
BONDING_OPTS="bonding
parameters
" directive in the ifcfg-bondN interface file. Do not specify options
specific to abond in
/etc/modprobe.d/bonding.conf, or in the deprecated
/etc/modprobe.conf file.
The
max_bonds parameter is not interfacespecific and therefore, if required, should be
specified in
/etc/modprobe.d/bonding.conf as follows:
options bonding max_bonds=1
However, the max_bonds parameter should not be set when usingifcfg-bondN files
with the
BONDING_OPTS directive as this directivewill cause the network scripts to create
the bondinterfaces as required.

Note that anychanges to /etc/modprobe.d/bonding.confwill not take effect until
the module isnext loaded. A running module must first be unloaded. See
Chapter 31,
Working with Kernel Modules for more information on loading and unloading modules.

==========================================================================

To create a channel bonding interface, create a file in the /etc/sysconfig/network-scripts/
directory called ifcfg-bondN, replacing N with the number for the interface, such as 0.
The contents of the file can be identical to whatever type of interface is getting bonded, such as an
Ethernet interface. The only difference is that the
DEVICE directive is bondN, replacing N with the
number for the interface. The
NM_CONTROLLED directive can be added to prevent NetworkManager
from configuring this device.
Example 11.1. Example ifcfg-bond0 interface configuration file
The following is an example of a channel bonding interface configuration file:
The MAC address of the bond will be taken from the first interface to be enslaved. It can also be
specified using the HWADDR directive if required. If you want
NetworkManager to control this
interface, remove the
NM_CONTROLLED=no directive, or set it to yes, and add TYPE=Bond and
BONDING_MASTER=yes.
After the channel bonding interface is created, the network interfaces to be bound together must be
configured by adding the
MASTER and SLAVE directives to their configuration files. The configuration files
for each of the channel-bonded interfaces can be nearly identical.
Example 11.2. Example ifcfg-ethX bonded interface configuration file
DEVICE=bond0
IPADDR=192.168.1.1
NETMASK=255.255.255.0
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
NM_CONTROLLED=no
BONDING_OPTS="
bonding parameters separated by spaces"
CHAPTER 11. NETWORK INTERFACES
173
If two Ethernet interfaces are being channel bonded, both eth0 and eth1 can be as follows:
In this example, replace
X with the numerical value for the interface.
Once the interfaces have been configured, restart the network service to bring the bond up. As
root,
issue the following command:
~]# service network restart
To view the status of a bond, view the /proc/ file by issuing a command in the following format:
cat /proc/net/bonding/bondN
For example:
~]$ cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: load balancing (round-robin)
MII Status: down
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0
For further instructions and advice on configuring the bonding module and to view the list of bonding
parameters, see
Section 31.8.1, “Using Channel Bonding”.
Support for bonding was added to
NetworkManager in Red Hat Enterprise Linux 6.3. See
Section 11.2.1, “Ethernet Interfaces” for an explanation of NM_CONTROLLED and the
NM_BOND_VLAN_ENABLED directive.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章