In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to achieve load balancing with dual Nic bindings in Linux. I believe most people don't know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it.
Linux dual network card binding to achieve load balancing, for your reference, the details are as follows
System environment: CentOS release 6.9 (Final) Linux centos6 2.6.32-696.10.1.el6.x86_64
Under the Ubuntu system, ifenslave is used to configure the network card, which is more or less the same.
Close NetworkManager
# service NetworkManager stop# chkconfig NetworkManager off
Create a bond0 interface profile
# cd / etc/sysconfig/network-script/# vim ifcfg-bond0DEVICE=bond0IPADDR=192.168.100.106PREFIX=24GATEWAY=192.168.100.1DNS1=202.103.24.68BOOTPROTO=staticONBOOT=yesUSERCTL=no
Modify the configuration of eth0 and eth2
# vim ifcfg-eth0 DEVICE=eth0BOOTPROTO=noneONBOOT=yesMASTER=bond0SLAVE=yesUSERCTL=no# vim ifcfg-eth2 DEVICE=eth2BOOTPROTO=noneONBOOT=yesMASTER=bond0SLAVE=yesUSERCTL=no
Load bonding module
# vim / etc/modprobe.d/bonding.conf # create a new bonding.conf file alias bond0 bondingoptions bond0 miimon=100 mode=6
Description:
Miimon is used for link monitoring. For example: miimon=100, in ms (milliseconds). The 100th here is 100ms, or 0.1s. The system monitors the link connection status once per 100ms, and if one line fails, it is transferred to another line. Mode refers to the mode of operation, there are a total of seven (0-6). These two parameters can be configured in the / etc/modprobe.d/bonding.conf file, namely options bond0 miimon=100 mode=6, or directly written in the configuration file of bond0, that is, BONDING_OPTS= "mode=6 miimon=100"
Restart network services
# service network restart
View bond0 interface status
[root@centos6 ~] # cat / proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27 2011) Bonding Mode: adaptive load balancingPrimary Slave: NoneCurrently Active Slave: eth0MII Status: upMII Polling Interval (ms): 100Up Delay (ms): 0Down Delay (ms): 0Slave Interface: eth0MII Status: upSpeed: 100MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 52:54:00:a9:4e:2cSlave queue ID: 0Slave Interface: eth2MII Status: upSpeed: 100MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 52:54:00:91:1b:68Slave queue ID: 0
If you have modified the bond configuration several times, you may need to restart the system before the bond0 interface status is updated.
View the sending and receiving status of the network interface
# watch-n 1 ifconfig-a
Introduction of seven working modes of bond
1. Mode=0 (balance-rr) (balanced cycle strategy)
Link load balancing, increase bandwidth, support fault tolerance, a link failure will automatically switch the normal link. The switch needs to be configured with an aggregation port, and Cisco is called port channel.
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. However, if the packets of a connection or session are sent from different interfaces and pass through different links halfway, there is likely to be the problem of packet disorderly arrival on the client, and disorderly packets need to be re-required to be sent, so that the throughput of the network will decline.
2. Mode=1 (active-backup) (master-backup policy)
This is the active / standby mode. Only one network card is active and the other is a standby standby. All traffic is processed on the active link. If the switch is configured with bundling, it will not work, because the switch sends packets to two network cards, and half of the packets are discarded.
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
3. Mode=2 (balance-xor) (balance strategy)
Indicates that the XOR Hash load is shared and cooperates with the aggregation of the switch in a non-negotiated manner. (xmit_hash_policy is required, switch is required to configure port channel)
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
4. Mode=3 (broadcast) (broadcast strategy)
Indicates that all packets are sent from all network interfaces, which is uneven, only redundant, but too wasteful of resources. This model applies to the financial industry because they need highly reliable networks and do not allow any problems. It needs to cooperate with the aggregation of the switch in a non-negotiated manner.
Features: transmitting each packet on each slave interface, this mode provides fault tolerance
5. Mode=4 (802.3ad) (IEEE 802.3ad dynamic link aggregation)
Indicates that it supports the 802.3ad protocol and cooperates with the aggregate LACP mode of the switch (requires xmit_hash_policy). The standard requires all devices to aggregate at the same rate and duplex mode, and, like other bonding load balancing modes except balance-rr mode, no connection can use the bandwidth of more than one interface.
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
6. Mode=5 (balance-tlb) (adapter transmission load balancing)
The slave is selected to send according to the load of each slave, and the current slave is used when receiving. This mode requires some ethtool support for the network device driver of the slave interface; and ARP monitoring is not available.
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.
Necessary condition: ethtool supports the rate of getting each slave
7. Mode=6 (balance-alb) (Adapter Adaptive load balancing)
Rlb (receiving load balancing receive load balance) is added to the tlb of 5. No switch (switch) support is required. Receiving load balancing is realized through ARP negotiation.
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 fill up 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. And mod=6, you will find that the first port traffic is very high, the second port only accounts for a small part of the traffic.
Mode5 and mode6 do not need to be set on the switch side, and the network card can be aggregated automatically. Mode4 needs to support 802.3ad. Mode0,mode2 and mode3 theoretically require static aggregation.
However, in the actual measurement, mode0 can receive unevenly through mac address spoofing when the switch is not set up.
These are all the contents of the article "how to bind dual network cards in Linux to achieve load balancing". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.