卡饭网 > 其他 > 正文

Debian 双网卡bond

来源:本站整理 作者:梦在深巷 时间:2013-02-23 22:32:57

1. 安装ifenslave
ifenslave的作用是网卡的负载均衡
# apt-get install ifenslave
2. 修改/etc/network/interface

复制代码

代码如下:

{root@b01 359 ~}
# 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
auto <A onclick="tagshow('bond');return false;" href="/tag/bond/">bond</A>0
iface bond0 inet static
address 192.168.1.5
netmask 255.255.255.0
gateway 192.168.1.1
up ifenslave bond0 eth0 eth1
down ifenslave -d bond0 eth0 eth1
dns-nameservers 8.8.8.8
iface eth0 inet static
iface eth1 inet static

3. 加载bonding模块(这块费了大部分时间)

复制代码

代码如下:

# cat /etc/modprobe.d/aliases-bond
install bond0 /sbin/modprobe bonding miimon=100 mode=0

bond的mode一共有七种:

复制代码

代码如下:

0: (balance-rr) Round-robin policy: (平衡抡循环策略):传输数据包顺序是依次传输,直到最后一个传输完毕, 此模式提供负载平衡和容错能力。
1: (active-backup) Active-backup policy:(主-备份策略):只有一个设备处于活动状态。 一个宕掉另一个马上由备份转换为主设备。mac地址是外部可见得。 此模式提供了容错能力。
2:(balance-xor) XOR policy:(广播策略):将所有数据包传输给所有接口。 此模式提供了容错能力。
3:(balance-xor) XOR policy:(平衡策略): 传输根据原地址布尔值选择传输设备。 此模式提供负载平衡和容错能力。
4:(802.3ad) IEEE 802.3ad Dynamic link aggregation.IEEE 802.3ad 动态链接聚合:创建共享相同的速度和双工设置的聚合组。
5:(balance-tlb) Adaptive transmit load balancing(适配器传输负载均衡):没有特殊策略,第一个设备传不通就用另一个设备接管第一个设备正在处理的mac地址,帮助上一个传。
6:(balance-alb) Adaptive load balancing:(适配器传输负载均衡):大致意思是包括mode5,bonding驱动程序截获 ARP 在本地系统发送出的请求,用其中之一的硬件地址覆盖从属设备的原地址。就像是在服务器上不同的人使用不同的硬件地址一样

一个小技巧:
为了防止修改网卡配置或其他配置错误导致不能连接服务器,写一个crontab, 将正确的网卡配置文件恢复后重新network restart或者
重启机器 (iptable等类似风险操作也可以这样来处理)

复制代码

代码如下:

{root@b01 361 ~}
# crontab -l
# m h dom mon dow command
#20 * * * * cp -pr /etc/network/interfaces.org /etc/network/interfaces
#21 * * * * /sbin/init 6

相关推荐