linux中可以将2块物理网卡绑定在一起并虚拟出一块bond网卡用来提高性能(负载或高可用)

1、查看linux是否支持bonding:

# modinfo bonding

filename:       /lib/modules/2.6.32-358.6.2.el6.i686/kernel/drivers/net/bonding/bonding.ko

author:         Thomas Davis, tadavis@lbl.gov and many others

description:    Ethernet Channel Bonding Driver, v3.6.0

version:        3.6.0

license:        GPL

srcversion:     E440B07A7F6C1C364F47622

2、bond驱动设置

bonding驱动是通过模块来加载的

vim /etc/modprobe.d/bonding.conf

alias bond0 bonding
options bond0 miimon=100 mode=0
说明:
miimon是用来进行链路监测的。 比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;
mode的值表示工作模式,他共有0,1,2,3四种模式,常用的为0,1两种。
  mode=0表示load balancing (round-robin)为负载均衡方式,两块网卡都工作。

  mode=1表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份.  

3、修改网卡参数:

vim /etc/sysconfig/network-scripts/ifcfg-eth0

     DEVICE="eth0"

     ONBOOT="yes"

      BOOTPROTO="static"

      MASTER=bond0

      SLAVE=yes   ------必须为小写,否则会有问题!

vim /etc/sysconfig/network-scripts/ifcfg-eth1

      DEVICE=“eth1”

      ONBOOT=”yes“

       MASTER=bond0

       SLAVE=yes

       BOOTPROTO=“static”

物理网卡只留上面5行,其它行注释掉:

vim /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE="bond0"

BOOTPROTO="static"

IPADDR=192.168.15.81

NETMASK=255.255.255.0

GATEWAY=192.168.15.1

#DNS1=192.168.15.100

#HWADDR="00:0C:29:56:DC:CC"

#NM_CONTROLLED="yes"

#PEERDNS=no

ONBOOT="yes"

TYPE="Ethernet"

#UUID="bf24e005-f7ff-4b7e-b003-172c5119ea0f"

4、启动bonding:

/etc/init.d/network restart

5、查看网卡参数:

151746360.jpg

发现MAC地址都一样了!

6、测试:

ifdown eth1

看网卡是否正常工作