debian12离线部署LACP链路聚合

1、下载ifenslave离线包

找一台联网的debian机器执行下载deb安装包

apt --download-only install ifenslave

会在/var/cache/apt/archives/目录下生成deb安装包

ifenslave_2.13_all.debnet-tools_2.10-0.1+deb12u2_amd64.deb拷贝出来

Debian 12默认支持FAT32,无需额外驱动,将两个.deb文件复制到U盘根目录

2、挂载U盘离线安装

插入U盘,查看U盘设备名

fdisk -l

创建挂载点安装离线包

# 创建目录
mkdir -p /data/usb  
# 挂载U盘(替换sdb4为实际设备)
mount /dev/sdb4 /data/usb
#进入挂载目录
cd /data/usb  
#安装离线包
dpkg -i ifenslave_2.13_all.deb net-tools_2.10-0.1+deb12u2_amd64.deb

验证安装

#检查是否安装
dpkg -l | grep ifenslave
# 检查net-tools(需重启终端)
ifconfig -V          

卸载U盘

umount /data/usb 

3、LACP 链路聚合配置

查看可用网络接口

ls /sys/class/net/

编辑 interfaces 文件

#编辑网络配置
vi /etc/network/interfaces

编辑内容如下

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# 物理网络接口配置
auto eno1
iface eno1 inet manual
    bond-master bond0
    bond-slave yes
    bond-mode 4       # LACP模式(802.3ad)
    bond-miimon 100   # 链路监控间隔(ms)
    bond-updelay 50   # 接口上线延迟
    bond-downdelay 50 # 接口下线延迟

auto eno2
iface eno2 inet manual
    bond-master bond0
    bond-slave yes
    bond-mode 4
    bond-miimon 100
    bond-updelay 50
    bond-downdelay 50

auto eno3
iface eno3 inet manual
    bond-master bond0
    bond-slave yes
    bond-mode 4
    bond-miimon 100
    bond-updelay 50
    bond-downdelay 50
    
auto eno4
iface eno4 inet manual
    bond-master bond0
    bond-slave yes
    bond-mode 4
    bond-miimon 100
    bond-updelay 50
    bond-downdelay 50
    
# LACP聚合接口(bond0)配置    
auto bond0
iface bond0 inet static
    address 10.21.26.16
    netmask 255.255.255.0
    gateway 10.21.26.1
    dns-nameservers 114.114.114.114 8.8.8.8
    bond-slaves eno1 eno2 eno3 eno4
    bond-mode 4
    bond-miimon 100
    bond-primary-reselect always
    bond-transmit-hash-policy layer2+3
    bond-lacp-rate 1  # 快速LACP模式(1为快速,0为慢速)
    bond-mii-status-updelay 100
    bond-mii-status-downdelay 100   	

重启服务器,验证LACP聚合状态

# 查看bond0接口状态
ifconfig bond0

# 查看LACP详细信息
cat /proc/net/bonding/bond0

# 查看聚合链路状态(需安装ethtool)
ethtool bond0

4、桥接

配置网络桥接模式,安装的依赖模块bridge-utils

apt install bridge-utils  

备份原来网卡信息

cp /etc/network/interfaces /etc/network/interfaces.bak

修改/etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# 物理网络接口配置
auto eno1
iface eno1 inet manual
    bond-master bond0
    bond-slave yes
    bond-mode 4       # LACP模式(802.3ad)
    bond-miimon 100   # 链路监控间隔(ms)
    bond-updelay 50   # 接口上线延迟
    bond-downdelay 50 # 接口下线延迟

auto eno2
iface eno2 inet manual
    bond-master bond0
    bond-slave yes
    bond-mode 4
    bond-miimon 100
    bond-updelay 50
    bond-downdelay 50

auto eno3
iface eno3 inet manual
    bond-master bond0
    bond-slave yes
    bond-mode 4
    bond-miimon 100
    bond-updelay 50
    bond-downdelay 50
    
auto eno4
iface eno4 inet manual
    bond-master bond0
    bond-slave yes
    bond-mode 4
    bond-miimon 100
    bond-updelay 50
    bond-downdelay 50
    
# LACP聚合接口(bond0)配置    
auto bond0
iface bond0 inet manual  #物理网卡需配置为manual模式
    bond-slaves eno1 eno2 eno3 eno4
    bond-mode 4
    bond-miimon 100
    bond-primary-reselect always
    bond-transmit-hash-policy layer2+3
    bond-lacp-rate 1  # 快速LACP模式(1为快速,0为慢速)
    bond-mii-status-updelay 100
    bond-mii-status-downdelay 100   
    
#桥接配置    
auto br0
iface br0 inet static
#iface br0 inet dhcp #若需DHCP分配IP,改为dhcp
    address 10.21.26.16
    netmask 255.255.255.0
    gateway 10.21.26.1
    bridge_ports bond0  # 将bond0作为桥接端口
    bridge_stp off
    bridge_fd 0
    dns-nameserver 114.114.114.114 8.8.8.8

简写

source /etc/network/interfaces.d/*

auto lo
iface lo inet loopback

auto eno1
iface eno1 inet manual

auto eno2
iface eno2 inet manual

auto eno3
iface eno3 inet manual

auto eno4
iface eno4 inet manual

auto bond0
iface bond0 inet manual
	bond-slaves eno1 eno2 eno3 eno4
	bond-miimon 100
	bond-mode 802.3ad
	bond-xmit-hash-policy layer3+4

auto vmbr0
iface vmbr0 inet static
	address 10.21.26.106/24
	gateway 10.21.26.254
	bridge-ports bond0
	bridge-stp off
	bridge-fd 0
	dns-nameserver 114.114.114.114 8.8.8.8

重启网络服务

systemctl restart networking

5、DNS问题

网络配置通了,dns解析不了,发现**/etc/resolv.conf**没有

手动生成一个

nano /etc/resolv.conf

写入:

nameserver 114.114.114.114
nameserver 8.8.8.8

Ctrl+O 保存文件

Ctrl+X 退出编辑器

6、其他

Debian 12默认已经安装了bonding内核模块,但需要确保其已加载:

lsmod | grep bonding

如果没有输出,说明bonding模块未加载,可以通过以下命令手动加载:

modprobe bonding

为确保系统重启后bonding模块自动加载,可以将其添加到/etc/modules文件中:

echo "bonding" >> /etc/modules

Bonding模式

根据需求选择合适模式(常用模式对比):

模式名称冗余能力带宽叠加交换机要求适用场景
Mode 1 (active-backup)主备模式主备切换单链路带宽高可用性基础方案
Mode 4 (802.3ad)LACP动态聚合多活冗余N倍带宽需支持LACP高性能负载均衡
Mode 6 (balance-alb)自适应负载均衡多活冗余近似N倍无需特殊交换机支持
  • 若交换机支持LACP,选 Mode 4(性能最优)交换机需配置对应的LACP聚合组

  • 若交换机不支持聚合协议,选 Mode 6(无需交换机配合)此模式支持流量收发均衡,且故障切换自动完成

bond-transmit-hash-policy参数详解

1.layer2:

使用二层帧头作为计算分发出口的参数,这导致通过同一个网关的数据流将完全从一个端口发送,为了更加细化分发策略,必须使用一些三层信息,然而却增加了计算开销。

2.layer2+3:

在1的基础上增加了三层的ip报头信息,计算量增加了,然而负载却更加均衡了,一个个主机到主机的数据流形成并且同一个流被分发到同一个端口,根据这个思想,如果要使负载更加均衡,我们在继续增加代价的前提下可以拿到4层的信息。

3.layer3+4:

layer3+4 该策略在可能的时候使用上层协议的信息来生成hash。这将允许特定网络对(network peer)的流量分摊到多个slave上,尽管同一个连接(connection)不会分摊到多个slave上。