龙空技术网

Linux链路聚合(Bonding)

冰原猫 553

前言:

此时各位老铁们对“redhat链路聚合”可能比较关怀,大家都需要学习一些“redhat链路聚合”的相关资讯。那么小编在网上网罗了一些对于“redhat链路聚合””的相关资讯,希望兄弟们能喜欢,我们一起来了解一下吧!

链路聚合LAG是指将多个网口组成一个逻辑网口,以提升带宽或者实现容错。

LAG在实现上有多种模式,大体可划分为备份和负荷分担两类。一个聚合口管理多个slave口,根据不同模式进行报文分配。

Linux提供bonding驱动来支持LAG,而Windows提供NIC Teaming技术。

Linux支持的Bonding模式

balance-rr (0)

属于分担模式,也提供容错能力。该模式下slave口按顺序轮流发包。

active-backup (1)

热备份模式。只有一个slave口为active状态,只有当前active口出问题了,才会切换到另一个slave口。

balance-xor (2)

负荷分担模式。根据报文内容做哈希计算来选择slave口,算法可通过xmit_hash_policy配置,默认算法是取源的目的MAC地址做异或运算,这种算法可以保证同一个二层连接使用的是同一个slave口。

broadcast (3)

容错模式。报文通过所有slave口发出。

802.3ad (4)

支持IEEE 802.3ad的模式

balance-tlb (5)

负荷分担模式。自适应发包负荷分担,根据配置有不同行为:

tlb_dynamic_lb=1 出向报文根据每个slave口的当前负载确定tlb_dynamic_lb=0 不考虑每个slave口的当前负载,只看哈希计算。

入向报文由当前slave接收,如果该slave出错,由另一个slave接管MAC地址。这种模式无需配置交换。

balance-alb (6)

负荷分担模式。与balance-tlb一样,再包含了入向报文的负荷分担。这种模式也无需配置交换。

Bonding配置

配置bonding驱动有多种方式,可以通过内核模块配置、initscripts等,这里只介绍 network scripts 的方式。

配置完成后,重启networking服务生效。除了通过 ifconfig 查看,也可以通过 /proc/net/bonding/bond0 查看

Redhat系列的配置

以两个网口eth0和eth1在linux下配置bond0为例,修改 ifcfg-eth0 和 ifcfg-eth1 配置文件

ONBOOT=yes      # 选配BOOTPROTO=noneMASTER=bond0SLAVE=yes

创建 ifcfg-bond0 配置文件

DEVICE=bond0NAME=bond0TYPE=BondBOOTPROTO=noneONBOOT=yesBONDING_MASTER=yesBONDING_OPTS="mode=1 miimon=100"  # bonding的配置都在这里,mode=1也可以写为active-backupIPADDR=...NETMASK=...

Bond口的mac地址可以通过MACADDR修改,但不能设置HWADDR,HWADDR只能用在真实存在的物理设备。

Debian系列的配置

ubuntu主配置文件 /etc/network/interfaces

也可以在interfaces.d里放配置文件,但interfaces需要添加 source /etc/network/interfaces.d/* (16.04以前是source-directory /etc/network/interfaces.d)

eth0, eth1配置bond0,active-backup模式,eth0为主用口:

# eth0 is manually configured, and slave to the "bond0" bonded NICauto eth0iface eth0 inet manualbond-master bond0bond-primary eth0# eth1 ditto, thus creating a 2-link bond.auto eth1iface eth1 inet manualbond-master bond0# bond0 is the bonding NIC and can be used like any other normal NIC.# bond0 is configured using static network information.auto bond0iface bond0 inet staticaddress 192.168.1.10gateway 192.168.1.1netmask 255.255.255.0bond-mode active-backupbond-miimon 100bond-slaves none

使用802.3ad LACP协议:

# eth0 is manually configured, and slave to the "bond0" bonded NICauto eth0iface eth0 inet manualbond-master bond0# eth1 ditto, thus creating a 2-link bond.auto eth1iface eth1 inet manualbond-master bond0# bond0 is the bonded NIC and can be used like any other normal NIC.# bond0 is configured using static network information.auto bond0iface bond0 inet staticaddress 192.168.1.10gateway 192.168.1.1netmask 255.255.255.0# bond0 uses standard IEEE 802.3ad LACP bonding protocolbond-mode 4bond-miimon 100bond-lacp-rate 1bond-slaves eth0 eth1

bond-mode指定bonding模式

ubuntu16.04默认不加载bonding驱动,需要在/etc/modules里添加bonding模块,或通过modprobe bonding手工加载。

ubuntu16.04还需要安装ifenslave包才能支持bonding。官方文档见

标签: #redhat链路聚合 #linux端口聚合链路聚合