in the production environment, Linux servers are generally guaranteed to provide the network transmission service 24x7, in order to ensure that a single network card failure and data transmission will not be interrupted and refer to the NIC binding technology-bonding.
Bonding is to bind multiple network cards to the same IP address to provide services externally, can achieve high availability or load balancing. Of course, it is not possible to set the same IP address directly for two NICs. Through bonding, the virtual one network card provides the connection, the physical network card is changed to the same MAC address.
Overview:
There are currently seven types of NIC bindings mode (0~6) bond0,bond1,bond2,bond3, Bond4, Bond5,Bond6
There are three kinds of commonly used :
Mode=0: Balanced load mode with automatic redundancy, but requires "Switch" Support and settings.
Mode=1: Automatic redundancy mode, where one line is disconnected, other lines will be automatically redundant.
Mode=6: Balanced load mode with automatic redundancy without "Switch" Support and settings.
Description :
It should be explained that if you want to make mode 0 load balancer , just set here optionsbond0 miimon=100 mode=0 is not enough , The switch connected to the NIC must be specially configured (both ports should be aggregated) because the two NICs that do bonding are using the same MAC address . from the principle analysis (bond runs under Mode0 ):
Mode 0underBondOf the NIC that is boundIphave been modified to the sameMacaddress, if these NICs are connected to the same switch, then the switch'sArpthe table .Macthe address corresponds to a port that has moreThe switch receives a send to thisMacwhich port should the packet of the address be forwarded to? Under normal circumstancesMacaddress is the only one in the world, aMacan address that corresponds to multiple ports must have confused the switch. SoMode0under theBondIf you connect to the switch, these ports on the switch should be aggregated (CiscocalledEthernetchannel,FoundrycalledPortGroup), since the switches are aggregated, several ports under aggregation are also bundled into aMacAddress.Our SolutionsThe solution is that two network cards can be connected to different switches.
There is no need to configure the switch in Mode6, Mode1, MODE5 mode, because the two NICs that do bonding use different MAC addresses.
Description of seven bond modes:
First mode:mod=0 , ie:(BALANCE-RR) Round-robinpolicy (balanced Whirl cycle strategy)
Features: the transmission packet sequence is transmitted sequentially (i.e.: the first 1 packets go eth0, the next package will go eth1 .... The loop continues until the last transmission is complete), this mode provides load balancing and fault tolerance; but we know that if a connection or session packet is sent from a different interface, then through a different link, there is a good chance that the packet will arrive at the client. and the packets arriving in the packet need to be sent again, so the throughput of the network will drop
second mode: mod=1 ( Active-backup) active-backup policy (main -
Features: only one device is active, and when one is down the other is converted to the primary device immediately by the backup. the MAC address is externally visible, and from the outside, the MAC address of the Bond is unique to avoid the switch from confusing. This mode only provides fault tolerance, so the advantage of this algorithm is that it can provide high availability of network connection, but its resource utilization is low, only one interface is working, and the resource utilization is 1/n in the case of N network interface.
Third mode:mod=2, ie:(balance-xor) XORpolicy (balancing strategy)
feature: transmits packets based on the specified transfer HASH policy. The default policy is:( source mac address XOR destination mac address )% slave number. Other transport policies can be specified through the xmit_hash_policy option, which provides load balancing and fault tolerance
Fourth mode:mod=3, i.e.:broadcast(broadcast strategy)
feature: Each packet is transmitted on each slave interface, and this mode provides fault tolerance
fifth mode: mod=4 (802.3AD) IEEE 802.3ad Dynamic link Aggregation ieee802.3ad
Create an aggregation group, They share the same rate and duplex settings. According to the 802.3ad specification will be multiple slave work under the same active aggregate. Outgoing traffic slave election is based on transmission Hash policy, which can be xmit_hash_policy option from the default xor Policy changes to other policies. Note the Yes, not all transmission strategies are 802.3ad Adapted, especially considering the 802.3ad standard 43.2.4 The problem of packet disorder mentioned in the chapter. Different implementations may have different adaptations to the sex.
Necessary:
condition 1:ethtool supports obtaining rate and duplex settings for each slave
condition 2:switch supports IEEE802.3ad Dynamic link Aggregation
condition 3: most switch ( switches ) require a specific configuration to support 802.3ad mode
Sixth mode:mod=5, i.e.:(balance-tlb) Adaptive Transmit load Balancing(Adapter transport load balancer)
Features: no special switch ( switch ) supported channel bonding is required. out-of-office traffic is allocated on each slave based on the current load (calculated based on speed). If the slave that is accepting data fails, the other slave takes over the MAC address of the failed slave .
required for this pattern:ethtool supports getting the rate per slave
Seventh mode:mod=6, i.e.:(BALANCE-ALB) Adaptive load Balancing(Adapter Adaptive load balancer)
Features: This mode includes the balance-tlb mode, plus receive load Balancing for IPV4 traffic (receiveload balance, RLB), and does not require any support for switch ( switches ) . Receive load balancing is implemented through ARP negotiation. the bonding driver intercepts the ARP response sent by the native and overwrites the source hardware address with the unique hardware address of a slave in bond. This enables different peer-to-peer use of different hardware addresses for communication.
receive traffic from the server side is also balanced. When this machine sendsArpwhen requested,BondingDrive to the end of theIpinformation fromArpCopy and save the package. WhenArpwhen the answer is reached from the peer,Bondingthe driver extracts its hardware address and initiates aArpanswer toBondone of theSlave. UseArpone problem with negotiating load balancing is that each broadcastArpThe request will be usedBondhardware address, so after learning this hardware address, the incoming traffic will all flow to the currentSlave. This problem can be done by sending updates to all the peers (ArpAnswer ), which contains their unique hardware address, causing the traffic to be re-distributed. When the newSlaveadded toBond, or an inactiveSlaveRewhen activated, incoming traffic is also re-distributed. The received load is distributed in sequence (Roundrobin) inBondin the highest-speedSlaveonwhen a link is re-connected, or a newSlaveadded toBond, the received traffic is in all currently activeSlaveis reassigned by using the specifiedMacaddress to eachClientinitiatingArpanswer. The following describesUpdelayparameter must be set to a value greater than or equal toSwitchSwitch)forwards the value of the delay so that it is destined for the peer-to-peerArpAnswerwill not beSwitchSwitch)interdiction.
Necessary:
condition 1:ethtool supports obtaining the rate of each slave;
conditions2: The underlying driver supports setting the hardware address of a device so that there is always aSlave (Curr_active_slave)UseBondhardware addresses, while ensuring that eachBondin theSlavehave a unique hardware address. IfCurr_active_slavethe hardware address will be newly selected .Curr_active_slavetakeover actuallyMod=6with theMod=0The difference:Mod=6, first putEth0The traffic fills up, then accounts forEth1,. ... EthX; andMod=0, you will find2the flow of each port is very stable, basically the same bandwidth. andMod=6, you will find that the first port has a high flow rate,2only a fraction of the traffic.
Linux NIC Binding technology