目录
- 起因
- 前提知识
- 配置步骤
- 参考文档
- 说明
起因
因为机房服务器新部署,双网卡服务器。一般来说业务系统的要求配置都是双网线然后配置bond0,主从轮番使用网卡就行。这次不太一样,网络管理员要求使用boud4模式,也是链路融合,所以就查询了一下资料没发现了bond的配置方式,很奇特的是,和Centos不一样,ubuntu都是使用bond0,但是转发策略不一样,通过策略可以实现类似bond4的模式。
前提知识
Bond 模式
Mode 0
balance-rr
Round-robin policy: Transmit packets in sequential order from the first available slave through the last. This mode provides load balancing and fault tolerance.
讲直白一点就是多网卡状态下顺序使用网卡的模式Mode 1
active-backup
Active-backup policy: Only one slave in the bond is active. A different slave becomes active if, and only if, the active slave fails. The bond’s MAC address is externally visible on only one port (network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior of this mode.
这个模式是主备模式,主挂了,备自动顶上。Mode 2
balance-xor
XOR policy: Transmit based on selectable hashing algorithm. The default policy is a simple source+destination MAC address algorithm. Alternate transmit policies may be selected via the xmit_hash_policy option, described below. This mode provides load balancing and fault tolerance.
这个模式呢,就是提供了一种基于mac地址的hash算法,负载均衡方式使用网卡。Mode 3
broadcast
Broadcast policy: transmits everything on all slave interfaces. This mode provides fault tolerance.
广播模式,每个网卡都会收到相同的报文。Mode 4
802.3ad
IEEE 802.3ad Dynamic link aggregation. Creates aggregation groups that share the same speed and duplex settings. Utilizes all slaves in the active aggregator according to the 802.3ad specification.
Prerequisites:
Ethtool support in the base drivers for retrieving the speed and duplex of each slave.
A switch that supports IEEE 802.3ad Dynamic link aggregation. Most switches will require some type of configuration to enable 802.3ad mode.
链路聚合方式,该方式呢,你可以这样理解,就是把多张物理网卡看成一个逻辑网卡,通过这个逻辑网卡进行传输,大概就是1+1约等于2 这样的一个概念。
这个模式有前提约束,1、就是必须有支持的驱动才可以。2、就是交换机必须支持802.3ad动态链路聚合的功能。Mode 5
balance-tlb
Adaptive transmit load balancing: channel bonding that does not require any special switch support. The outgoing traffic is distributed according to the current load (computed relative to the speed) on each slave. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed receiving slave.
Prerequisites:
Ethtool support in the base drivers for retrieving the speed of each slave.
自适应传输负载平衡:不需要任何特殊交换机支持的信道绑定。输出流量根据每个从机上的当前负载(相对于速度计算)进行分配。输入流量由当前从设备接收。如果接收从设备发生故障,另一个从设备将接管故障接收从设备的MAC地址。
原文翻译,自己没用过,没发言权了。T_TMode 6
balance-alb
Adaptive load balancing: includes balance-tlb plus receive load balancing (rlb) for IPV4 traffic, and does not require any special switch support. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the local system on their way out and overwrites the source hardware address with the unique hardware address of one of the slaves in the bond such that different peers use different hardware addresses for the server.
自适应负载平衡:包括IPV4流量的平衡tlb和接收负载平衡(rlb),不需要任何特殊的交换机支持。通过ARP协商实现接收负载平衡。绑定驱动程序在本地系统发送的ARP应答离开时拦截它们,并用绑定中的一个从设备的唯一硬件地址覆盖源硬件地址,使得不同的对等设备为服务器使用不同的硬件地址。
原文翻译,自己没用过,没发言权了。T_T(太心累了)
配置步骤
sudo vim /etc/netplan/00-installer-config.yaml
##将配置文件修改为以下样例
network:
ethernets:
switchports:
match: {name: "enth*"}
version: 2
renderer: networkd
bonds:
bond0:
addresses: [xxx.xxx.xxx.xxx/24] # 链路融合使用到的IP地址
gateway4: xxx.xxx.xxx.xxx
nameservers:
addresses:[114.114.114.114,8.8.8.8]
interfaces: [switchports]
parameters:
mode: 802.3ad #模式
mii-monitor-interval:
lacp-rate: fast
transmit-hash-policy: layer3+4 #可选配置layer2, layer3+4, layer2+3, encap2+3,encap3+4
layer3+4 就是我们需要的bond4模式。
参考文档
[官方netplan配置手册] https://manpages.ubuntu.com/manpages/focal/man5/netplan.5.html
[官方 bonding 模式说明-有点旧了,没有更新] https://help.ubuntu.com/community/UbuntuBonding?action=recall&rev=37
说明
其实写这篇文章的意图是解释transmit-hash-policy 这几个可选配置都是啥意思。
原文是这样的,摘出来备忘一下。
layer2 Uses XOR of hardware MAC addresses to generate the hash. This algorithm will place all traffic to a particular network peer on the same slave.
默认系统配置,这个配置就是标准的bond0的实现。根据MAC地址计算负载。layer2+3 Uses XOR of hardware MAC addresses and IP addresses to generate the hash. This algorithm will place all traffic to a particular network peer on the same slave.
比layer2多了一个根据IP负载的计算。layer3+4 This policy uses upper layer protocol information, when available, to generate the hash. This allows for traffic to a particular network peer to span multiple slaves, although a single connection will not span multiple slaves.
这个模式是Bond4,其实就是多网卡在使用过程中,其实针对一个外部地址,进行负载。encap2+3 This policy uses the same formula as layer2+3 but it relies on skb_flow_dissect to obtain the header fields which might result in the use of inner headers if an encapsulation protocol is used.
没用过,但根据内容来看,应该是在2+3 的基础上增加了一个skb_flow_dissect报文头,用来控制使用负载的。encap3+4 This policy uses the same formula as layer3+4 but it relies on skb_flow_dissect to obtain the header fields which might result in the use of inner headers if an encapsulation protocol is used.
没用过,同3+4模式一样,也是多了一个skb_flow_dissect报文头,用来控制使用负载的。