1. What is bonding;
The Linux bonding driver binds multiple network interface devices to a single network interface setting for network load balancing and network redundancy. The Linux bonding Driver provides a method for aggregating multiple network interfaces into a single logical bonded interface. the behavior of the bonded interfaces depends upon the mode; generally speaking, modes provide either hot standby or load balancing services. additionally, link integrity monitoring may be completed MED.
2. Bonding application direction;
2.1 network load balancing;
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;
2.2 network Redundancy;
For servers, the stability of network devices is also important, especially the network card. In production systems, the reliability of NICS is even more important. In production systems, hardware redundancy is used to provide server reliability and security, such as power supply. Bonding can also provide support for Nic redundancy. Bind a network adapter to an IP address. When a network adapter is physically damaged, the other network adapter can also provide normal services.
3. network load balancing application instances;
3.1 system environment and implementation goals;
Operating System Environment: slackware 11.0, kernel 2.6.20
NIC: three;
Goal: bind the three NICs eth0, eth1, and eth2 to one for network load balancing. Google can find many bonding documents, but most of them are from foreign languages. There is also an article in China, which seems to be an application in the RedHat/Fedora environment, that is to say, for the System V-style init script STARTUP script. For the BSD-style Linux operating system that starts the service script, there are not many ready-made documents on the Internet. Debian, fedora, RedHat, and Ubuntu are all in the System V style. Slackware is BSD-like. In addition to the official slackware documentation, the usage of bonding is not mentioned on the Internet. I have made a lot of detours. The main reason is that I still don't understand slackware. Although slackware is easy to use, it won't solve the problem if I don't read the document. It seems that the official document is very important to me. What if you cannot solve it? Is it the same as I did not read doc? If I am the same as me, I still like me, read the official Doc honestly. As long as it is an application problem, most of it can be solved.
3.2 solution to the System V style Linux system;
Debian, fedora, RedHat, and Ubuntu are all System V-style systems. For details, refer to bonding.
3.3 Use bonding in slackware to achieve network load balancing;
This article focuses on solving network load balancing, not through bonding to achieve network device redundancy;
3.31 determine the kernel version; [root @ linuxsir:/home/beinan #] uname-
Linux linuxsir 2.6.20 #7 SMP sun may 6 00:20:14 CST 2007 x86_64 x86_64 x86_64 GNU/Linux
The basic kernel version is used to install your kernel source package, which is generally provided in the release version. After installation, it is usually placed in the/usr/src directory. If you compile it yourself, you should know where your source code package is put; for example, I put the source code package in/usr/src/linux-2.6.20.
3.32 compile bonding;
Bonding can be used only after compilation. Whether the Linux kernel is supported by default can be viewed through modinfo bonding;
[Root @ linuxsir:/home/beinan #]/sbin/modinfo
If no detailed information is output, it may not be supported. You should compile your own; Compile bonding driver support in the module mode; Compile the kernel method, see how to mount the bonding module;
[Root @ linuxsir:/home/beinan #] modprobe Bonding
3.33 compiling ifenslave;
In the newer Linux kernel, ifenslave is not supported by the kernel by default and needs to be compiled by ourselves. We need to enter a similar position in the kernel source code package;
[Root @ linuxsir:/home/beinan #] cd/usr/src/linux-2.6.20/documentation/networking
[Root @ linuxsir:/home/networking #] gcc-wall-wstrict-prototypes-o-I/usr/src/linux-2.6.20/include ifenslave. C-o ifenslave
[Root @ linuxsir:/home/networking #] CP ifenslave/sbin/ifenslave
3.34 modify Network-related configuration files;
In slackware, we first need to modify the/etc/rc. d/rc. Inet file; find the following line;
./Etc/rc. d/rc. inet1.conf
Add the following section;
# Bonding Conf
/Sbin/ifenslave bond0 eth0
/Sbin/ifenslave bond0 eth1
/Sbin/ifenslave bond0 eth2
The purpose is to bind multiple NICs to the bond0 device, modify/etc/rc. d/rc. inet1.conf, and set eth0, eth1 ...... If the NIC settings are disabled, no value is set. For example, if the eth0 settings do not allow it to take effect, it should be
Ipaddr [0] = ""
Netmask [0] = ""
Use_dhcp [0] = ""
Dhcp_hostname [0] = "" Gateway = "192.168.1.1"
# Note: the IP address of the gateway and the LAN are all sent out through 192.168.1.1. You can set the IP address as needed;
Ifname [4] = "bond0" # Note: bond0 Network Device
Hwaddr [4] = "00: 13: 72: 25: F3: 6C" # Note: the physical address of the eth0 Nic;
Ipaddr [4] = "" # Note: if you use a specified IP address, you can set it to the IP address you specified;
Netmask [4] = "" # Note: The bond0 mask, for example, 255.255.255.0, is set based on your own situation;
Use_dhcp [4] = "yes" # Note: whether to use DHCP. I use DHCP, so I will set it to yes;
Dhcp_hostname [4] = "192.168.1.1"
# Note: the DHCP server host name, such as dns.linuxsir.org, can also be used. Of course, you have to create a DHCP server. If not, you can use an IP address.
The purpose of this operation is to allow the bond0 device to automatically pass the DHCP server address. If the address is specified, it is the same; Modify/etc/rc. d/rc. modules and add;
/Sbin/modprobe Bonding
Alias bond0 Bonding
Options bonding mode = 0 miimon = 100
The purpose of this operation is to automatically mount the bonding module after it is started;
3.35 try to bind multiple NICs to a device bond0;
First, we need to disable all NICs;
[Root @ linuxsir:/home/beinan #] modprobe Bonding
Note: mount the bonding module;
[Root @ linuxsir:/home/beinan #]/sbin/ifconfig eth0 down
[Root @ linuxsir:/home/beinan #]/sbin/ifconfig eth0 down
[Root @ linuxsir:/home/beinan #]/sbin/ifconfig eth0 down
Then run the following command to bind the NIC to bond0;
[Root @ linuxsir:/home/beinan #]/sbin/ifenslave bond0 eth0
[Root @ linuxsir:/home/beinan #]/sbin/ifenslave bond0 eth1
[Root @ linuxsir:/home/beinan #]/sbin/ifenslave bond0 eth2
Is the binding successful? Is the physical address of the bond0 and eth0, eth1, and eth2 NICs the same ???
[Root @ linuxsir:/home/beinan #]/sbin/ifconfig
Bond0 link encap: Ethernet hwaddr 00: 23: 00: A5: B3: 3C
Inet ADDR: 192.168.1.171 bcast: 192.168.1.255 mask: 255.255.255.0
Inet6 ADDR: fe80: 213: 72ff: fe25: f36c/64 scope: Link
Up broadcast notrailers running master multicast MTU: 1500 Metric: 1
RX packets: 601775 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 421244 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX Bytes: 866655472 (826.5 MB) TX Bytes: 26175996 (24.9 MB)
Eth0 link encap: Ethernet hwaddr 00: 23: 00: A5: B3: 3C
Inet6 ADDR: fe80: 213: 72ff: fe25: f36c/64 scope: Link
Up broadcast running slave multicast MTU: 1500 Metric: 1
RX packets: 192677 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 138863 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX Bytes: 278360897 (265.4 MB) TX Bytes: 9486604 (9.0 MB)
Interrupt: 17
Eth1 link encap: Ethernet hwaddr 00: 23: 00: A5: B3: 3C
Inet6 ADDR: fe80: 213: 72ff: fe25: f36c/64 scope: Link
Up broadcast running slave multicast MTU: 1500 Metric: 1
RX packets: 206372 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 141191 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX Bytes: 296700989 (282.9 MB) TX Bytes: 8348311 (7.9 MB)
Interrupt: 18 base address: 0xae00
Eth2 link encap: Ethernet hwaddr 00: 23: 00: A5: B3: 3C
Inet6 ADDR: fe80: 213: 72ff: fe25: f36c/64 scope: Link
Up broadcast running slave multicast MTU: 1500 Metric: 1
RX packets: 202726 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 141190 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 1000
RX Bytes: 291593586 (278.0 MB) TX Bytes: 8341081 (7.9 MB)
Interrupt: 16 base address: 0xcf00
Lo link encap: local loopback
Inet ADDR: 127.0.0.1 mask: 255.0.0.0
Inet6 ADDR: 1/128 scope: Host
Up loopback running MTU: 16436 Metric: 1
RX packets: 4 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 4 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX Bytes: 200 (200.0 B) TX Bytes: 200 (200.0 B)