Bonding
来自三叶草知识库
bonding的原理
在正常情况下,网卡只接收目的硬件地址(MAC Address)是自身Mac的以太网帧,对于别的数据帧都过滤掉,以减轻驱动程序的负担。但是网卡也支持另外一种被称为混杂的模式,可以接收网络上所有的帧,比如说很多用物抓包工具就需要让网卡运行在这个模式下。bonding也运行在这个模式下,而且修改了驱动程序中的MAC地址,将两块网卡的MAC地址改成相同,可以接收特定MAC的数据帧。然后把相应的数据帧传送给bond驱动程序处理。
bonding模块工作方式
bonding有0-6七种模式,常用的工作方式为0、1、6三种:
mode=0:表示load balancing(round-robin)为负载均衡模式(两块网卡都要工作),但需要交换机支持并需要在交换机上进行相应配置。
mode=1:表示fault-tolerance(active-backup)提供冗余功能,工作方式是主务的方式,也就是说默认情况下只有一块网卡工作,另一块做备份。
mode=6:表示load balancing(round-robin)为负载均衡模式(两块网卡都要工作),不需要交换机支持。
bonding HA配置
以下配置基于debian7 64bit安装配置mode 1方式 安装bonding组件
apt-get install ifenslave
设置开机自动加载模块(miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;mode的值表示bonding工作模式。)
sh -c "echo bonding mode=6 miimon=100 >> /etc/modules"
加载bonding模块
modprobe bonding mode=1 miimon=100
网卡配置文件如下:
auto bond0 iface bond0 inet static address 192.168.120.101 netmask 255.255.254.0 gateway 192.168.120.1 dns-nameservers 8.8.8.8 bond-slaves none bond-mode 1 bond-miimon 100 #post-up ifenslave bond0 eth0 eth2 #pre-down ifenslave -d bond0 eth0 eth2 auto eth0 iface eth0 inet manual bond-master bond0 bond-primary eth0 eth2 auto eth2 iface eth2 inet manual bond-master bond0 bond-primary eth0 eth2
重启网络
/etc/init.d/networking restart