因为服务环境需要高内核版本,故需要升级内核。
准备工作
检查系统版本
[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
检查内核版本
[[email protected] ~]# uname -r
3.10.0-1160.88.1.el7.x86_64
检查是否安装elrep源
[[email protected] ~]# rpm -q elrepo-release
elrepo-release-7.0-5.el7.elrepo.noarch
如未安装则使用yum安装,如未安装epel-release
源请先安装epel-release
源。
[[email protected] ~]# yum -y install elrepo-release
查看可安装内核列表
长期支持版本:kernel-lt
最新的稳定主线版本:kernel-ml
根据实际情况选择对应版本
[[email protected] ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-managerThis system is not registered with an entitlement server. You can use subscription-manager to register.Loading mirror speeds from cached hostfile
* elrepo-kernel: ftp.ne.jp
Available Packages
elrepo-release.noarch 7.0-6.el7.elrepo elrepo-kernel
kernel-lt-devel.x86_64 5.4.238-1.el7.elrepo elrepo-kernel
kernel-lt-doc.noarch 5.4.238-1.el7.elrepo elrepo-kernel
kernel-lt-headers.x86_64 5.4.238-1.el7.elrepo elrepo-kernel
kernel-lt-tools.x86_64 5.4.238-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs.x86_64 5.4.238-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs-devel.x86_64 5.4.238-1.el7.elrepo elrepo-kernel
kernel-ml.x86_64 6.2.8-1.el7.elrepo elrepo-kernel
kernel-ml-devel.x86_64 6.2.8-1.el7.elrepo elrepo-kernel
kernel-ml-doc.noarch 6.2.8-1.el7.elrepo elrepo-kernel
kernel-ml-headers.x86_64 6.2.8-1.el7.elrepo elrepo-kernel
kernel-ml-tools.x86_64 6.2.8-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs.x86_64 6.2.8-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs-devel.x86_64 6.2.8-1.el7.elrepo elrepo-kernel
perf.x86_64 5.4.238-1.el7.elrepo elrepo-kernel
python-perf.x86_64 5.4.238-1.el7.elrepo elrepo-kernel
升级内核
这里我选择的是长期支持版本。
[[email protected] ~]# yum --enablerepo="elrepo-kernel" install -y kernel-lt
[[email protected] ~]# rpm -qa|grep kernel
kernel-3.10.0-1160.88.1.el7.x86_64
kernel-lt-5.4.238-1.el7.elrepo.x86_64
kernel-tools-libs-3.10.0-1160.88.1.el7.x86_64
kernel-tools-3.10.0-1160.88.1.el7.x86_64
查看内核版本及启动顺序
[[email protected] ~]# awk -F' '$1=="menuentry " {print i++ " : " $2}' /boot/grub2/grub.cfg
0 : CentOS Linux (5.4.238-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1160.88.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-4fa186c3288b41d185a74baeeb9c5600) 7 (Core)
修改内核启动顺序
编辑/etc/default/grub
文件并修改GRUB_DEFAULT=
配置序号为要设置的启动序号。
[[email protected] ~]# vi /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
生成grub 配置文件
内核版本升级完成后需要重启。
[[email protected] ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.238-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.4.238-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.88.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.88.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-4fa186c3288b41d185a74baeeb9c5600
Found initrd image: /boot/initramfs-0-rescue-4fa186c3288b41d185a74baeeb9c5600.img
done
检查结果
[[email protected] ~]# uname -r
5.4.238-1.el7.elrepo.x86_64
根据需要卸载旧版本
[[email protected] ~]# rpm -e kernel-3.10.0-1160.88.1.el7.x86_64 kernel-tools-libs-3.10.0-1160.88.1.el7.x86_64 kernel-tools-3.10.0-1160.88.1.el7.x86_64
安装新版内核工具
[[email protected] ~]# yum --enablerepo="elrepo-kernel" install -y kernel-lt-tools kernel-lt-tools-libs
验证
[[email protected] ~]# rpm -qa|grep kernel
kernel-lt-5.4.238-1.el7.elrepo.x86_64
kernel-lt-tools-5.4.238-1.el7.elrepo.x86_64
kernel-lt-tools-libs-5.4.238-1.el7.elrepo.x86_64
文章来源于互联网:Centos7升级系统内核版本