网卡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 0balance-rr
Round-robin policy: 从第一块可用的slave网卡开始顺序传输数据包.拥有负载均衡和容错的能力。
Mode 1active-backup
Active-backup policy: 同一时刻只有一块网卡处于工作模式,另外一块仅当active出现故障时才会启用.
Mode 2balance-xor
XOR policy: 基于目的mac异或运算传输数据包,提供负载均衡和容错能力.
Mode 3broadcast
Broadcast policy: 所有数据包要传送至所有slave,具有很高的容错能力.
Mode 4802.3ad 遵循IEEE 802.3ad 规范.
Mode 5
balance-tlb
自适应负载均衡: 流出流量基于当前各slave速率负载. 进入流量由当前active slave接收.如果流入处理失败,由其他slave接替.
Mode 6
balance-alb
自适应负载均衡: 包含tlb和rlb, 流入负载基于arp协商.
参考文档:
其他参考:https://www.kernel.org/doc/Documentation/networking/bonding.txt