Chinaunix首页 | 论坛 | 博客
  • 博客访问: 530512
  • 博文数量: 104
  • 博客积分: 2089
  • 博客等级: 大尉
  • 技术积分: 1691
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-29 08:48
文章分类

全部博文(104)

文章存档

2015年(1)

2013年(13)

2012年(31)

2011年(59)

分类: LINUX

2012-07-23 10:44:45

说明
 bond技术是在linux2.4以后加入内核。
 一般步骤是
1.把bonding模块加入内核,

2 编辑要绑定的网卡设置,去除地址设定

3 添加bond设备,设置地址等配置

重启网络 

5 在交换机上做支持

具体信息看  内核文档 Documentation/networking/bonding.txt 

参考实例:

Linux双网卡绑定一个IP地址,实质工作就是使用两块网卡虚拟为一块,使用同一个IP地址,是我们能够得到更好的更快的服务。其实这项技术在Sun和Cisco中早已存在,被称为Trunking和Etherchannel技术,在Linux的2.4.x的内核中也采用这这种技术,被称为bonding。

1、bonding 的原理:

什么是bonding需要从网卡的混杂(promisc)模式说起。我们知道,在正常情况下,网卡只接收目的硬件地址(MAC Address)是自身Mac的以太网帧,对于别的数据帧都滤掉,以减轻驱动程序的负担。但是网卡也支持另外一种被称为混杂promisc的模式,可以接 收网络上所有的帧,比如说tcpdump,就是运行在这个模式下。bonding也运行在这个模式下,而且修改了驱动程序中的mac地址,将两块网卡的 Mac地址改成相同,可以接收特定mac的数据帧。然后把相应的数据帧传送给bond驱动程序处理。

2、bonding模块工作方式:

bonding mode=1 miimon=100。miimon是用来进行链路监测的。 比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;mode的值表示工作模式,他共有0-6七种模式,常用的为0,1,6三种。
mode=0:平衡负载模式,有自动备援,但需要”Switch”支援及设定。
mode=1:自动备援模式,其中一条线若断线,其他线路将会自动备援。
mode=6:平衡负载模式,有自动备援,不需要”Switch”支援及设定。
mode=0 (balance-rr)

Round-robin policy: Transmit packets in sequential order from the first available slave through the last. This mode provides load balancing and fault tolerance.

mode=1 (active-backup)

Active-backup policy: Only one slave in the bond is active. A different slave becomes active if, and only if, the active slave fails. The bond’s MAC address is externally visible on only one port (network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior of this mode.

mode=2 (balance-xor)

XOR policy: Transmit based on [(source MAC address XOR'd with destination MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load balancing and fault tolerance.

mode=3 (broadcast)

Broadcast policy: transmits everything on all slave interfaces. This mode provides fault tolerance.

mode=4 (802.3ad)

IEEE 802.3ad Dynamic link aggregation. Creates aggregation groups that share the same speed and duplex settings. Utilizes all slaves in the active aggregator according to the 802.3ad specification. Pre-requisites: 1. Ethtool support in the base drivers for retrieving

the speed and duplex of each slave. 2. A switch that supports IEEE 802.3ad Dynamic link

aggregation. Most switches will require some type of configuration to enable 802.3ad mode.

mode=5 (balance-tlb)

Adaptive transmit load balancing: channel bonding that does not require any special switch support. The outgoing traffic is distributed according to the current load (computed relative to the speed) on each slave. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed receiving slave. Prerequisite: Ethtool support in the base drivers for retrieving the speed of each slave.

mode=6 (balance-alb)

Adaptive load balancing: includes balance-tlb plus receive load balancing (rlb) for IPV4 traffic, and does not require any special switch support. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the local system on their way out and overwrites the source hardware address with the unique hardware address of one of the slaves in the bond such that different peers use different hardware addresses for the server.

3、debian系统的安装配置

3.1、安装ifenslave

  1. apt-get install ifenslave  

3.2、让系统开机自动加载模块bonding

  1. sudo sh -c "echo bonding mode=1 miimon=100 >> /etc/modules"  

3.3、网卡配置

  1. sudo vi /etc/network/interfaces  
  2. #实例内容如下:  
  3. auto lo  
  4. iface lo inet loopback  
  5.   
  6. auto bond0  
  7. iface bond0 inet static  
  8. address 192.168.1.110  
  9. netmask 255.255.255.0  
  10. gateway 192.168.1.1  
  11. dns-nameservers 192.168.1.1  
  12. post-up ifenslave bond0 eth0 eth1  
  13. pre-down ifenslave -d bond0 eth0 eth1  

3.4、重启网卡,完成配置

  1. #如果安装ifenslave后你没有重启计算机,必须手动加载bonding模块。  
  2. sudo modprobe bonding mode=1 miimon=100  
  3. #重启网卡  
  4. sudo /etc/init.d/networking restart  
4、redhat系统的安装配置

4.1、安装ifenslave
redhat默认一般已经安装。未安装的要先安装。

  1. yum install ifenslave  

4.2、让系统开机自动加载模块bonding

  1. sudo sh -c "echo alias bond0 bonding >> /etc/modprobe.conf"  
  2. sudo sh -c "echo options bond0 miimon=100 mode=1 >> /etc/modprobe.conf"  

4.3、网卡配置

  1. sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0  
  2. #eth0配置如下  
  3. DEVICE=eth0  
  4. ONBOOT=yes  
  5. BOOTPROTO=none  
  6.   
  7. sudo vi /etc/sysconfig/network-scripts/ifcfg-eth1  
  8. #eth1配置如下  
  9. DEVICE=eth1  
  10. ONBOOT=yes  
  11. BOOTPROTO=none  
  12.   
  13. sudo vi /etc/sysconfig/network-scripts/ifcfg-bond0  
  14. #bond0配置如下  
  15. DEVICE=bond0  
  16. ONBOOT=yes  
  17. BOOTPROTO=static  
  18. IPADDR=192.168.1.110  
  19. NETMASK=255.255.255.0  
  20. GATEWAY=192.168.1.1  
  21. SLAVE=eth0,eth1  
  22. TYPE=Ethernet  
  23.   
  24. #系统启动时绑定双网卡  
  25. sudo sh -c "echo ifenslave bond0 eth0 eth1 >> /etc/rc.local"  

4.4、重启网卡,完成配置

  1. #如果安装ifenslave后你没有重启计算机,必须手动加载bonding模块。  
  2. sudo modprobe bonding mode=1 miimon=100  
  3. #重启网卡  
  4. sudo /etc/init.d/network restart  
5、交换机etherChannel配置

使用mode=0时,需要交换机配置支持etherChannel。

  1. Switch# configure terminal  
  2. Switch(config)# interface range fastethernet 0/1 - 2  
  3. Switch(config-if-range)# channel-group 1 mode on  
  4. Switch(config-if-range)# end  
  5. Switch#copy run start  


参考



阅读(1520) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~