- CentOS 6 Linux Server Cookbook
- Jonathan Hobson
- 1304字
- 2021-07-27 18:01:36
Bonding two Ethernet devices to increase bandwidth and provide redundancy
In this recipe we will learn how to combine the features of multiple network interfaces as a single device in an arrangement known as channel bonding with the intention of improving the overall performance of your server.
If your server has more than one Ethernet device, the process of channel bonding allows you to bind these interfaces together into a single channel in order to increase bandwidth and provide redundancy. It may sound complicated and finding the best settings will require some experimentation on your behalf or the support of specific network-based hardware, but it is the purpose of this recipe to provide a suitable starting point that enables you to take control and discover a network configuration that suits you best.
Getting ready
To complete this recipe, you will require a working installation of the CentOS 6 operating system with root privileges, a console-based text editor of your choice, and a connection to the Internet in order to facilitate the download of additional packages. In addition to this, it is assumed that one or more Ethernet devices are currently configured to use a static IP address, and that you have created a backup of your existing configuration files.
How to do it...
Before we begin this recipe, we will be required to download a series of packages that will enable us to complete the process of making a bond and testing our configuration.
- To do this, log in as root and download the following packages:
yum –y install bind-utils ethtool
- Having installed the necessary packages, we shall begin by creating a new file called
bond0
that will become the bonding master. To do this, return to your console and type:vi /etc/sysconfig/network-scripts/ifcfg-bond0
- Now add the following lines by substituting the relevant values marked as
XXX.XXX.XXX.XXX
with something more appropriate to the needs of your server:DEVICE="bond0" NAME="System bond0" NM_CONTROLLED="no" USERCTL=no ONBOOT=yes TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes PEERDNS=no PEERROUTES=yes IPV4_FAILURE_FATAL=yes IPV6INIT=no IPADDR=XXX.XXX.XXX.XXX NETMASK=XXX.XXX.XXX.XXX BROADCAST=XXX.XXX.XXX.XXX
- When ready, save and close the file before proceeding to modify your existing Ethernet configuration files:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
- Again, make the relevant changes but as a point of reference, here is an example of a single NIC:
DEVICE="eth0" NM_CONTROLLED="no" ONBOOT=yes HWADDR=XX:XX:XX:XX:XX:XX UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX TYPE=Ethernet BOOTPROTO=none NAME="System eth0" USERCTL=no MASTER=bond0 SLAVE=yes
- Now repeat this step for each Ethernet device by substituting the appropriate values before continuing to the next step.
- When the process of Ethernet device configuration is complete, the next step is to create the bonding module configuration file by typing the following command:
vi /etc/modprobe.d/bonding.conf
- Now add the following lines:
alias bond0 bonding options bond0 mode=5 miimon=100
- Save and close the file before proceeding to register the bonding module with CentOS as a device. To do this, type:
modprobe bonding
- And finally, to complete our configuration you should reboot or type:
service network restart
- Well done. The process of channel bonding is now complete and you can test your new network settings by running the following command:
ifconfig
How it works...
In this recipe you have been provided with a walkthrough of the necessary steps involved in implementing channel bonding. Channel bonding (also known as Ethernet bonding) is a computer networking arrangement in which two or more network interfaces on a host computer are combined in order to provide redundancy or increased throughput. Of course, to get the best out of this arrangement some additional experimentation with the bonding values will be required but overall, this introduction has served to show you that creating a channel bond may not be as complicated as it was originally thought.
So what have we learned from this experience?
Having started this recipe by installing the appropriate packages, we then proceeded to create the bonding master at /etc/sysconfig/network-scripts/ifcfg-bond0
, which would maintain the following range of settings:
DEVICE="bond0" NAME="System bond0" NM_CONTROLLED="no" USERCTL=no ONBOOT=yes TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes PEERDNS=no PEERROUTES=yes IPV4_FAILURE_FATAL=yes IPV6INIT=no IPADDR=XXX.XXX.XXX.XXX NETMASK=XXX.XXX.XXX.XXX BROADCAST=XXX.XXX.XXX.XXX
By doing this, we have created a new device. This device is known as the bonding master that will use our real Ethernet cards as slaves. If a slave device fails, this type of configuration will ensure that the other slave will take over thereby reducing the margin of error.
In the next step, we then made some changes to our existing Ethernet devices:
DEVICE="eth0" NM_CONTROLLED="no" ONBOOT=yes HWADDR=XX:XX:XX:XX:XX:XX UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX TYPE=Ethernet BOOTPROTO=none NAME="System eth0" USERCTL=no MASTER=bond0 SLAVE=yes
From your initial experience of building a static IP address, you will notice that the first eight lines of both configuration files show that nothing of significance has changed. We have removed what is now considered to be redundant information, but this is because much of the information we have removed is now contained in /etc/sysconfig/network-scripts/ifcfg-bond0
.
On the other hand, you will notice that the final three lines have not only declared that non-root users are not allowed to control the device, but they have agreed to confirm that the master is known as bond0
, while the Ethernet device is considered to be a slave.
For example, the configuration file for a second Ethernet device may look like this:
DEVICE="eth1" NM_CONTROLLED="no" ONBOOT=yes HWADDR=XX:XX:XX:XX:XX:XX UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX TYPE=Ethernet BOOTPROTO=none NAME="System eth1" USERCTL=no MASTER=bond0 SLAVE=yes
So having made some basic changes to the current Ethernet configuration files (now known as slaves), the recipe then required us to register the bonding module as a device. This was achieved by creating a new file called bonding.conf in/etc/modprobe.d
with the following preferences:
alias bond0 bonding options bond0 mode=5 miimon=100
The previous settings indicate the type of bond we are trying to build and this is something you may wish to experiment with at a later date.
In all, there are six modes thereby giving you plenty of scope to reconfigure this recipe for your own needs. However, for the purposes of simplicity, we have used mode=5
, a function that conforms to a process of adaptive transmit load balancing, a basic configuration path that does not require any specific type of network switch support.
The consequence of this modification is to allow the outgoing traffic to be distributed according to the current load on each slave (Ethernet) device and if one device fails the other device assumes responsibility for continuing with the task in hand.
To finalize this process we then proceeded to register the module and restart the network service.
Of course, there is always much more detail that could be provided but don't forget, any changes to the mode type or miimon
value found in /etc/modprobe.d/bonding.conf
is something that you can alter at your leisure if you want to improve the overall performance of your server.
There's more...
As a fallback it may be worth considering adding an additional setting to /etc/sysconfig/network-scripts/ifcfg-bond0
that will serve to provide balance to the system. Channel bonding can be used in such a way that multiple devices can carry different configurations, but before you begin experimenting it is suggested that we finalize the main recipe by enabling both Ethernet cards to carry the same options until you have the time to test your configuration and improve it.
Note
Remember, there are six modes in total and although some of these modes will require specific hardware support, the aim of this recipe is to provide a starting point from which you can begin testing your server's performance by changing both the mode type or miimon
settings to suit your environment.
To begin, open ifcfg-bond0
in your favorite text editor like so:
vi/etc/sysconfig/network-scripts/ifcfg-bond0
Now add the following line at the bottom of the file:
BONDING_OPTS="miimon=100 mode=balance-tlb"
Alternatively, if you are currently using mode=6
, you can use the following settings:
BONDING_OPTS="miimon=100 mode=balance-alb"
When you have finished, run the following command to restart the network:
service network restart