Bind a Centos dual-nic to achieve load balancing and Failover

Source: Internet
Author: User
Tags failover

I. Introduction

In Linux, dual Nic binding is implemented by virtualizing two NICs into one Nic. The device combined seems to be a separate Ethernet interface device, in general, two NICs have the same IP address, and parallel links are aggregated into a logical link. In fact, this technology already exists in Sun and Cisco, known as Trunking and Etherchannel technology. It is also used in Linux 2.4.x kernel, known as bonding.

The earliest application of bonding technology was on the cluster beowulf, designed to improve data transmission between cluster nodes. Next we will discuss the principles of bonding. What is bonding? It should start with the promisc mode of the NIC. We know that, under normal circumstances, the network adapter only receives the target hardware Address (MAC Address) as its own Mac Ethernet frame, and filters out all other data frames to reduce the burden on the driver. However, the NIC also supports another mode called hybrid promisc, which can receive all frames on the network. For example, tcpdump runs in this mode. Bonding also runs in this mode, and modifies the mac address in the driver, changing the Mac address of the two NICs to the same, can receive data frames of a specific mac. Then, the data frame is sent to the bond driver for processing.

It is impossible to directly set the same IP address for the two NICs. Kernels 2.4.12 and later versions are provided for the bonding module. Previous versions can be implemented through patch.

2. bonding configuration

1. Edit the virtual network interface configuration file and specify the nic ip Address

Assume that eth0 is the NIC for external services and has already debugged the network. eth1 is the NIC for external services at the same time as eth0.

[Root @ jw-masterdb ~] # Cd/etc/sysconfig/network-scripts/
[Root @ jw-masterdb network-scripts] # cp ifcfg-eht0 ifcfg-bond0

Modify the ifcfg-bon0 information as follows:

[Root @ jw-masterdb network-scripts] # vim ifcfg-bond0.

DEVICE = bond0
BOOTPROTO = none
IPADDR = 10.3.3.120
NETMASK = 255.255.255.0
ONBOOT = yes
TAPE = Ethernet
GATEWAY = 10.3.3.1
USERCTL = no

2. Configure the real Nic

Modify ifcfg-eth0 as follows:

[Root @ jw-masterdb network-scripts] # vim ifcfg-eth0.

DEVICE = eth0
BOOTPROTO = none
ONBOOT = yes
USERCTL = no
SLAVE = yes
MASTER = bond0

Modify ifcfg-eth1 as follows:

[Root @ jw-masterdb network-scripts] # vim ifcfg-eth1.

DEVICE = eth1
BOOTPROTO = none
ONBOOT = yes
USERCTL = no
MASTER = bond0
SLAVE = yes

 3. Load the module so that the system supports bonding

By default, the kernel supports bonding. You only need to modify the configuration file/etc/modprobe. conf;

Add two red lines:

[Root @ jw-masterdb network-scripts] # vim/etc/modprobe. conf

Alias eth0 bnx2
Alias eth1 bnx2
Alias scsi_hostadapter cciss
Alias scsi_hostadapter1 ata_piix
Alias bond0 bonding
Options bond0 miimon = 100 mode = 1

Note:

Mode specifies the bond0 working mode. Commonly Used 0 and 1 are used to indicate the load balancing mode, and 1 is the Master/Slave mode. You can configure it as needed. Commonly used are 0, 1. Mode = 0 indicates that the load balancing (round-robin) method is load balancing, and both network adapters work. Mode = 1 indicates that fault-tolerance (active-backup) provides redundancy, working in the active/standby mode. That is to say, only one network adapter 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. 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.

4. Add boot script

Add/etc/rc. d/rc. local

[Root @ jw-masterdb network-scripts] # vim/etc/rc. d/rc. local

/Sbin/modprobe bonding miimon = 100 mode = 1

Or ifenslave bond0 eht0 eth1

If both eth0 and eth1 write MASTER and SLAVE, the above steps do not matter.

5. Restart

Reboot or service network restart can see the results.

Vi. Test

Ping An address. Of course, the address can be pinged. If network connectivity is found, check the network settings for the ifcfg-bond0.

Then unplug a network cable. If the ping is not broken, it indicates that a backup line is unplugged. If it is not the main line, re-plug it for two minutes.

At this time, unplug the other network cable. Now we can see that the ping times out or is stuck there. Please wait for 10 ~ 30 seconds. ping continues.

The test is successful.

 

This article is from the "& Si Yuan Chen Xi" blog, please be sure to keep this source http://kling.blog.51cto.com/3320545/1182260

Related Article

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.