欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

linux中链路聚合配置

程序员文章站 2022-07-01 17:19:46
...

linux中链路聚合配置

链路聚合可以提高带宽。
环境:一台服务器,加两个网络适配器

1、添加网络适配器

在vm中,找到【虚拟机】—> 【设置】—>【添加】—>选择【网络适配器】—>【完成】,如下图:linux中链路聚合配置
2、查看网卡添加情况

[aaa@qq.com ~]# ip a |grep ens
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.184.137/24 brd 192.168.184.255 scope global dynamic ens33
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.184.163/24 brd 192.168.184.255 scope global dynamic ens37
[aaa@qq.com ~]# ethtool ens33        ###查看协商速率
Settings for ens33:
	Supported ports: [ TP ]
	Supported link modes:   10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	Supported pause frame use: No
	Supports auto-negotiation: Yes
	Advertised link modes:  10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	Advertised pause frame use: No
	Advertised auto-negotiation: Yes
	Speed: 1000Mb/s                      ###协商速率为1000MB/s
	Duplex: Full
	Port: Twisted Pair
	PHYAD: 0
	Transceiver: internal
	Auto-negotiation: on
	MDI-X: off (auto)
	Supports Wake-on: d
	Wake-on: d
	Current message level: 0x00000007 (7)
			       drv probe link
	Link detected: yes

可以查看到新添加的一块网络适配器ens37(在此处有可能添加的是ens38)

3、配置网卡

(1)创建ifcfg-bond0并修改配置文件

[aaa@qq.com network-scripts]# vim ifcfg-bond0
DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
IPADDR=192.168.184.110
NETMASK=255.255.255.0
IPV6INIT=no
USERCTL=no

(2)修改ifcfg-ens33配置文件

[aaa@qq.com network-scripts]# vim ifcfg-ens33 
DEVICE=ens33
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
IPV6INIT=no
USERCTL=no
MASTER=bond0
SLAVE=yes

(3)创建ifcfg-ens37并修改配置文件

[aaa@qq.com network-scripts]# vim ifcfg-ens37
DEVICE=ens37
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
IPV6INIT=no
USERCTL=no
MASTER=bond0
SLAVE=yes

4、创建 /etc/modprobe.d/bond0.conf 文件(或者用tail -2查看配置文件)

[aaa@qq.com network-scripts]# vim /etc/modprobe.d/bond0.conf
alias bond0 bonding
options bonding mode=0 miimon=100

5、重启网卡

[aaa@qq.com network-scripts]# systemctl restart network

重启网卡后,当前连接会断开,再重新打开一个窗口,使用地址192.168.184.110连接。

6、测试 ---- 192.168.184.110

使用ethtool bond0查看配置信息,也可以查看ip地址。

[aaa@qq.com ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
    link/ether 00:0c:29:a9:ca:a2 brd ff:ff:ff:ff:ff:ff
3: ens37: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
    link/ether 00:0c:29:a9:ca:a2 brd ff:ff:ff:ff:ff:ff
4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether 00:0c:29:a9:ca:a2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.184.110/24 brd 192.168.184.255 scope global bond0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fea9:caa2/64 scope link tentative dadfailed 
       valid_lft forever preferred_lft forever

[aaa@qq.com ~]# ethtool bond0
Settings for bond0:
	Supported ports: [ ]
	Supported link modes:   Not reported
	Supported pause frame use: No
	Supports auto-negotiation: No
	Advertised link modes:  Not reported
	Advertised pause frame use: No
	Advertised auto-negotiation: No
	Speed: 2000Mb/s                       ###提升了协商速率,协商速率为2000MB/s
	Duplex: Full
	Port: Other
	PHYAD: 0
	Transceiver: internal
	Auto-negotiation: off
	Link detected: yes
                    ###提升了协商速率,协商速率为2000MB/s
	Duplex: Full
	Port: Other
	PHYAD: 0
	Transceiver: internal
	Auto-negotiation: off
	Link detected: yes