ubuntu bond

Linux bonding驱动提供了一个把多个网络接口设备捆绑为单个的网络接口设置来使用,用于网络负载均衡及网络冗余。

bonding一共有7种工作模式(mode):

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 load balancing(适配器传输负载均衡):通道绑定不需要专用的交换机支持。发出的流量根据当前负载分给每一个设备。由当前设备处理接收,如果接受的设 备传不通就用另一个设备接管当前设备正在处理的mac地址。

6:(balance-alb) Adaptive load balancing: (适配器负载均衡):包括mode5,由 ARP 协商完成接收的负载。bonding驱动程序截获 ARP在本地系统发送出的请求,用其中之一的硬件地址覆盖从属设备的原地址。就像是在服务器上不同的人使用不同的硬件地址一样。

1.安装ifenslave软件

ifenslave为一种粘合和分离式的软件,可以将数据包有效的分配到bonding驱动。

sudo apt-get install ifenslave

2.Add bonding to kernel (package ifenslave mentioned above)

echo bonding >> /etc/modules
modprobe bonding

echo 8021q >> /etc/modules

modprobe 8021q

root@ubuntu:~# cat /etc/modules
# /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.
# Parameters can be specified after the module name.

lp
rtc
bonding
8021q

root@ubuntu:~# cat /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

# The primary network interface
auto eth0
iface eth0 inet static
address 172.18.240.150
netmask 255.255.255.0
network 172.18.240.0
broadcast 172.18.240.255
gateway 172.18.240.2
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 172.18.240.2

auto bond0
iface bond0 inet manual
bond-mode 4
bond-miimon 100
bond-lacp-rate 1
bond-slaves none

auto eth1
iface eth1 inet manual
bond-master bond0

auto eth2
iface eth2 inet manual
bond-master bond0

auto bond0.15
iface bond0.15 inet static
address 172.25.15.10/24
gateway 172.25.15.1
vlan-raw-device bond0


root@ubuntu:~# ifconfig | grep HWaddr
bond0 Link encap:Ethernet HWaddr 00:0c:29:24:8e:85    #bond和子接口的MAC会变成bond中最先up起来的member接口的MAC
bond0.15 Link encap:Ethernet HWaddr 00:0c:29:24:8e:85 
docker0 Link encap:Ethernet HWaddr 02:42:87:6b:f5:23 
eth1 Link encap:Ethernet HWaddr 00:0c:29:24:8e:85
eth2 Link encap:Ethernet HWaddr 00:0c:29:24:8e:85

原文地址:https://www.cnblogs.com/marcoxu/p/7820335.html