在 linux 中可以很简单的把多个网卡绑定成一个网卡来使用,可以达到增加带宽、负载均衡、冗余的目的。这里使用 ubuntu 来设置:
1.安装
# sudo apt-get install ifenslave
加入以下内容:
alias bond0 bonding
options bond0 mode=balance-alb miimon=100 max_bonds=2
2.配置
在 /etc/network/interfaces 中修改为:
# 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
auto bond0
iface bond0 inet static
address 169.254.195.249
netmask 255.255.0.0
broadcast 169.254.255.255
#gateway 192.168.1.1
# The primary network interface
slave eth0 eth1
up ifenslave bond0 eth0 eth1
down ifenslave bond0 -d eth0 eth1
bond-mode balance-rr
bond-miimon 100
双网卡情况,多网卡依次类推。
.重启后便可以使用,测试。
# ifconfig -a
可以显示bond0, eth0, eth1, loop
================================================
bonding 的7种模式
0:(balance-rr) Round-robin policy: (平衡轮询策略):传输数据包顺序是依次传输,直到最后一个传输完毕, 此模式提供负载平衡和容错能力。
1:(active-backup) Active-backup policy:(活动备份策略):只有一个设备处于活动状态。 一个宕掉另一个马上由备份转换为主设备。mac地址是外部可见得。 此模式提供了容错能力。
2:(balance-xor) XOR policy:(平衡策略):传输根据[(源MAC地址xor目标MAC地址) mod 设备数量]的布尔值选择传输设备。 此模式提供负载平衡和容错能力。
3:(broadcast) Broadcast policy:(广播策略):将所有数据包传输给所有设备。 此模式提供了容错能力。
4:(802.3ad) IEEE 802.3ad Dynamic link aggregation. IEEE 802.3ad动态链接聚合:创建共享相同的速度和双工设置的聚合组。此模式提供了容错能力。每个设备需要基于驱动的重新获取速度和全双工支持;如果使用交换机,交换机也需启用 802.3ad 模式。
5:(balance-tlb) Adaptive transmit loadbalancing(适配器传输负载均衡):通道绑定不需要专用的交换机支持。发出的流量根据当前负载分给每一个设备。由当前设备处理接收,如果接受的设备传不通就用另一个设备接管当前设备正在处理的mac地址。
6:(balance-alb) Adaptive load balancing: (适配器负载均衡):包括mode5,由 ARP协商完成接收的负载。bonding驱动程序截获 ARP在本地系统发送出的请求,用其中之一的硬件地址覆盖从属设备的原地址。就像是在服务器上不同的人使用不同的硬件地址一样。
================================================