Centos7开启BBR

Centos7开启BBR

升级内核

BBR 模块从 4.9 版本的内核中开始支持,CentOS7 的发布版标配的是 kernel-3.10,所以首先需要升级内核到大于等于 4.9 的版本,然后再更改设置开启 BBR。

查看内核版本

[root@centos7 ~]# uname -r
3.10.0-1127.19.1.el7.x86_64

查询得到的版本号为:3.10.0-1127.19.1.el7.x86_64,也就是3.10版本,需要进行升级

YUM方式升级安装

#导入该源的秘钥
[root@centos7 ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
#启用该源仓库
[root@centos7 ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
#查看有哪些内核版本可供安装
[root@centos7 ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
  • 可用的源如下所示:

    可用源主要分为了两个大版本,一个是lt版本,为长期支持版。另一个是ml版本,就是主线版本。长期支持版更加稳定!!建议选择长期支持版

    image-20210531104854447

  • 安装长期支持版

    [root@centos7 ~]# yum --enablerepo=elrepo-kernel install kernel-lt -y
    
  • 检查是否安装成功

    [root@centos7 ~]# rpm -qa | grep kernel
    

    查看是否有 5.4+ 的内核版本,如果有,则证明安装成功了:

    image-20210531105451576

更改开机启动项

在这里我根据网上教程执行 grub2-set-default 0 命令,经尝试 发现,执行该条命令的一个前提在于新安装的内核在第一个,所以将0设为默认启动项。 由上图可知,我新安装的内核(Centos Linux 5.0.9)不是在第一个,所以这样执行是有问题的。正确的做法应该是:

  • 查看所有的内核
[root@centos7 ~]# cat /boot/grub2/grub.cfg | grep menuentry

image-20210531105806778

可以看到我这里面有6个内核

  • 修改最新内核为默认启动(这儿只能使用上面命令输出中双引号 “ ” 或者单引号 ‘ ‘ 中的内容)
[root@centos7 ~]# grub2-set-default 'CentOS Linux (5.4.123-1.el7.elrepo.x86_64) 7 (Core)'
  • 验证默认启动内核

    [root@centos7 ~]# grub2-editenv list
    saved_entry=CentOS Linux (5.4.123-1.el7.elrepo.x86_64) 7 (Core)
    
  • 重启

    [root@centos7 ~]# reboot
    
  • 查看内核版本

    [root@centos7 ~]# uname -r
    5.4.123-1.el7.elrepo.x86_64
    

开启BBR

[root@centos7 ~]# echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
[root@centos7 ~]# echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
[root@centos7 ~]# sysctl -p

执行这一步时可能会有类似报错 error: “No such file or directory” setting key “net.core.default_qdisc”,不用管直接 reboot 即可。重启后执行。

[root@centos7 ~]# sysctl -n net.ipv4.tcp_congestion_control
bbr
[root@centos7 ~]# lsmod | grep bbr
tcp_bbr                20480  14 

如果两行命令都有 BBR 字样输出,则代表 BBR 启用成功。

原文地址:https://www.cnblogs.com/cuianbing/p/14830574.html