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 do a special configuration (these two 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 0 under Bond the IP of the NIC is changed to the same MAC address, if these network cards are connected to the same switch, then the switch ARP table this MAC address corresponds to a number of ports, then the switch to the MAC address to accept the packet to which port to forward it? Normally the MAC address is the only one in the world, and a MAC address that corresponds to multiple ports definitely confuses the switch. So mode0 bond If you connect to the switch, these ports of the switch should be aggregated (Cisco is called Ethernetchannel,foundry called PortGroup), since the switches are aggregated, Several ports under aggregation are also bundled into a MAC address. Our solution is to have two NICs connected to different switches.
There is no need to configure the switch in Mode6 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-robin policy (balanced Whirl cycle strategy)
Features: transmission packet sequence is transmitted sequentially (that is: the 1th packet to go eth0, the next package will go eth1 .... Loop 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, and then passes through a different link, there is a good chance that the packet will arrive out of order at the client, and the unordered arrival packet needs to be sent again, so the throughput of the network will drop
Second mode: mod=1, ie: (active-backup) active-backup policy (primary-backup strategy)
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) XOR policy (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, i.e.: (802.3AD) IEEE 802.3ad dynamic Link aggregation (IEEE802.3AD dynamically linked aggregation)
Feature: Create an aggregation group that shares the same rate and duplex settings. Multiple slave are working under the same active aggregate according to the 802.3AD specification. The slave election for outgoing traffic is based on the transfer hash policy, which can be changed from the default XOR policy to another policy through the xmit_hash_policy option. It is important to note that not all transmission strategies are 802.3AD adapted, especially considering the problem of packet chaos mentioned in the 802.3AD standard 43.2.4 section. Different implementations may have different adaptations.
Necessary:
Conditional 1:ethtool supports getting the rate and duplex settings for each slave
Condition 2:switch (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 switch (switch) support. 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 one of the slave in bond, allowing different peer-to-peer communication using different hardware addresses.
Receive traffic from the server side is also balanced. When the native sends an ARP request, the bonding driver copies and saves the IP information from the ARP packet to the peer. When the ARP response arrives from the peer, the bonding driver extracts its hardware address and initiates an ARP response to one of the slave in Bond. One problem with the use of ARP negotiation for load balancing is that the hardware address of the bond is used every time the ARP request is broadcast, so when the peer learns the hardware address, the incoming traffic will flow to the current slave. This problem can be resolved by sending updates (ARP responses) to all the peers, which contain their unique hardware address, which results in the redistribution of traffic. When a new slave is added to bond, or an inactive slave is reactivated, the incoming traffic is also re-distributed. The received load is distributed sequentially (Roundrobin) at the highest speed of bond slave a link is re-connected, or a new slave is added to bond, receiving traffic is redistributed in all currently active slave, by using the specified MAC address to each The client initiates an ARP reply. The Updelay parameter described below must be set to a value that is greater than or equal to the switch forwarding delay to ensure that the ARP response destined to the peer is not blocked by the switch.
Necessary:
The condition 1:ethtool supports obtaining the rate of each slave;
Condition 2: The underlying driver supports setting the hardware address of a device so that there is always a slave (curr_active_slave) using the hardware address of bond, while ensuring that slave in each bond has a unique hardware address. If the Curr_active_slave fault, its hardware address will be newly elected to the Curr_active_slave takeover actually mod=6 and mod=0 difference: mod=6, first eth0 traffic occupied, and then accounted for ETH1,....ETHX; mod= 0, you will find 2 ports of traffic are very stable, the same bandwidth. And Mod=6, will find the first port flow is very high, the 2nd port only accounted for a small portion of traffic
Linux Network Port bindings:
Through the network port binding (bond) technology, can easily realize the network port redundancy, load balancing, so as to achieve high availability and high reliability. Prerequisite Agreement:
2 Physical network ports are: eth0,eth1
The virtual port after binding is: Bond0
The server IP is: 10.10.10.1
The first step is to configure the settings file:
- [Email protected] ~]# vi/etc/sysconfig/network-scripts/ifcfg-bond0
- Device=bond0
- Bootproto=none
- Onboot=yes
- ipaddr=10.10.10.1
- netmask=255.255.255.0
- network=192.168.0.0
- [Email protected] ~]# Vi/etc/sysconfig/network-scripts/ifcfg-eth0
- Device=eth0
- Bootproto=none
- Master=bond0
- Slave=yes
- [Email protected] ~]# vi/etc/sysconfig/network-scripts/ifcfg-eth1
- Device=eth1
- Bootproto=none
- Master=bond0
- Slave=yes
The second step, modify the Modprobe related settings file, and load bonding module:
- 1. Here, we create a dedicated setup file that loads bonding/etc/modprobe.d/bonding.conf
- [Email protected] ~]# vi/etc/modprobe.d/bonding.conf
- Alias Bond0 Bonding
- Options Bonding Mode=0 miimon=200
- 2. Load the module (reboot the system without manually reloading)
- [Email protected] ~]# modprobe bonding
- 3. Confirm that the module is loaded successfully:
- [Email protected] ~]# Lsmod | grep bonding
- Bonding 100065 0
The third step, restart the network, and then confirm the situation:
- [Email protected] ~]# service network restart
- Shutting down interface bond0: [OK]
- Shutting down loopback interface: [OK]
- Bringing up loopback interface: [OK]
- Bringing Up interface bond0: [OK]
- [Email protected] ~]# cat/proc/net/bonding/bond0
- Ethernet Channel Bonding driver:v3.4.0-1 (October 7, 2008)
- Bonding mode:fault-tolerance (Active-backup)
- Primary Slave:none
- Currently Active Slave:eth0
- MII Status:up
- MII Polling Interval (ms): 100
- Up Delay (ms): 0
- Down Delay (ms): 0
- Slave Interface:eth0
- MII Status:up
- speed:1000 Mbps
- Duplex:full
- Link Failure count:0
- Permanent HW ADDR:40:F2:E9:DB:C9:C2
- Slave interface:eth1
- MII Status:up
- speed:1000 Mbps
- Duplex:full
- Link Failure count:0
- Permanent HW ADDR:40:F2:E9:DB:C9:C3
- [Email protected] ~]# Ifconfig | grep HWaddr
- Bond0 Link encap:ethernet HWaddr 40:f2:e9:db:c9:c2
- Eth0 Link encap:ethernet HWaddr 40:f2:e9:db:c9:c2
- eth1 Link encap:ethernet HWaddr 40:f2:e9:db:c9:c2
From the confirmation information above, we can see 3 important information:
1. Now the bonding mode is Active-backup
2. Now the active state of the network port is eth0
The physical address of the 3.bond0,eth1 is the same as the physical address of the eth0 in the active state, in order to avoid confusion on the upper switch.
Unplug a network cable and then visit your server to see if the Internet is still on.
In the fourth step, the system starts auto-binding and adds the default gateway:
- [Email protected] ~]# vi/etc/rc.d/rc.local
- #追加
- Ifenslave bond0 eth0 eth1
- Route add default GW 10.10.10.1
#如可上网就不用增加路由, 0.1 addresses are modified by environment.
------------------------------------------------------------------------
Note: The front is just 2 network ports bound into a bond0 case, if we want to set up a plurality of bond ports, such as physical network port eth0 and eth1 composition bond0,eth2 and eth3 composition Bond1,
Multiple Network port bindings:
Then the setting of the network settings file method and the 1th step above the same method, but the/etc/modprobe.d/bonding.conf settings can not be as simple as the following overlay:
Alias Bond0 Bonding
Options Bonding mode=1 miimon=200
Alias Bond1 Bonding
Options Bonding mode=1 miimon=200
There are 2 ways to set up the correct method:
The first kind you can see, in this way, multiple bond The mode of the mouth can only be set to the same:
- <span style= "color: #000000;" >alias bond0 Bonding
- Alias Bond1 Bonding
- Options bonding max_bonds=2 miimon=200 mode=1
- </span>
Second, in this way, the mode of the different bond openings can be set differently:
- <span style= "color: #000000;" >alias bond0 Bonding
- Options Bond0 miimon=100 mode=1
- Install Bond1/sbin/modprobe bonding-o bond1 miimon=200 mode=0
- </span>
Take a closer look at the above 2 Setup methods, now if you want to set 3, 4, or even more bond port, you should also have it!
Postscript:
Simply introduce the meanings of some of the parameters in the options when loading the bonding module:
Miimon monitors the frequency of network links in milliseconds, which we set to 200 milliseconds.
Max_bonds number of bond ports configured
Mode bond model, mainly the following several, in the general practical application, 0 and 1 used more.
Linux bond seven types of NIC binding mode