1.需求描述
如下规划图所示,DELL T440
服务器安装CENTOS
系统,现需将服务器的两个网卡连接至H3C
交换机S7003E
的GE0/0/17
和GE0/0/18
接口。服务器和交换机对接时能够通过链路聚合提高接口利用率,实现负载均衡。
2.配置思路
前面文章已经介绍过bond
的7
种模式,其中动态链路聚合(模式4
)需要交换机支持802.3ad
标准,并创建聚合组来共享传输速度。这种模式提供了更高的带宽和可靠性,可以满足上述需求。
这样,就可以分别进行配置:
在服务器这边,将em1
和em2
配置为bond
,并选择模式4
;
在交换机这边,创建聚合组,并改为动态模式,将GE0/0/17
和GE0/0/18
加入聚合组。
3.配置步骤
3.1配置LINUX服务器
# 创建一个虚拟网卡bond0
,编辑文件ifcfg-bond0
,写入网卡配置,保存退出。
vim /etc/sysconfig/network-scripts/ifcfg-bond0
BONDING_OPTS="mode=4 miimon=100 updelay=100 downdelay=100 xmit_hash_policy=layer3+4" # 设置bond模式为802.3ad (LACP),链路监控间隔100ms,上下延迟均为100ms,传输哈希策略为三层+四层
TYPE=Bond # 网络接口类型设置为Bond
BONDING_MASTER=yes # 表示这是一个Bond主接口
PROXY_METHOD=none # 不使用代理方法
BROWSER_ONLY=no # 不限制仅浏览器访问
BOOTPROTO=static # 使用静态IP地址配置
IPADDR=10.129.79.250 # 设置静态IP地址为172.16.79.250
PREFIX=24 # 设置子网掩码为255.255.255.0(等同于/24前缀)
GATEWAY=10.129.79.1 # 设置默认网关为172.16.79.1
DEFROUTE=yes # 将此接口作为默认路由
IPV4_FAILURE_FATAL=no # IPv4配置失败不是致命错误
NAME=bond0 # 接口名称为bond0
DEVICE=bond0 # 设备名称为bond0
ONBOOT=yes # 系统启动时自动激活此接口
# 编辑文件ifcfg-em1
,写入网卡配置,保存并退出。
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-em1
DEVICE=em1 # 指定网络接口的名称为em1
TYPE=Ethernet # 网络接口类型为以太网
ONBOOT=yes # 系统启动时自动激活此网络接口
SLAVE=yes # 表示此接口是bond0的从接口(slave)
MASTER=bond0 # 指定此从接口所属的主接口(master)为bond0
BOOTPROTO=none # 不使用任何启动协议来配置网络接口(因为此接口作为bond的从接口,其配置由bond接口管理)
说明:
在Linux系统中,
bonding
(绑定)是一种将多个物理网络接口绑定成一个逻辑接口的技术,以提高网络的可靠性和性能。上面配置中,em1
接口被配置为bond0
接口的从接口,意味着它的行为将受到bond0
接口配置的控制。
# 编辑文件ifcfg-em2
,写入网卡配置,保存并退出。
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-em2
DEVICE=em2
TYPE=Ethernet
ONBOOT=yes
SLAVE=yes
MASTER=bond0
BOOTPROTO=none
上面配置完成后,重启网络服务:
[root@localhost ~]# systemctl restart NetworkManager
3.2配置H3C交换机
# 创建二层聚合接口1
,并配置该接口为动态聚合模式。
[BDH-HXSW]interface Bridge-Aggregation 1
[BDH-HXSW-Bridge-Aggregation1]link-aggregation mode dynamic
[BDH-HXSW-Bridge-Aggregation1]
# 配置端口为边缘端口
[BDH-HXSW-Bridge-Aggregation1]stp edged-port
[BDH-HXSW-Bridge-Aggregation1]quit
[BDH-HXSW]
# 分别将端口GigabitEthernet0/0/17
和GigabitEthernet0/0/18
加入到聚合组1
中。
[BDH-HXSW]interface GigabitEthernet 0/0/17
[BDH-HXSW-GigabitEthernet0/0/17]port link-aggregation group 1
[BDH-HXSW-GigabitEthernet0/0/17]quit
[BDH-HXSW]
[BDH-HXSW]int GigabitEthernet 0/0/18
[BDH-HXSW-GigabitEthernet0/0/18]port link-aggregation group 1
[BDH-HXSW-GigabitEthernet0/0/18]quit
[BDH-HXSW]
# 配置聚合组1
类型,并加入相应的规划VLAN
[BDH-HXSW]interface Bridge-Aggregation 1
[BDH-HXSW-Bridge-Aggregation1]port link-type access
Configuring GigabitEthernet0/0/17 done.
Configuring GigabitEthernet0/0/18 done.
[BDH-HXSW-Bridge-Aggregation1]port access vlan 1079
Configuring GigabitEthernet0/0/17 done.
Configuring GigabitEthernet0/0/18 done.
[BDH-HXSW-Bridge-Aggregation1]
4.进行验证
# 在交换机上查看聚合状态
<BDH-HXSW>display link-aggregation verbose
Loadsharing Type: Shar -- Loadsharing, NonS -- Non-Loadsharing
Port Status: S -- Selected, U -- Unselected, I -- Individual
Port: A -- Auto port, M -- Management port, R -- Reference port
Flags: A -- LACP_Activity, B -- LACP_Timeout, C -- Aggregation,
D -- Synchronization, E -- Collecting, F -- Distributing,
G -- Defaulted, H -- Expired
Aggregate Interface: Bridge-Aggregation1
Creation Mode: Manual
Aggregation Mode: Dynamic
Loadsharing Type: Shar
Management VLANs: None
System ID: 0x8000, 083a-389d-9000
Local:
Port Status Priority Index Oper-Key Flag
GE0/0/17(R) S 32768 1 1 {ACDEF}
GE0/0/18 S 32768 2 1 {ACDEF}
Remote:
Actor Priority Index Oper-Key SystemID Flag
GE0/0/17 255 1 9 0xffff, f4ee-0831-90b3 {ACDEF}
GE0/0/18 255 2 9 0xffff, f4ee-0831-90b3 {ACDEF}
<BDH-HXSW>
# 在服务器上查看bond0
状态,可以看到其工作在动态聚合模式下,有两个成员端口,并携带LACP
信息。
[root@localhost ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer3+4 (1)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
802.3ad info
LACP rate: slow
Min links: 0
Aggregator selection policy (ad_select): stable
System priority: 65535
System MAC address: f4:ee:08:31:90:b3
Active Aggregator Info:
Aggregator ID: 1
Number of ports: 2
Actor Key: 9
Partner Key: 1
Partner Mac Address: 08:3a:38:9d:90:00
Slave Interface: em1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: f4:ee:08:31:90:b3
Slave queue ID: 0
Aggregator ID: 1
Actor Churn State: none
Partner Churn State: none
Actor Churned Count: 0
Partner Churned Count: 0
details actor lacp pdu:
system priority: 65535
system mac address: f4:ee:08:31:90:b3
port key: 9
port priority: 255
port number: 1
port state: 61
details partner lacp pdu:
system priority: 32768
system mac address: 08:3a:38:9d:90:00
oper key: 1
port priority: 32768
port number: 1
port state: 61
Slave Interface: em2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: f4:ee:08:31:90:b4
Slave queue ID: 0
Aggregator ID: 1
Actor Churn State: none
Partner Churn State: none
Actor Churned Count: 0
Partner Churned Count: 0
details actor lacp pdu:
system priority: 65535
system mac address: f4:ee:08:31:90:b3
port key: 9
port priority: 255
port number: 2
port state: 61
details partner lacp pdu:
system priority: 32768
system mac address: 08:3a:38:9d:90:00
oper key: 1
port priority: 32768
port number: 2
port state: 61
[root@localhost ~]#
# 在H3C
交换机上查看入流量。
<BDH-HXSW>display counters rate inbound interface
Usage: Bandwidth utilization in percentage
Interface Usage (%) Total (pps) Broadcast (pps) Multicast (pps)
BAGG1 0 531 -- --
GE0/0/17 0 0 -- --
GE0/0/18 0 531 -- --