Linux--多網卡的7種Bond模式和交換機配置


網卡bond是通過把多張網卡綁定為一個邏輯網卡,實現本地網卡的冗余,帶寬擴容和負載均衡。在應用部署中是一種常用的技術,我們公司基本所有的項目相關服務器都做了bond,這里總結整理,以便待查。

bond模式:

  1. Mode=0(balance-rr) 表示負載分擔round-robin,和交換機的聚合強制不協商的方式配合。
  2. Mode=1(active-backup) 表示主備模式,只有一塊網卡是active,另外一塊是備的standby,這時如果交換機配的是捆綁,將不能正常工作,因為交換機往兩塊網卡發包,有一半包是丟棄的。
  3. Mode=2(balance-xor) 表示XOR Hash負載分擔,和交換機的聚合強制不協商方式配合。(需要xmit_hash_policy)
  4. Mode=3(broadcast) 表示所有包從所有interface發出,這個不均衡,只有冗余機制...和交換機的聚合強制不協商方式配合。
  5. Mode=4(802.3ad) 表示支持802.3ad協議,和交換機的聚合LACP方式配合(需要xmit_hash_policy)
  6. Mode=5(balance-tlb) 是根據每個slave的負載情況選擇slave進行發送,接收時使用當前輪到的slave
  7. Mode=6(balance-alb) 在5的tlb基礎上增加了rlb。

5和6不需要交換機端的設置,網卡能自動聚合。4需要支持802.3ad。0,2和3理論上需要靜態聚合方式
但實測中0可以通過mac地址欺騙的方式在交換機不設置的情況下不太均衡地進行接收。

 

常用的有三種

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地址。

來段英文的

  • mode=0 (Balance Round Robin) per packet
  • mode=1 (Active backup)
  • mode=2 (Balance XOR)
  • mode=3 (Broadcast)
  • mode=4 (802.3ad)
  • mode=5 (Balance TLB)
  • mode=6 (Balance ALB)

Modes of bonding :

RHEL bonding supports 7 possible “modes” for bonded interfaces. These modes determine the way in which traffic sent out of the bonded interface is actually dispersed over the real interfaces. Modes 0, 1, and 2 are by far the most commonly used among them.
    • Mode 0 (balance-rr)
      This mode transmits packets in a sequential order from the first available slave through the last. If two real interfaces are slaves in the bond and two packets arrive destined out of the bonded interface the first will be transmitted on the first slave and the second frame will be transmitted on the second slave. The third packet will be sent on the first and so on. This provides load balancing and fault tolerance.
    • Mode 1 (active-backup)
      Mode 1 places one of the interfaces into a backup state and will only make it active if the link is lost by the active interface. Only one slave in the bond is active at an instance of time. A different slave becomes active only when the active slave fails. This mode provides fault tolerance.
    • Mode 2 (balance-xor)
      Transmits based on XOR formula. (Source MAC address is XOR’d with destination MAC address) modula slave count. This selects the same slave for each destination MAC address and provides load balancing and fault tolerance.
    • Mode 3 (broadcast)
      The broadcast mode transmits everything on all slave interfaces. This mode is least used (only for a specific purpose) and provides only fault tolerance.
    • Mode 4 (802.3ad)
      The 802.3ad mode is known as Dynamic Link Aggregation mode. It creates aggregation groups that share the same speed and duplex settings. This mode requires a switch that supports IEEE 802.3ad Dynamic link. Slave selection for outgoing traffic is done according to the transmit hash policy, which may be changed from the default simple XOR policy via the xmit_hash_policy option. Note that not all transmit policies may be 802.3ad compliant, particularly in regards to the packet mis-ordering requirements of section 43.2.4 of the 802.3ad standard. Differing peer implementations will have varying tolerances for noncompliance.
    • Mode 5 (balance-tlb)
      This is called as Adaptive transmit load balancing. The outgoing traffic is distributed according to the current load and queue on each slave interface. Incoming traffic is received by the current slave.
    • Mode 6 (balance-alb)
      This is Adaptive load balancing mode. This includes balance-tlb + receive load balancing (rlb) for IPV4 traffic. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the server on their way out and overwrites the src hw address with the unique hw address of one of the slaves in the bond such that different clients use different hw addresses for the server.

參考鏈接

https://www.cnblogs.com/lcword/p/5914089.html

https://www.cloudibee.com/network-bonding-modes/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM