共计 5844 个字符,预计需要花费 15 分钟才能阅读完成。
一键快速升级
# 导入 repo 密钥 / 源 && 安装最新内核 && 设置最新内核为第一启动顺序 && 重启服务器
# CentOS 7
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org && \
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm && \
yum clean all && \
rm -rf /var/cache/yum && \
yum --enablerepo=elrepo-kernel install kernel-ml -y && \
grub2-mkconfig -o /boot/grub2/grub.cfg && \
grub2-set-default 0 && \
reboot
# CentOS 8
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org && \
yum install -y https://www.elrepo.org/elrepo-release-8.0-2.el8.elrepo.noarch.rpm && \
yum clean all && \
rm -rf /var/cache/yum && \
yum --enablerepo=elrepo-kernel install kernel-ml -y && \
grub2-mkconfig -o /boot/grub2/grub.cfg && \
grub2-set-default 0 && \
reboot
# 确认内核版本
uname -r
5.3.7-1.el7.elrepo.x86_64
# done!
一步一步安装
导入 epel-repo
源
# CentOS 7
yum install -y https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
# CentOS 8
yum install -y https://www.elrepo.org/elrepo-release-8.0-2.el8.elrepo.noarch.rpm
导入密钥
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
清理 yum 缓存
yum clean all && rm -rf /var/cache/yum
检查当前能安装的内核版本
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available | grep kernel-ml
kernel-ml.x86_64 5.5.9-1.el7.elrepo elrepo-kernel
kernel-ml-devel.x86_64 5.5.9-1.el7.elrepo elrepo-kernel
kernel-ml-doc.noarch 5.5.9-1.el7.elrepo elrepo-kernel
kernel-ml-headers.x86_64 5.5.9-1.el7.elrepo elrepo-kernel
kernel-ml-tools.x86_64 5.5.9-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs.x86_64 5.5.9-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs-devel.x86_64 5.5.9-1.el7.elrepo elrepo-kernel
安装最新内核
yum -y install --enablerepo=elrepo-kernel kernel-ml
减少启动菜单的等待时间
下面的代码转载来的,实践过程中出现退出不了的情况,用一键安装没问题,有疑问可以文末的原文地址询问。
vim /etc/default/grub
# 将 GRUB_TIMEOUT=5 改为 1 即等待 1 秒后启动
#GRUB_TIMEOUT=5
GRUB_TIMEOUT=1
GRUB_DISTRIBUTOR="$(sed's, release .*$,,g'/etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=zh_CN.UTF-8"
GRUB_DISABLE_RECOVERY="true"
重新生成启动菜单列表 (兼容传统 /EFI)
grub2-mkconfig -o /boot/grub2/grub.cfg
确认启动顺序
index=0
的内核版本应该等于刚刚更新的内核版本即为正确
grubby --info=ALL
index=0
kernel=/boot/vmlinuz-5.5.9-1.el7.elrepo.x86_64
args="ro rhgb quiet crashkernel=auto biosdevname=0 net.ifnames=0"
root=/dev/vda1
initrd=/boot/initramfs-5.5.9-1.el7.elrepo.x86_64.img
title=CentOS Linux (5.5.9-1.el7.elrepo.x86_64) 7 (Core)
index=1
kernel=/boot/vmlinuz-4.11.8-1.el7.elrepo.x86_64
args="ro rhgb quiet crashkernel=auto biosdevname=0 net.ifnames=0"
root=/dev/vda1
initrd=/boot/initramfs-4.11.8-1.el7.elrepo.x86_64.img
title=CentOS Linux (4.11.8-1.el7.elrepo.x86_64) 7 (Core)
index=2
kernel=/boot/vmlinuz-0-rescue-149440bfb3fb443c9ec859e2714615c1
args="ro rhgb quiet crashkernel=auto biosdevname=0 net.ifnames=0"
root=/dev/vda1
initrd=/boot/initramfs-0-rescue-149440bfb3fb443c9ec859e2714615c1.img
title=CentOS Linux (0-rescue-149440bfb3fb443c9ec859e2714615c1) 7 (Core)
index=3
kernel=/boot/vmlinuz-0-rescue-4913bf8729dd48efa6db0b3f2b251530
args="ro rhgb quiet crashkernel=auto biosdevname=0 net.ifnames=0"
root=/dev/vda1
initrd=/boot/initramfs-0-rescue-4913bf8729dd48efa6db0b3f2b251530.img
title=CentOS Linux (0-rescue-4913bf8729dd48efa6db0b3f2b251530) 7 (Core)
index=4
kernel=/boot/vmlinuz-0-rescue-5a69dfb2a94f4ef6aca77e6a501028ba
args="ro rhgb quiet crashkernel=auto biosdevname=0 net.ifnames=0"
root=/dev/vda1
initrd=/boot/initramfs-0-rescue-5a69dfb2a94f4ef6aca77e6a501028ba.img
title=CentOS Linux (0-rescue-5a69dfb2a94f4ef6aca77e6a501028ba) 7 (Core)
index=5
kernel=/boot/vmlinuz-0-rescue-3f19b46f14dd47b7b760167faa8b14eb
args="ro rhgb quiet crashkernel=auto biosdevname=0 net.ifnames=0"
root=/dev/vda1
initrd=/boot/initramfs-0-rescue-3f19b46f14dd47b7b760167faa8b14eb.img
title=CentOS Linux (0-rescue-3f19b46f14dd47b7b760167faa8b14eb) 7 (Core)
index=6
kernel=/boot/vmlinuz-0-rescue-df8b983086ae46e1bed740034974dabd
args="ro rhgb quiet crashkernel=auto biosdevname=0 net.ifnames=0"
root=/dev/vda1
initrd=/boot/initramfs-0-rescue-df8b983086ae46e1bed740034974dabd.img
title=CentOS Linux (0-rescue-df8b983086ae46e1bed740034974dabd) 7 (Core)
index=7
non linux entry
切换默认启动内核为最新版本内核
grub2-set-default 0
重启
reboot
确认内核版本
uname -r
5.5.9-1.el7.elrepo.x86_64
开启 bbr
bbr 仅支持 kernel 版本 >= 4.9 以上的版本开启
# 检查当前环境是否有启用 bbr
lsmod | grep bbr
# 如果 没显示 bbr 则继续执行
modprobe tcp_bbr && \
echo "tcp_bbr" >> /etc/modules-load.d/modules.conf && \
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf &&\
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf && \
sysctl -p
确认 bbr 启用
lsmod | grep bbr
# 显示 tcp_bbr 表示 已启用 bbr
tcp_bbr 20480 1
sysctl net.ipv4.tcp_available_congestion_control && \
sysctl net.ipv4.tcp_congestion_control
# 显示有 bbr 表示 已启用 bbr
net.ipv4.tcp_available_congestion_control = reno cubic bbr
net.ipv4.tcp_congestion_control = bbr
内核降级
重新启动 在启动菜单选择旧版内核启动后执行删除新版内核操作
yum remove -y kernel-ml
删除后再次重启确认内核版本即可
清理旧内核
# 检查当前所有已安装的内核版本
rpm -qa |grep kernel
kernel-ml-headers-4.11.8-1.el7.elrepo.x86_64
kernel-ml-devel-4.11.8-1.el7.elrepo.x86_64
kernel-ml-5.5.9-1.el7.elrepo.x86_64
kernel-ml-4.11.8-1.el7.elrepo.x86_64
yum remove 非启动版本的内核即可清理
如 删除 kernel-ml-headers-4.11.8-1.el7.elrepo.x86_64
yum remove -y kernel-ml-headers-4.11.8-1.el7.elrepo.x86_64
运行过程
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package kernel-ml-headers.x86_64 0:4.11.8-1.el7.elrepo will be erased
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================
Package Arch Version Repository Size
===============================================================================================
kernel-ml-headers x86_64 4.11.8-1.el7.elrepo installed 4.0 M
Transaction Summary
===============================================================================================
Remove 1 Package
Installed size: 4.0 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Erasing : kernel-ml-headers-4.11.8-1.el7.elrepo.x86_64 1/1
Verifying : kernel-ml-headers-4.11.8-1.el7.elrepo.x86_64 1/1
Removed:
kernel-ml-headers.x86_64 0:4.11.8-1.el7.elrepo
安装完成后 VPS 信息:bbr 和 5.5.9 最新内核
转至并实践过:https://blankhang.com/archives/201908161015
正文完