Linux内核是Linux发行版中重要的组成部分,使用新的Linux内核也会支持更多的功能、特性,如BBR就需要4.9或更高版本的内核,如CentOS或RHEL类的Linux发行版需要升级Linux内核的话可以使用ELRepo第三方源来很方便进行升级。需要注意的是一般只有独立服务器、KVM、Xen支持更换内核,OpenVZ的是与HOST使用同一内核所有无法进行升级。升级内核属于高危操作,生产环境不建议进行升级,另外如果你的VPS没有Console、VNC之类的用于应急恢复或独服没有ipim之类的维护功能请勿进行升级操作。CentOS 8 默认内核版本为 4.18.x,内核版本高于 4.9 就可以直接开启 BBR,所以 CentOS 8 启用 BBR 非常简单。
首先呢,我们进入系统,输入yum update -y 更新系统,然后再看一下系统环境的版本情况。
[root@VM-0-14-centos ~]# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
目前是最新的8.2.2004,Centos8 的系统内核已经支持BBR了。我们只需要开启即可启动BBR
第一步:开启BBR
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf sysctl -p
输出代码结果如下:
[root@VM-0-14-centos ~]# echo “net.core.default_qdisc=fq” >> /etc/sysctl.conf
[root@VM-0-14-centos ~]# echo “net.ipv4.tcp_congestion_control=bbr” >> /etc/sysctl.conf
[root@VM-0-14-centos ~]# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
net.ipv4.conf.all.promote_secondaries = 1
net.ipv4.conf.default.promote_secondaries = 1
net.ipv6.neigh.default.gc_thresh3 = 4096
net.ipv4.neigh.default.gc_thresh3 = 4096
kernel.softlockup_panic = 1
kernel.sysrq = 1
net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.default.disable_ipv6 = 0
net.ipv6.conf.lo.disable_ipv6 = 0
kernel.shmmax = 68719476736
kernel.printk = 5
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
第二步,检查 BBR 是否开启成功
[root@VM-0-14-centos ~]# sysctl -n net.ipv4.tcp_congestion_control
bbr
[root@VM-0-14-centos ~]# lsmod | grep bbr
tcp_bbr 20480 1
[root@VM-0-14-centos ~]#
如果输出包含 BBR,说明启用成功。到这里,bbr已经开启成功了。接下来是升级内核,小白误入。
第三步,CentOS 8 升级内核
查看当前内核版本
目前Linux内核发布的最新稳定版可以从 https://www.kernel.org 进行查看,当前最新稳定版为 5.9.6 .
安装 ELRepo 源:
centos8:
rpm –import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh https://www.elrepo.org/elrepo-release-8.0-2.el8.elrepo.noarch.rpm
centos7:
rpm –import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm
centos6:
rpm –import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh https://www.elrepo.org/elrepo-release-6-9.el6.elrepo.noarch.rpm
启用 ELRepo 源仓库:
yum –disablerepo=”*” –enablerepo=”elrepo-kernel” list available
安装新内核:
yum -y –enablerepo=elrepo-kernel install kernel-ml kernel-ml-devel
不如意外,等半个小时以后,最新内核已经安装好。
修改 grub 配置使用新内核版本启动
dnf install grubby
grubby –default-kernel
当前最新版本 5.9.6,一般安装完就会以最新内核启动,回返回信息:
[root@VM-0-14-centos ~]# dnf install grubby
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Last metadata expiration check: 0:07:06 ago on Tue 10 Nov 2020 10:21:52 PM CST.
Package grubby-8.40-38.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@VM-0-14-centos ~]# grubby –default-kernel
/boot/vmlinuz-5.9.6-1.el8.elrepo.x86_64
[root@VM-0-14-centos ~]#
当前最新版本 5.9.6,一般安装完就会以最新内核启动。
如果不是,不是你之前安装的版本,那么需要查看所有内核:
grubby –info=ALL
[root@VM-0-14-centos ~]# grubby –info=ALL
index=0
kernel=”/boot/vmlinuz-5.9.6-1.el8.elrepo.x86_64″
args=”ro crashkernel=auto console=ttyS0 console=tty0 panic=5 net.ifnames=0 biosdevname=0 intel_idle.max_cstate=1 intel_pstate=disable $tuned_params”
root=”UUID=659e6f89-71fa-463d-842e-ccdf2c06e0fe”
initrd=”/boot/initramfs-5.9.6-1.el8.elrepo.x86_64.img $tuned_initrd”
title=”Red Hat Enterprise Linux (5.9.6-1.el8.elrepo.x86_64) 8.3 (Ootpa)”
id=”33790f3e0323419f9a055840e9d10b13-5.9.6-1.el8.elrepo.x86_64″
index=1
kernel=”/boot/vmlinuz-4.18.0-193.28.1.el8_2.x86_64″
args=”ro crashkernel=auto console=ttyS0 console=tty0 panic=5 net.ifnames=0 biosdevname=0 intel_idle.max_cstate=1 intel_pstate=disable $tuned_params”
root=”UUID=659e6f89-71fa-463d-842e-ccdf2c06e0fe”
initrd=”/boot/initramfs-4.18.0-193.28.1.el8_2.x86_64.img $tuned_initrd”
title=”CentOS Linux (4.18.0-193.28.1.el8_2.x86_64) 8 (Core)”
id=”33790f3e0323419f9a055840e9d10b13-4.18.0-193.28.1.el8_2.x86_64″
index=2
kernel=”/boot/vmlinuz-4.18.0-80.el8.x86_64″
args=”ro crashkernel=auto console=ttyS0 console=tty0 panic=5 net.ifnames=0 biosdevname=0 intel_idle.max_cstate=1 intel_pstate=disable $tuned_params”
root=”UUID=659e6f89-71fa-463d-842e-ccdf2c06e0fe”
initrd=”/boot/initramfs-4.18.0-80.el8.x86_64.img $tuned_initrd”
title=”CentOS Linux (4.18.0-80.el8.x86_64) 8 (Core)”
id=”33790f3e0323419f9a055840e9d10b13-4.18.0-80.el8.x86_64″
index=3
kernel=”/boot/vmlinuz-0-rescue-33790f3e0323419f9a055840e9d10b13″
args=”ro crashkernel=auto console=ttyS0 console=tty0 panic=5 net.ifnames=0 biosdevname=0 intel_idle.max_cstate=1 intel_pstate=disable”
root=”UUID=659e6f89-71fa-463d-842e-ccdf2c06e0fe”
initrd=”/boot/initramfs-0-rescue-33790f3e0323419f9a055840e9d10b13.img”
title=”CentOS Linux (0-rescue-33790f3e0323419f9a055840e9d10b13) 8 (Core)”
id=”33790f3e0323419f9a055840e9d10b13-0-rescue”
然后指定新内核启动:
grubby –set-default /boot/vmlinuz-5(复制到这里,然后按键盘TAB,Q左边哪一个,按一下就可以切换到最新内核)
我这里这样写,是因为我怕哪天更新了,你还按照我的输入,那就来鬼了。
重启系统 reboot,然后 uname -r 查看就是新内核。
[root@VM-0-14-centos ~]# uname -r
5.9.6-1.el8.elrepo.x86_64
[root@VM-0-14-centos ~]#