Think before you speak, read before you think.

linux双网卡绑定

by

in

以下操作均在CentOS下,网卡绑定有多种模式,这里是为了增加带宽

安装需要的组件

yum install ethtool -y

添加一个ifcfg-bond0的配置文件,做为master,需要绑定的物理网卡(ifcfg-eth0, ifcfg-eth1)做为slave

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

添加

DEVICE=bond0
ONBOOT=yes
IPADDR=192.168.1.12
NETMASK=255.255.255.0
NETWORK=192.168.1.0
USERCTL=no
BOOTPROTO=none

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

添加

DEVICE=eth0
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

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

添加

DEVICE=eth1
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

USERCTL=yes/no 是否允许非root用户控制该设备

BOOTPROTO=none/static/dhcp 指定启动协议,这里不指定

如果还有更多网卡,照上面写即可

接下来需要在CentOS中注册一下bonding模块

vim /etc/modprobe.d/bonding.conf

添加

alias bond0 bonding
options bond0 mode=4 miimon=100

mode参数见:

http://unixfoo.blogspot.com/2008/02/network-bonding-part-ii-modes-of.html

  • Mode 0 (balance-rr)
    This mode transmits packets in a sequential order from the first available slave through the last. If two real interfaces are slaves in the bond and two packets arrive destined out of the bonded interface the first will be transmitted on the first slave and the second frame will be transmitted on the second slave. The third packet will be sent on the first and so on. This provides load balancing and fault tolerance.
  • Mode 1 (active-backup)
    This mode places one of the interfaces into a backup state and will only make it active if the link is lost by the active interface. Only one slave in the bond is active at an instance of time. A different slave becomes active only when the active slave fails. This mode provides fault tolerance.
  • Mode 2 (balance-xor)
    Transmits based on XOR formula. (Source MAC address is XOR’d with destination MAC address) modula slave count. This selects the same slave for each destination MAC address and provides load balancing and fault tolerance.
  • Mode 3 (broadcast)
    This mode transmits everything on all slave interfaces. This mode is least used (only for specific purpose) and provides only fault tolerance.
  • Mode 4 (802.3ad)
    This mode is known as Dynamic Link Aggregation mode. It creates aggregation groups that share the same speed and duplex settings. This mode requires a switch that supports IEEE 802.3ad Dynamic link.
  • Mode 5 (balance-tlb)
    This is called as Adaptive transmit load balancing. The outgoing traffic is distributed according to the current load and queue on each slave interface. Incoming traffic is received by the current slave.
  • Mode 6 (balance-alb)
    This is Adaptive load balancing mode. This includes balance-tlb + receive load balancing (rlb) for IPV4 traffic. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the server on their way out and overwrites the src hw address with the unique hw address of one of the slaves in the bond such that different clients use different hw addresses for the server.

mode的值表示工作模式,共有7种模式,常用的为0,1,4三种。

mode=0表示load balancing (round-robin)为负载均衡方式,两块网卡都工作。
mode=1表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份
mode=4是通用的802.3ad协议,类似于第一种,接思科交换机时需要选LACP模式。

miimon是用来进行链路监测的。比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;

重启网络服务

service network restart

使用watch -n 1可以每秒更新bond0的状态

watch -n 1 'cat /proc/net/bonding/bond0'

参考:http://www.cyberciti.biz/howto/question/static/linux-ethernet-bonding-driver-howto.php


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *