網卡bonding可以帶來網絡處理能力的提升,網絡接口的冗餘等.
前提條件:至少兩塊可用的網卡,下面以簡潔的步驟描述如何快速配置bonding:
1.加載內核模塊
vi /etc/modules 加入
bonding
配置好後類似以下:
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
loop
lp
rtc
bonding
2.斷開網絡
stop networking
3.加載模塊
modprobe bonding
4.編輯網卡配置,加入bonding
vi /etc/network/interfaces eth0 eth1設置爲bonding模式,編輯好後類似如下:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet manual
bond-master bond0
auto eth1
iface eth1 inet manual
bond-master bond0
auto bond0
iface bond0 inet static
address 192.168.1.110
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
# load balancing and fault tolerance
#bond-mode balance-rr
bond-mode 802.3ad
bond-miimon 100
bond-lacp-rate 1
bond-slaves none
#bond-downdelay 200
#bond-updelay 200
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 192.168.1.1
5.啓動網絡
start networking
注:這裏的bond-mode有多種,根據實際情況和需求進行設置:
- Mode 0
-
balance-rr
Round-robin policy: 從第一塊可用的slave網卡開始順序傳輸數據包.擁有負載均衡和容錯的能力。
- Mode 1
-
active-backup
Active-backup policy: 同一時刻只有一塊網卡處於工作模式,另外一塊僅當active出現故障時纔會啓用.
- Mode 2
-
balance-xor
XOR policy: 基於目的mac異或運算傳輸數據包,提供負載均衡和容錯能力.
- Mode 3
-
broadcast
Broadcast policy: 所有數據包要傳送至所有slave,具有很高的容錯能力.
- Mode 4
-
802.3ad 遵循IEEE 802.3ad 規範.
Mode 5
balance-tlb
自適應負載均衡: 流出流量基於當前各slave速率負載. 進入流量由當前active slave接收.如果流入處理失敗,由其他slave接替.
Mode 6
balance-alb
自適應負載均衡: 包含tlb和rlb, 流入負載基於arp協商.
參考文檔:https://help.ubuntu.com/community/UbuntuBonding
其他參考:https://www.kernel.org/doc/Documentation/networking/bonding.txt
younstar原創內容,本人轉載