In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the ways to bind multiple network cards in Linux system". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the ways to bind multiple network cards in the Linux system?"
There are seven types of mode bound to Nic (066) bond0, bond1, bond2, bond3, bond4, bond5, bond6
There are three commonly used ones.
Mode=0: load balancing mode, with automatic backup, but requires "Switch" support and setting.
Mode=1: automatic backup mode. If one line is disconnected, the other lines will be backed up automatically.
Mode=6: load balancing mode, automatic backup, no need for "Switch" support and setting.
It should be noted that if you want to achieve mode 0 load balancing, it is not enough to set options bond0 miimon=100 mode=0 here. The switch connected to the network card must be specially configured (the two ports should be aggregated), because the two network cards for bonding use the same MAC address. Analyze the principle (bond runs under mode 0):
The IP of the network card bound to bond under mode 0 is modified to the same mac address. If these network cards are all connected to the same switch, there will be multiple ports corresponding to the mac address in the arp table of the switch. Which port should the switch forward packets destined for this mac address? Normally, mac addresses are unique in the world, and a single mac address corresponds to multiple ports must confuse the switch. Therefore, if the bond under mode0 is connected to the switch, the ports of the switch should be aggregated (cisco is called ethernetchannel,foundry and portgroup), because after the switch has done aggregation, several ports under the aggregation are also bundled into a mac address. Our solution is that two network cards can be connected to different switches.
There is no need to configure the switch in mode6 mode because the two network cards for bonding use different MAC addresses.
Seven bond modes describe:
The first mode: mod=0, that is: (balance-rr) Round-robin policy (balanced cycle strategy)
Features: the order of transmitting data packets is to transmit in turn (that is, the first packet goes eth0, the next packet goes eth2. . This mode provides load balancing and fault tolerance until the last transmission is completed), but we know that if the packets of a connection or session are sent from different interfaces and pass through different links halfway, the problem of packet disorderly arrival is likely to occur on the client, and disorderly packets need to be re-required to be sent, so that the throughput of the network will decline.
The second mode: mod=1, namely: (active-backup) Active-backup policy (master-backup strategy)
Features: only one device is active, when one goes down and the other is immediately switched to the primary device by backup. The mac address is externally visible, and from the outside, the MAC address of the bond is unique to avoid confusion in the switch (switch). This mode only provides fault tolerance; thus it can be seen that the advantage of this algorithm is that it can provide high availability of network connections, but its resource utilization is low, only one interface is working, and when there are N network interfaces, the resource utilization rate is 1max N
The third mode: mod=2, namely: (balance-xor) XOR policy (balancing strategy)
Features: data packets are transmitted based on the specified transmission HASH policy. The default policy is: (source MAC address XOR destination MAC address)% number of slave. Other transport policies can be specified through the xmit_hash_policy option, which provides load balancing and fault tolerance
The fourth mode: mod=3, namely: broadcast (broadcast strategy)
Features: transmitting each packet on each slave interface, this mode provides fault tolerance
The fifth mode: mod=4, namely: (802.3ad) IEEE 802.3ad Dynamic link aggregation (IEEE 802.3ad dynamic link aggregation)
Features: create an aggregation group that shares the same speed and duplex settings. Multiple slave work under the same active polymer according to the 802.3ad specification.
The slave election for outbound traffic is based on the transport hash policy, which can be changed from the default XOR policy to other policies through the xmit_hash_policy option. It should be noted that not all transmission strategies are 802.3ad adaptive, especially considering the packet disorder mentioned in section 43.2.4 of 802.3ad standard. Different implementations may have different adaptations.
Necessary conditions:
Conditional 1:ethtool supports getting the rate and duplex settings for each slave
Conditional 2:switch (switch) supports IEEE 802.3ad Dynamic link aggregation
Condition 3: most switch (switches) require specific configuration to support 802.3ad mode
The sixth mode: mod=5, namely: (balance-tlb) Adaptive transmit load balancing (Adapter Transport load balancing)
Features: do not need any special switch (switch) support channel bonding. Outbound traffic is allocated on each slave based on the current load (based on speed). If the slave that is receiving data fails, another slave takes over the MAC address of the failed slave.
A necessary condition for this mode: ethtool supports getting the rate of each slave
The seventh mode: mod=6, namely: (balance-alb) Adaptive load balancing (Adapter Adaptive load balancing)
Features: this mode includes balance-tlb mode, plus receiving load balancing (receive load balance, rlb) for IPV4 traffic, and does not require any switch (switch) support. Receiving load balancing is implemented through ARP negotiation. The bonding driver intercepts the ARP reply sent by the local machine and rewrites the source hardware address to the unique hardware address of a slave in the bond, so that different peers use different hardware addresses to communicate.
Received traffic from the server side is also balanced. When the local ARP request is sent, the bonding driver copies and saves the IP information of the peer from the ARP package. When the ARP reply arrives from the peer, the bonding driver extracts its hardware address and initiates an ARP reply to a slave in the bond. One of the problems with using ARP negotiation for load balancing is that every time an ARP request is broadcast, the hardware address of bond is used, so after the peer learns this hardware address, all received traffic will flow to the current slave. This problem can be solved by sending updates (ARP replies) to all peers, which contain their unique hardware addresses, causing traffic to be redistributed. Received traffic is also redistributed when a new slave is added to the bond, or when an inactive slave is reactivated. The received load is sequentially distributed (round robin) on the fastest slave in the bond
When a link is reconnected, or a new slave is added to the bond, received traffic is redistributed across all currently active slave, and an ARP reply is initiated for each client using the specified MAC address. The updelay parameter described below must be set to a value greater than or equal to the switch (switch) forwarding delay to ensure that ARP replies sent to the peer will not be blocked by switch (switch).
Necessary conditions:
Conditional 1:ethtool supports getting 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 the slave in each bond has a unique hardware address. If curr_active_slave fails, its hardware address will be taken over by the newly selected curr_active_slave
In fact, the difference between mod=6 and mod=0: mod=6, first full of eth0 traffic, and then occupy eth2, … EthX; and mod=0, you will find that the traffic of both ports is very stable, basically the same bandwidth. On the other hand, mod=6 will find that the first port has a high traffic flow, and the second port accounts for only a small part of the traffic.
Linux network port binding
Through the network port binding (bond) technology, it is easy to achieve network port redundancy and load balancing, so as to achieve the goal of high availability and high reliability. Premise agreement:
The two physical network ports are: eth0,eth2
The bound virtual port is: bond0
The server IP is: 192.168.0.100
First, configure the configuration file:
The code is as follows:
/ etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.0.100
NETMASK=255.255.255.0
NETWORK=192.168.0.0
BROADCAST=192.168.0.255
# BROADCAST broadcast address
/ etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
/ etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
The second step is to modify the modprobe related settings file and load the bonding module:
1. Here, we directly create a dedicated settings file / etc/modprobe.d/bonding.conf that loads bonding
The code is as follows:
[root@test ~] # vi / etc/modprobe.d/bonding.conf
# append
Alias bond0 bonding
Options bonding mode=0 miimon=200
two。 Load module (you don't have to load it manually after restarting the system)
The code is as follows:
[root@test ~] # modprobe bonding
3. Verify that the module is loaded successfully:
The code is as follows:
[root@test ~] # lsmod | grep bonding
Bonding 100065 0
Step 3, restart the network, and then confirm the situation.
The code is as follows:
[root@test ~] # / etc/init.d/network restart
[root@test ~] # cat / proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.5.0 (November 4, 2008)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
……
[root@test ~] # ifconfig | grep HWaddr
Bond0 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74
Eth0 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74
Eth2 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74
From the confirmation message above, we can see three important messages:
1. The current bonding mode is active-backup
two。 Now the network port of Active status is eth0.
3. The physical address of bond0 eth0 is the same as that of eth0 in the state of bond0.This is to avoid confusion on the upper switch.
Unplug a network cable at will, and then access your server to see if the network is still open.
Step 4: the system starts automatic binding and adds a default gateway:
The code is as follows:
[root@test ~] # vi / etc/rc.d/rc.local
# append
Ifenslave bond0 eth0 eth2
Route add default gw 192.168.0.1
If you can access the Internet, there is no need to add routing, 0.1 address is modified according to the environment.
Note: the previous two network ports are only bound into a bond0. If we want to set multiple bond ports, such as physical network ports eth0 and eth2 to form bond0,eth3 and eth4 to form bond1
Then the setting method of the network port setting file is the same as that described in step 1 above, except that the setting of / etc/modprobe.d/bonding.conf cannot be simply superimposed as follows:
The code is as follows:
Alias bond0 bonding
Options bonding mode=1 miimon=200
Alias bond1 bonding
Options bonding mode=1 miimon=200
There are two ways to set up correctly:
First, as you can see, in this way, the mode of multiple bond ports can only be set to the same:
The code is as follows:
Alias bond0 bonding
Alias bond1 bonding
Options bonding max_bonds=2 miimon=200 mode=1
Second, in this way, the mode of different bond ports can be set to different:
The code is as follows:
Alias bond0 bonding
Options bond0 miimon=100 mode=1
Install bond1 / sbin/modprobe bonding-o bond1 miimon=200 mode=0
Take a closer look at the above two setting methods, now if you want to set 3, 4, or even more bond ports, you should also know it!
Postscript: briefly introduce the meaning of some parameters in options when loading the bonding module above:
Miimon monitors the frequency of network links in milliseconds, which we set to 200ms.
Number of bond ports configured by max_bonds
There are mainly the following mode bond modes. In general practical applications, 0 and 1 are used more often.
At this point, I believe you have a deeper understanding of "what are the ways to bind multiple network cards in the Linux system?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.