bond不同模式下网卡流量分配

大家常用的bond模式主要是mode 1和4.其中mode1就是简单的主备模式,mode4是两个网卡都有流量的。以下是每种模式的简单介绍:

balance-rr or 0 — Sets a round-robin policy for fault tolerance and load balancing. Transmissions are received and sent out sequentially on each bonded slave interface beginning with the first one available.

active-backup or 1 — Sets an active-backup policy for fault tolerance. Transmissions are received and sent out via the first available bonded slave interface. Another bonded slave interface is only used if the active bonded slave interface fails.

balance-xor or 2 — Sets an XOR (exclusive-or) policy for fault tolerance and load balancing. Using this method, the interface matches up the incoming request’s MAC address with the MAC address for one of the slave NICs. Once this link is established, transmissions are sent out sequentially beginning with the first available interface.

broadcast or 3 — Sets a broadcast policy for fault tolerance. All transmissions are sent on all slave interfaces.

802.3ad or 4 — Sets an IEEE 802.3ad dynamic link aggregation policy. Creates aggregation groups that share the same speed and duplex settings. Transmits and receives on all slaves in the active aggregator. Requires a switch that is 802.3ad compliant.

balance-tlb or 5 — Sets a Transmit Load Balancing (TLB) policy for fault tolerance and load balancing. The outgoing traffic is distributed according to the current load on each slave interface. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed slave.

balance-alb or 6 — Sets an Active Load Balancing (ALB) policy for fault tolerance and load balancing. Includes transmit and receive load balancing for IPV4 traffic. Receive load balancing is achieved through ARP negotiation.

对于mode0,可以直接在线把1个网卡disable,也可以改变起主备状态:
1. 把一个网卡eth1从bond0中去除
ifenslave -d bond0 eth1
2. 把一个网卡eth1加入bond0中
ifenslave bond0 eth1

3.切换当前的active网卡(mode1)到eth1
ifenslave -c bond0 eth1

对于mode0来说,始终只有active的网卡有流量,大家在配置网卡的时候会加一些参数,指定master网卡 :
BONDING_OPTS=”miimon=100 mode=1 primary=eth0″
大家也经常在使用mode0的时候加入updelay(单位是毫秒,需要是miimon的整数倍)参数,设置当网卡up指定的时间后才能变成active,防止master的网卡刚启动其实还不能正常服务就被变成active了。

对应mode4来说会比较复杂一点,mode4是双活的,所以入口的流量(2个网卡双活的前提下)到底在那个网卡上其实是由交换机上hash出来的,其实在服务器上是不能改变的,一般也是正对源IP,源端口,源MAC什么的hash,每个厂商的可能有不通。对于出口的流量是可以自己控制的,主要是根据xmit_hash_policy的设置而异,一般是:

0 or layer2 —
Default setting. This parameter uses the XOR of hardware MAC addresses to generate the hash. The formula used is:
(XOR ) MODULO
This algorithm will place all traffic to a particular network peer on the same slave, and is 802.3ad compliant.

1 or layer3+4 —
Uses upper layer protocol information (when available) to generate the hash. This allows for traffic to a particular network peer to span multiple slaves, although a single connection will not span multiple slaves.
The formula for unfragmented TCP and UDP packets used is:
((XOR ) XOR ((XOR ) AND 0xffff) MODULO
For fragmented TCP or UDP packets and all other IP protocol traffic, the source and destination port information is omitted. For non-IP traffic, the formula is the same as the layer2 transmit hash policy.
This policy intends to mimic the behavior of certain switches; particularly, Cisco switches with PFC2 as well as some Foundry and IBM products.
The algorithm used by this policy is not 802.3ad compliant.

2 or layer2+3 —
Uses a combination of layer2 and layer3 protocol information to generate the hash.
Uses XOR of hardware MAC addresses and IP addresses to generate the hash. The formula is:
(((XOR ) AND 0xffff) XOR(XOR )) MODULO
This algorithm will place all traffic to a particular network peer on the same slave. For non-IP traffic, the formula is the same as for the layer2 transmit hash policy.
This policy is intended to provide a more balanced distribution of traffic than layer2 alone, especially in environments where a layer3 gateway device is required to reach most destinations.
This algorithm is 802.3ad compliant.

我们一般layer3+4和layer2+3都有使用,想均匀一点可以优先考虑layer3=4.发一个机器上的截图

bind1
从图上开入口流量还是比较均衡的,不过出口流量不是太均衡,主要是因为从本机是只向几个远程机器同步数据,所以出口的流量不是太均衡。

此条目发表在net, System分类目录。将固定链接加入收藏夹。