Linux下多网卡绑定bond及模式介绍

资讯 2024-07-09 阅读:43 评论:0
【介绍】Introduction 网卡bond一般主要用于网络吞吐量很大,以及对于网络稳定性要求较高的场景。Netcard bond is generally used mainly in situations whe...
美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

【介绍】

Introduction

网卡bond一般主要用于网络吞吐量很大,以及对于网络稳定性要求较高的场景。

Netcard bond is generally used mainly in situations where network throughput is high and where network stability is more demanding.

主要是通过将多个物理网卡绑定到一个逻辑网卡上,实现了本地网卡的冗余,带宽扩容以及负载均衡。

The redundancy of local net cards, bandwidth and load balance was achieved mainly by tying multiple physical net cards to a logical network card.

Linux下一共有七种网卡bond方式,实现以上某个或某几个具体功能。

Linux has a total of seven web-cardbond ways to achieve one or more of these specific functions.

最常见的三种模式是bond0,bond1,bond6.

The three most common patterns are Bond0, Bond1, Bond6.

【bond0】

平衡轮循环策略,有自动备援,不过需要"Switch"支援及设定。

Balance cycle strategy, with automatic backup, but with &quat; Switch&quat; support and setting.

balance-rr(Round-robin policy)

方式:

Modalities:

传输数据包的顺序是依次传输(即:第一个包走eth0,第二个包就走eth1……,一直到所有的数据包传输完成)。

The transmission of the data package is sequential (i.e., the first package takes Eth0, the second package takes Eth1, until all the data pack transfers are completed).

优点:

Advantages:

提供负载均衡和容错能力。

Provides load balance and tolerance for error.

缺点:

Disadvantages:

同一个链接或者会话的数据包从不同的接口发出的话,中间会经过不同的链路,在客户端可能会出现数据包无法有序到达的情况,而无序到达的数据包将会被要求重新发送,网络吞吐量反而会下降。

When a data package with the same link or session is sent from a different interface, a different link between the two links may occur on the client side where the package cannot be reached in an orderly manner, while a data package that arrives disorderlyly will be required to be re-transmitted and the amount of Internet throughput will decline.

【bond1】

主-备份策略

Main-backup policy

active-backup(Active -backup policy)

方式:

Modalities:

只有一个设备处于活动状态,一个宕掉之后另一个马上切换为主设备。

Only one equipment was in active condition, and the other immediately after one fell off was switched to the main equipment.

mac地址为外部可见,从外面看,bond的mac地址是唯一的,switch不会发生混乱。

The mac address is external and, from outside, the bond's mac address is the only one, and there will be no confusion with the switch.

优点:

Advantages:

提高了网络连接的可靠性。

Improved reliability of network connections.

缺点:

Disadvantages:

此模式只提供容错能力,资源利用性较低,只有一个接口处于active状态,在有N个网络接口bond的状态下,利用率只有1/N。

This model provides only for error tolerance, low resource utilization, only one interface in active status and only 1/N utilization in the N network interface position.

【bond2】

平衡策略

Balance strategy

balance-xor(XOR policy)

方式:

Modalities:

基于特性的Hash算法传输数据包。

The Hash algorithm based on characteristics transmits the data package.

缺省的策略为:(源MAC地址 XOR 目标MAC地址) % slave数量。 # XRO为异或运算,值不同时结果为1,相同为0

The default strategy is: (source MAC address XOR target MAC address) %slave number. #XRO is different or operational, with a value of 1 and the same value of 0

可以通过xmit_hash_policy选项设置传输策略。

The transfer policy can be set by xmit_hash_policy options.

特点:

Features:

提供负载均衡和容错能力。

Provides load balance and tolerance for error.

【bond3】

广播策略

Broadcasting strategy

broadcast

方式:

Modalities:

在每个slave接口上传输每一个数据包。

Transfers each data package on each slave interface.

特点:

Features:

提供容错能力。

Provision of fault tolerance.

【bond4】

IEEE 802.3ad 动态链接聚合

IEEE 802.3ad Dynamic Link Convergence

802.3ad( IEEE 802.3ad Dynamic link aggregation)

方式:

Modalities:

创建一个聚合组,共享同样的速率和双工设定。

Creates a condensed group that shares the same speed and double-work settings.

根据802.3ad规范将多个slave工作在同一个激活的聚合体下。外出流量的slave选举基于传输Hash策略,同样,此策略也可以通过xmit_hash_policy选项进行修改。

The slave election is based on transmitting the Hash strategy, which can also be modified through the xmit_hash_policy option.

注意:

Note:

并不是所有的传输策略都是802.3ad所适应的。

Not all transmission strategies are adapted to 802.3ad.

条件:

Condition:

1. ethtool支持获取每个slave的速率和双工设定。

1. Ethtool supports the acquisition of the rate and double-entry set for each slave.

2. switch支持IEEE 802.3ad Dynamic link aggregation(大多数交换机需要设定才支持)

2. switch supports IEE 802.3ad Dynamic link support (most switches need to be set to support)

【bond5】

适配器传输负载均衡

Fitter Transfer Load Balance

balance-tlb(Adaptive transmit load balancing)

方式:

Modalities:

在每个slave上根据当前的负载(依据速度)分配外出流量,接收时使用当前轮到的slave。

The outgoing flow is distributed on each slave according to the current load (at speed) and is received using the current slave.

如果正在接受数据的slave出故障了,另一个slave接管失败的slave的MAC地址。

If the slave that was receiving the data failed, another slave took over the failed slave MAC address.

条件:

Condition:

ethtool支持获取每个slave的速率。

Ethtool supports the acquisition of the rate per slave.

特点:

Features:

不需要任何特别的switch(交换机)支持的通道bonding。

Do not need any special switch (exchange) support for the channelbonding.

【bond6】

适配器适应性负载均衡

Adaptive load balance for adaptors

balance-alb(Adaptive load balancing)

方式:

Modalities:

此模式包含了bond5的balance-tlb,同时增加了针对IPV4流量的接收负载均衡。(receive load balance, rlb)

This model includes the bend5 balance-tlb, while increasing the load balance for IPV4 traffic. (received load balance, rlb)

接收负载均衡是通过ARP协商实现的。

The receiving load balance is achieved through ARP consultations.

bonding驱动截获本机发送的ARP应答,并把源硬件地址改写为bond中某个slave的唯一硬件地址,从而使得不同的对端使用不同的硬件地址进行通信。

Bonding drives the interception of ARP responses sent by this machine and recasts the source hardware address to the only hardware address of one of the slaves in the Bond, allowing different end-to-ends to communicate using different hardware addresses.

来自服务器端的接收流量也会被均衡。

The reception traffic from the server end will also be balanced.

当本机发送ARP请求时,bonding驱动把对端的IP信息从ARP包中复制并保存下来。

When this machine sends an ARP request, the binding driver reproduces and saves IP information from the end from the ARP package.

当ARP应答从对端到达时,bonding驱动把它的硬件地址提取出来,并发起一个ARP应答给bond中的某个slave。

When the ARP response arrives from the counter, the binding drives to extract its hardware address and initiates an ARP response to one of the Bonds slave.

使用ARP协商进行负载均衡的一个问题是:

One of the problems with the use of ARP consultations for load balance is:

每次广播 ARP请求时都会使用bond的硬件地址,因此对端学习到这个硬件地址后,接收流量将会全部流向当前的slave。

The hardware address of the bond is used for each ARP request broadcast, so when the other end learns about the hardware address, the receiving traffic will flow to the current slave.

这个问题可以通过给所有的对端发送更新 (ARP应答)来解决,应答中包含他们独一无二的硬件地址,从而导致流量重新分布。

This problem can be solved by sending updates (ARP responses) to all the pairs, which contain their unique hardware addresses, leading to a redistribution of traffic.

当新的slave加入到bond中时,或者某个未激活的slave重新 激活时,接收流量也要重新分布。

When a new slave is added to the bond, or an inactive slave is reactivated, the receiving traffic is also redistributed.

接收的负载被顺序地分布(round robin)在bond中最高速的slave上当某个链路被重新接上,或者一个新的slave加入到bond中,接收流量在所有当前激活的slave中全部重新分配,通过使用指定的MAC地址给每个 client发起ARP应答。

The received load is distributed sequentially (round robin) at the highest speed in Bond when the slave is reconnected to a certain link, or a new slave is added to the bond, and the receiving traffic is fully redistributed among all currently activated slaves by using the designated MAC address to initiate the ARP response to each clit.

下面介绍的updelay参数必须被设置为某个大于等于switch(交换机)转发延时的值,从而保证发往对端的ARP应答不会被switch(交换机)阻截。

The updelay parameter presented below must be set to a value greater than the extension delay equal to the switch (exchanger) so as to ensure that the ARP response sent to the counter is not intercepted by the switch (exchanger).

条件:

Condition:

1. ethtool支持获取每个slave的速率

1. ethtool supports the acquisition of the rate per slave

2. 底层驱动支持设置某个设备的硬件地址

2. Bottom drive supports the setting up of a hardware address for a device

特点:

Features:

总是有一个slave(curr_active_slave)使用bond的硬件地址,同时每个bond里面的slave都有一个唯一的硬件地址。

There is always a slave (cur_active_slave) hardware address using bond, while each slave in bond has a single hardware address.

如果curr_active_slave出了故障,则它的硬件地址会被重新选举产生的slave接管。

If the curr_active_slave fails, its hardware address will be taken over by the re-elected slave.

与bond0最大的区别在于,bond0的多张网卡里面的流量几乎是相同的,但是bond6里面的流量是先占满eth0,再占满eth1……依次

The biggest difference to Bond0 is that the traffic in the multi-net cards of Bond0 is almost the same, but the traffic in Bond6 is to fill eth0 first and eth1 in turn.

【网卡绑定】

[net cards tied]

我们假定前条件:

We assume that the pre-condition:

2个物理网口eth0,eth1

2 physical nodes eth0, eth1

绑定后的虚拟口为bond0

The bound virtual mouth is Bond0.

服务器IP为10.10.10.1

Server IP 10.10.10.1

配置文件:

Profile:

1. vi /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0

BOOTPROTO=none

ONBOOT=yes

IPADDR=10.10.10.1

NETMASK=255.255.255.0

NETWORK=192.168.0.0

2. vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

3. vi /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

修改modprobe相关设定文件,并加载bonding模块:

Modify the modprobe-related settings file and load the binding module:

1. vi /etc/modprobe.d/bonding.conf

alias bond0 bonding

options bonding mode=0 miimon=200

2. 加载模块

2. Loading modules

modprobe bonding

3. 确认是否加载成功

3. Confirmation of successful loading

[root@slb ~]# lsmod | grep bonding

bonding 100065 0

4. 重启网络

4. Restarting the network

[root@slb ~]# /etc/init.d/network restart

[root@slb ~]# 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@slb ~]# ifconfig |grep HWadd

bond0 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74

eth0 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74

eth1 Link encap:Ethernet HWaddr 00:16:36:1B:BB:74

以上信息可以确认:

The following information can be identified:

a. 现在的bonding模式是active-backup

a. The current Bonding model is active-backup

b. 现在Active的网口是eth0

b. The active portal is now eth0

c. bond0, eth1的物理地址和处于active状态下的eth0的物理地址相同,这样是为了避免上位交换机发生混乱。

c. Bond0, the physical address of eth1 is the same as the physical address of eth0, which is in active condition, in order to avoid confusion on the top switch.

可以随意拔掉一根网线或者在交换机上shutdown一个网口,查看网络是否依旧联通。

It is possible to unplug a network or shutdown a portal on the switchboard to see if the network is still connected.

5. 系统启动自动绑定并增加默认网关(可选)

5. System start-up automatically binds and increases default gateways (optional)

[root@slb ~]# vi /etc/rc.d/rc.local

ifenslave bond0 eth0 eth1

route add default gw 10.10.10.1

【多网卡绑定】

♪ Multinet cards tied ♪

上面只是两个网卡绑定一个bond0的情况,如果我们要设置多个bond口,就不能这样做了。

It's just the case of two webcards tied to a Bond0, and we can't do that if we're going to have more than one Bond mouth.

·/etc/modprobe.d/bonding.conf·的修改可以如下:

./etc/modprobe.d/bonding.conf. could be amended as follows:

1. 多个bond的模式一样的情况

1. Same pattern as multiple bond

alias bond0 bonding

alias bond1 bonding

options bonding max_bonds=2 miimon=200 mode=1

2. 多个bond的模式不一样的情况

2. Different patterns of multiple bond

alias bond0 bonding

options bond0 miimon=100 mode=1

install bond1 /sbin/modprobe bonding -o bond1 miimon=200 mode=0

install bond2 /sbin/modprobe bonding -o bond2 miimon=100 mode=1

美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
文字格式和图片示例

注册有任何问题请添加 微信:MVIP619 拉你进入群

弹窗与图片大小一致 文章转载注明

分享:

扫一扫在手机阅读、分享本文

发表评论
平台列表
美化布局示例

欧易(OKX)

  全球官网 大陆官网

币安(Binance)

  官网

火币(HTX)

  官网

Gate.io

  官网

Bitget

  官网

deepcoin

  官网
热门文章
  • DDO在新加坡上市真假,欧意交易所能交易数字期权吗?

    DDO在新加坡上市真假,欧意交易所能交易数字期权吗?
    然而,对于DDO在新加坡的列名是否真实存在争议。 据报道,有人质疑DDO的数字选项是否真的上市,其背景是否经过了彻底调查。 首先,有报告说,DDO数字选项清单仅仅是一种宣传手段,没有找到DDO交易的平台,这就对DDO的真正清单提出了疑问。 其次,一些媒体调查了DDO数字选项的背景。 报告显示DDO数字选项发行人声称其数字选项是国家赞助的,但实际上,根据中国人民银行,虚拟货币相关业务是非法金融活动。 此外,DDO数字选项在视频号码等平台上广为传播,吸引了许多信徒的注意,然...
  • Griffin Gaming Partners计划为其第三支基金筹集5亿美元

    Griffin Gaming Partners计划为其第三支基金筹集5亿美元
    Pitchbook引用的6月8日《快链头条新闻》作为监管文件, 指出游戏风险投资公司Griffin赌博伙伴计划为其第三个旗舰基金筹集5亿美元, 比第二个基金少33%。 2021年,格里芬赌博伙伴从Web3游戏开发者Forte获得A回合资金1.85亿美元,并于2022年筹集了第二个旗舰基金,金额达7.5亿美元,此时风险资本家对Web3和加密游戏的热情达到顶峰。...
  • 加密货币之王重回王位:比特币飙升至 71,000 美元,还能再涨多少?

    加密货币之王重回王位:比特币飙升至 71,000 美元,还能再涨多少?
    比特币是市场上最大的加密货币,它再次打破了重要的7万美元门槛。 在短短的四舍五入(67,000美元到69,000美元之间)之后,价格在这一水平上遇到了强烈的抵制。 然而,势头的不断增强表明,比特币可能形成一个超过70 000美元的板块,为重新测试下一个抵抗阵地71 300美元和3月份可能攀升到历史最高点73 700美元铺平了道路。 问题仍然是:比特币能否维持预期的上升趋势并继续大幅上升?    分析家预计比特币价格将上升到74,400美元。 加密货币分析师Ali M...
  • 比过山车还狠!比特币价格再次暴跌

    比过山车还狠!比特币价格再次暴跌
      上周日,比特币的价格创造了3000美元的历史新高,随后就开始各种高台跳水了。Last Sunday, the price of Bitcoin created a record high of $3,000, and then began to dive on all the high platforms.   据外媒报道,本周一,比特币价格一度下跌到2526.4美元,最高跌幅高达14.5%,这创造了2015年1月以来最大跌幅。According to external...
  • 几张图看懂区块链技术到底是什么?https://www.cnblogs.com/behindman/p/8873191.html

    几张图看懂区块链技术到底是什么?https://www.cnblogs.com/behindman/p/8873191.html
    “区块链”的概念可以说是异常火爆,好像互联网金融峰会上没人谈一谈区块链技术就out了,BAT以及各大银行还有什么金融机构都在开始自己的区块链研究工作,就连IBM最近也成立了自己的区块链研究实验室,但其实区块链到底是什么?大家或许并不清楚,停留在雾里看花的状态。从今天开始,就让我们一起走进区块链,揭开区块链的神秘面纱吧!The concept of a block chain can be described as an unusually hot one, as if no...
标签列表