Bind dual NICs in Linux to achieve load balancing and Failure Protection bond

Source: Internet
Author: User
For bonding network load balancing, we often use it on the file server. For example, we use three NICs as one to solve the problem of an IP address, heavy traffic, and heavy network pressure on the server. For file servers, such as NFS or Samba file servers, no administrator can solve the network load problem by creating multiple IP addresses of file servers on the Intranet. In the Intranet, most file servers use the same IP address for ease of management and application. For a m local network, when multiple users use the file server at the same time, the network pressure is extremely high, especially samaba and NFS servers. In order to solve the same IP address and break through traffic restrictions, after all, the network cable and network adapter have limits on data throughput. The best way to achieve network load balancing with limited resources is bonding; the other is that one of the server's network adapters fails or the network connection is accidentally disconnected, if bonding is enabled, you can switch to the network connection of another Nic. ensure that the service is not interrupted. for details, refer to: Workshop. (supported in most releases) # modinfo bondingfilename:/lib/modules/2.6.18-8. EL5/kernel/Drivers/NET/Bonding/bonding. ko
Author: Thomas Davis, tadavis@lbl.gov and other others
Description: Ethernet channel bonding driver, v3.0.3
Version: 3.0.3
License: GPL
Srcversion: 2547d22885c2fdf28ef7d98. if no, it indicates that the kernel does not support bonding. You do not need to recompile the kernel to compile the kernel. In make menuconfig, find the bonding driver support dialog box and select it. for module compilation, you also need to mount the module. how to mount the bonding module;

[Root @ localhost #] modprobe bonding if/sbin/ifenslave does not exist, we also need to compile it separately.
[Root @ Lin:/home/beinan #] cd/usr/src/linux-2.6.20/documentation/networking
[Root @ Lin:/home/networking #] gcc-wall-wstrict-prototypes-o-I/usr/src/linux-2.6.20/include ifenslave. c-o ifenslave [root @ Lin:/home/networking #] CP ifenslave/sbin/ifenslave1. edit the virtual network interface configuration file, if the specified Nic IP address does not have this file, we can copy one from the previous configuration file to reduce the input text.
# Cd/etc/sysconfig/network-scripts/# cp ifcfg-eth0 # vi ifcfg-bond0
Change the first line to device = bond0
# Cat ifcfg-bond0
Device = bond0
Bootproto = static
Ipaddr = 192.168.1.200netmask = 255.255.255.0
Broadcast = 192.168.1.255
Onboot = Yes
Type = Ethernet next, modify the settings of the previous Nic
[Root @ rhas-13 network-Scripts] # Cat ifcfg-eth0
Device = eth0
Onboot = Yes
Bootproto = none
[Root @ rhas-13 network-Scripts] # Cat ifcfg-eth1
Device = eth0
Onboot = Yes
Bootproto = NONE // Nic startup protocol. here I tested static, DHCP, none and found no difference 3 # vi/etc/moprobe. conf (the old version may be modules. conf)
Edit the/etc/moprobe. conf file and add the following line to enable the system to load the bonding module at startup. The external virtual network interface device is bond0.
 
Add the following lines
Alias bond0 Bonding
Options bond0 miimon = 100 mode = 1 alias net-pf-10 off // This line is off IPv6 support or not) Description: miimon is used for link monitoring. For example: miimon = 100, The system monitors the link connection status every Ms. If one line fails, it is transferred to another line. The value of mode indicates the working mode, which has a total, two or three modes, commonly used: 0, 1.
Mode = 0 indicates that the load balancing (round-robin) method is load balancing, and both NICs work.
Mode = 1 indicates that fault-tolerance (Active-Backup) provides redundancy, working in the active/standby mode. That is to say, by default, only one network card works and the other is used for backup.
Bonding can only provide link monitoring, that is, whether the link from the host to the switch is connected. If the external link of the switch is down and the switch is not faulty, bonding considers that the link is correct and continues to be used.
4 # vi/etc/rc. d/rc. Local
Join
After the ifenslave bond0 eth0 eth1 is restarted, use ifconfig to view the NIC information. You can see an extra bond0 Nic. bond0 link encap: Ethernet hwaddr 00: 0C: 29: C2: B3: 44
Inet ADDR: 192.168.1.200 bcast: 192.168.1.255 mask: 255.255.255.0
Up broadcast running master multicast MTU: 1500 Metric: 1
RX packets: 48 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 38 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX Bytes: 8817 (8.6 kib) TX Bytes: 4807 (4.6 kib) eth0 link encap: Ethernet hwaddr 00: 0C: 29: C2: B3: 44
Up broadcast running slave multicast MTU: 1500 Metric: 1
RX packets: 44 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 46 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX Bytes: 8196 (8.0 kib) TX Bytes: 6007 (5.8 kib)
Interrupt: 169 base address: 0x2000eth1 link encap: Ethernet hwaddr 00: 0C: 29: C2: B3: 44
Up broadcast running slave multicast MTU: 1500 Metric: 1
RX packets: 8 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 0 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX Bytes: 861 (861.0 B) TX Bytes: 0 (0.0 B)
Interrupt: 193 base address: 0x2080lo link encap: local loopback
Inet ADDR: 127.0.0.1 mask: 255.0.0.0
Up loopback running MTU: 16436 Metric: 1
RX packets: 12 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 12 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX Bytes: 960 (960.0 B) TX Bytes: 960 (960.0 B) that is to say, in Master/Slave Mode, when a network interface fails (for example, a master switch loses power ), if the network is not interrupted, the system will follow cat/etc/rc. d/RC. in local, the specified Nic works in sequence, and the machine can still provide external services, enabling the failure protection function. you can view the working status of bond0.
[Root @ localhost ~] # Cat/proc/NET/Bonding/bond0
Ethernet channel bonding DRIVER: v3.0.3 (March 23,200 6) 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
Link failure count: 0
Permanent hw addr: 00: 0C: 29: C2: B3: 44 slave interface: eth1
MII status: Up
Link failure count: 0
Permanent hw addr: 00: 0C: 29: C2: B3: 4E is an implementation method. the company's database server adopts another configuration method, the main difference in the NIC configuration file: VI ifcfg-eth0DEVICE = eth0
# Userctl = No
Bootproto = none
Onboot = Yes
Master = bond0
Slave = Yes
The ifcfg-eth1 also adds two lines in red,/etc/rc. ifenslave bond0 eth0 eth1 in local can be omitted. test the effect on a virtual machine. ping the IP address we just set from another machine, and then under the Virtual Machine VMWare, click one of the network cards to select disconnect (disconnect) we can see that ping only returns to normal after two times out. it indicates that our configuration has taken effect. it should be noted that if you want to achieve load balancing, it is not enough to set options bond0 miimon = 100 mode = 0 here. You also need to set the port of the switch. from the principle analysis (bond runs in Mode 0 ):
In Mode 0, the IP addresses of the NICS bound to bond are changed to the same MAC address. If these NICs are all connected to the same vswitch, in the ARP table of the switch, there are multiple ports corresponding to this MAC address. Which port should the switch forward packets sent to this MAC address? Under normal circumstances, the MAC address is globally unique. A single MAC address corresponds to multiple ports, which may confuse the switch.
Therefore, if the bond under mode0 is connected to the vswitch, the ports of the vswitch should adopt the aggregation mode (Cisco is called ethernetchannel and foundry is called portgroup), because after the vswitch is aggregated, several ports under the aggregation are also bundled into a MAC address. Because there is no layer-3 switch in the house, the test here is left to the user to verify it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.