search
HomeOperation and MaintenanceCentOSHow to configure bond in CentOS

How to configure bond in CentOS

Jun 15, 2021 am 11:14 AM
centos

The following tutorial column of centos will introduce to you how to configure bond in CentOS. I hope it will be helpful to friends in need!

CentOS configuration bond

1. What is network card bonding and its simple principle

Network card bonding is also called "network card bundling", which is to use multiple physical network cards to become a virtual network card. A network card to provide load balancing or redundancy and increase bandwidth. When a network card breaks down, the business will not be affected. This aggregated device appears to be a single Ethernet interface device, that is, these network cards have the same IP address and the parallel links are aggregated into one logical link. This technology is called Trunking and Etherchannel technology in network companies such as Cisco. This technology is called bonding in the Linux 2.4.x kernel.

There are 7 modes of Bonding:

#defineBOND_MODE_ROUNDROBIN       0   (balance-rr模式)网卡的负载均衡模式
#defineBOND_MODE_ACTIVEBACKUP     1   (active-backup模式)网卡的容错模式
#defineBOND_MODE_XOR              2   (balance-xor模式)需要交换机支持
#defineBOND_MODE_BROADCAST        3    (broadcast模式)
#defineBOND_MODE_8023AD           4   (IEEE 802.3ad动态链路聚合模式)需要交换机支持
#defineBOND_MODE_TLB              5   自适应传输负载均衡模式
#defineBOND_MODE_ALB              6   网卡虚拟化方式

All working modes of the bonding module can be divided into two categories: multi-master working mode and active-standby working mode. balance-rr and broadcast belong to the multi-master working mode and active-backup belongs to the active-backup mode. Operating mode. (balance-xor, adaptive transmission load balancing mode (balance-tlb) and adaptive load balancing mode (balance-alb) also belong to the multi-master working mode, and IEEE 802.3ad dynamic link aggregation mode (802.3ad) belongs to the active and backup mode type working mode.

Details introduction to these 7 modes:

1. balance-rr (mode=0)

Round-robin strategy: from beginning to end Send data packets sequentially on each slave interface. This mode provides load balancing and fault tolerance capabilities.

2. active-backup (mode=1)

Active-backup (active-backup) ) Policy: In a bond, only one slave is activated. Other slaves will be activated if and only if the active slave interface fails. In order to avoid switch chaos, the bound MAC address is only visible on one external port at this time. In In bonding version 2.6.2 and later, when a failover occurs in active-standby mode, bonding will send one or more gratuitous ARPs to the newly activated slave. Bonding's main salve interface and configuration on the interface All VLAN interfaces will send gratuitous ARP, as long as at least one IP address is configured on these interfaces. Gratuitous ARP sent on the VLAN interface will be accompanied by the appropriate VLAN ID. This mode provides fault tolerance, the primary option, documented below will affect Behavior of this mode.

3. balance-xor (mode=2)

XOR strategy: Based on the selected transmission hash strategy.

This mode provides load balancing and Fault tolerance.

4. Broadcast (mode=3)

Broadcast strategy: transmit all packets on all slave interfaces. This mode provides fault tolerance.

5, 802.3ad (mode=4)

IEEE 802.3ad dynamic link aggregation. Create aggregation groups that share the same speed and duplex mode. All slaves can be used to establish aggregate links according to the 802.3ad specification. Salve's outbound selection depends on the hash policy of the transmission. The default policy is a simple XOR policy, and the hash policy can be changed through the xmit_hash_policy option. It should be noted that not all transmission strategies are compatible with 802.3ad, especially the packet mis-ordering requirements in Chapter 43.2.4 of the 802.3ad standard. Implementations of different individuals often have great incompatibilities.

prerequisites:
1. The basic driver of each slave supports Ehtool to obtain the rate and duplex status.
2. The switch supports IEEE 802.3ad dynamic link aggregation. Most switches require some configuration to enable 802.3ad mode.

6. balance-tlb (mode=5)

Adaptive transmission load balancing: Channel binding does not require special switch support. The distribution of egress traffic depends on the current load of each slave (calculating relative speed). Import traffic is received from the current slave. If there is an error in receiving the salve, other slaves will continue to receive the MAC address of the slave that failed to take over.
prerequisites:
The basic driver of each slave supports Ehtool to obtain the rate status.

7, balance-alb (mode=6)

Adaptive load balancing: including balance-tlb (mode 5) and receiving load balancing for IPV4 traffic , and no special switch support is required. Receive load balancing is achieved through ARP negotiation. The bonding driver intercepts ARP Replies (ARP response messages) sent by the local machine and rewrites the source address of the ARP message with the hardware address of a slave of the bond, so that the server uses different hardware addresses for different devices. The incoming traffic of connections established by this server is also load balanced. When the machine sends an ARP Request, the bonding driver copies and saves the node's IP information through the ARP message. When receiving an ARP Reply from another node, the bonding driver obtains the node's hardware address and responds with an ARP Reply containing the bound slave's hardware address to the sending node. One problem with load balancing using ARP negotiation is that every time the bond's hardware address is used to broadcast an ARP message, all the data sent by other nodes will be concentrated on one slave. When processing ARP updates to all other nodes, each node will Hardware addresses are relearned, resulting in traffic redistribution. When a new slave is added or an inactive slave is reactivated, the received traffic will also be redistributed. The receive traffic load is distributed serially (round-robin) on a set of slaves with the highest rate in the bond.
When a link is reconnected or a new slave is added, bond will reinitialize ARP Replies to all clients. The value of the updelay parameter must be equal to or greater than the forwarding delay of the switch to prevent ARP Replies from being blocked by the switch.
prerequisites:
1. The basic driver of each slave supports Ehtool to obtain the rate status.

2. The basic driver supports resetting the hardware address when the device is turned on. Each slave is also required to have a unique hardware address. If curr_active_slave fails, its hardware address is replaced by the newly selected curr_active_slave hardware address.

Configure Bond0 and Bond1 on CentOS:

First of all, you need to check whether linux supports bonding. RHEL4 already supports it by default. (Most distributions support it)

# modinfo bonding
  
 
  
filename:       /lib/modules/2.6.18-8.el5/kernel/drivers/net/bonding/bonding.ko
  
author:         Thomas Davis, 
    tadavis@lbl.gov
     and many others
  
de.ion:    Ethernet Channel Bonding Driver, v3.0.3
  
version:        3.0.3
  
license:        GPL
  
srcversion:     2547D22885C2FDF28EF7D98

如果有类似上面的信息输出,说明已经支持了.      

1、配置Bond 0 负载均衡   

特点:  

1. 双网块同时工作,实现负载均衡,某一网卡不正常时,不会引发网络中断.  

2. 恢复不能正常工作的网卡时,会引发网络中断几秒,然后双网卡同时工作.  

    1.编辑虚拟网络接口配置文件,指定网卡IP    

    cp /etc/sysconfig/network-scripts/ifcfg-lo ifcfg-bond0
  
vi  ifcfg-bond0
  
 
  
DEVICE=bond0
  
IPADDR=10.10.10.1
  
NETMASK=255.255.255.0
  
NETWORK=10.10.10.0
  
BROADCAST=10.10.10.255
  
ONBOOT=yes
  
BOOTPROTO=none
  
USERCTL=no
  
GATEWAY=192.168.0.1

    2.在bond0上添加网关,是确保默认路由无故障   

[root@Linux ~]# route
    
Kernel IP routing table
    
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    
10.0.0.0        *               255.255.255.0   U     0      0        0 bond0
    
10.0.0.0        *               255.255.255.0   U     0      0        0 eth0
    
10.0.0.0        *               255.255.255.0   U     0      0        0 eth1
    
169.254.0.0     *               255.255.0.0     U     0      0        0 bond0
    
default         10.0.0.1        0.0.0.0         UG    0      0        0 bond0
    
 
    
vi  ifcfg-eth0
    
 
    
DEVICE=eth0
    
BOOTPROTO=none
    
ONBOOT=yes
    
USERCTL=no
    
MASTER=bond0
    
SLAVE=yes
    
 
    
vi  ifcfg-eth1
      
 
      
DEVICE=eth1
      
BOOTPROTO=none
      
ONBOOT=yes
      
USERCTL=no
      
MASTER=bond0
      
SLAVE=yes

3 # vi /etc/modprobe.conf              

编辑/etc/modprobe.conf 文件,加入如下一行内容,以使系统在启动时加载bonding模块,对外虚拟网络接口设备为 bond0       

        加入下列两行        

alias bond0 bonding 
      
options bond0 miimon=100 mode=0

        说明:       

miimon是用来进行链路监测的。 比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;      

        mode的值表示工作模式,他共有0,1,2,3四种模式,常用的为0,1两种。       

   mode=0表示load balancing (round-robin)为负载均衡方式,两块网卡都工作。      

   mode=1表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份.                

4 # vi /etc/rc.d/rc.local       

          加入以下内容          

# 仅在热备模式下,eht0 eth1网卡的工作顺序.
        
 
        
ifenslave bond0 eth0 eth1

到这时已经配置完毕重新启动机器.        

重启会看见以下信息就表示配置成功了        

................         

Bringing up interface bond0 OK 
        
Bringing up interface eth0 OK 
        
Bringing up interface eth1 OK

2、配置Bond 1 热备模式         

特点:        

1. 正在工作的网卡不正常后,切换到备用网卡,此时会中间几秒钟        

2. 恢复不正常的网卡时,不会引发网络中断.      

          其他步骤一致,只在第3步骤,将mode设置成1即可.         

alias bond0 bonding 
        
options bond0 miimon=100 mode=1

The above is the detailed content of How to configure bond in CentOS. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete
CentOS's Purpose: Building Robust and Reliable ServersCentOS's Purpose: Building Robust and Reliable ServersMay 11, 2025 am 12:18 AM

CentOS is suitable for building powerful and reliable servers. Its advantages include: 1. Stability and reliability, support cycle up to 10 years; 2. Security, built-in SELinux and regular security patches; 3. Compatibility and ecosystem, highly compatible with RHEL, with a rich software warehouse; 4. Performance optimization, suitable for various hardware platforms and providing kernel tuning.

The Future of CentOS: Transitioning to New DistributionsThe Future of CentOS: Transitioning to New DistributionsMay 10, 2025 am 12:19 AM

CentOS will continue to evolve in the future, and users should choose alternative distributions. 1) Evaluate the requirements, choose such as RockyLinux or AlmaLinux, and focus on stability and support. 2) Develop a migration plan, use tools such as CentOS2Rocky, and pay attention to testing and verification. 3) Plan early, maintain contact with the open source community, and ensure a smooth transition.

CentOS: The Choice for Server EnvironmentsCentOS: The Choice for Server EnvironmentsMay 09, 2025 am 12:21 AM

CentOS is widely selected as a server operating system because it is stable, secure and free. 1.CentOS is based on RHEL, providing enterprise-level stability and a life cycle of up to 10 years. 2. It has rich software packages and strong community support. 3. Simple installation, use yum management software package, and intuitive configuration. 4. Improve server management efficiency through command line tools, regular backups and log management. 5. Optimize server performance by adjusting kernel and network parameters.

The Future of CentOS: What's Next?The Future of CentOS: What's Next?May 08, 2025 am 12:01 AM

CentOS will continue to develop through CentOSStream in the future. CentOSStream is no longer a direct clone of RHEL, but is part of RHEL development. Users can experience the new RHEL functions in advance and participate in development.

CentOS: From Development to Production EnvironmentsCentOS: From Development to Production EnvironmentsMay 07, 2025 am 12:08 AM

The transition from development to production in CentOS can be achieved through the following steps: 1. Ensure the consistent development and production environment, use the YUM package management system; 2. Use Git for version control; 3. Use Ansible and other tools to automatically deploy; 4. Use Docker for environmental isolation. Through these methods, CentOS provides powerful support from development to production, ensuring the stable operation of applications in different environments.

CentOS Stream: The Successor and its ImplicationsCentOS Stream: The Successor and its ImplicationsMay 06, 2025 am 12:02 AM

CentOSStream is a cutting-edge version of RHEL, providing an open platform for users to experience the new RHEL functions in advance. 1.CentOSStream is the upstream development and testing environment of RHEL, connecting RHEL and Fedora. 2. Through rolling releases, users can continuously receive updates, but they need to pay attention to stability. 3. The basic usage is similar to traditional CentOS and needs to be updated frequently; advanced usage can be used to develop new functions. 4. Frequently asked questions include package compatibility and configuration file changes, and requires debugging using dnf and diff. 5. Performance optimization suggestions include regular cleaning of the system, optimizing update policies and monitoring system performance.

CentOS: Examining the Reasons Behind the End of LifeCentOS: Examining the Reasons Behind the End of LifeMay 04, 2025 am 12:12 AM

The reason for the end of CentOS is RedHat's business strategy adjustment, community-business balance and market competition. Specifically manifested as: 1. RedHat accelerates the RHEL development cycle through CentOSStream and attracts more users to participate in the RHEL ecosystem. 2. RedHat needs to find a balance between supporting open source communities and promoting commercial products, and CentOSStream can better convert community contributions into RHEL improvements. 3. Faced with fierce competition in the Linux market, RedHat needs new strategies to maintain its leading position in the enterprise-level market.

The Reasons for CentOS's Shutdown: A Detailed AnalysisThe Reasons for CentOS's Shutdown: A Detailed AnalysisMay 03, 2025 am 12:05 AM

RedHat shut down CentOS8.x and launches CentOSStream because it hopes to provide a platform closer to the RHEL development cycle through the latter. 1. CentOSStream, as the upstream development platform of RHEL, adopts a rolling release mode. 2. This transformation aims to enable the community to get exposure to new RHEL features earlier and provide feedback to accelerate the RHEL development cycle. 3. Users need to adapt to changing systems and reevaluate system requirements and migration strategies.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft