51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Centos7升级系统内核版本

因为服务环境需要高内核版本,故需要升级内核。

准备工作

检查系统版本
[root@cloud-master ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
检查内核版本
[root@cloud-master ~]# uname -r
3.10.0-1160.88.1.el7.x86_64
检查是否安装elrep源
[root@cloud-master ~]# rpm -q elrepo-release
elrepo-release-7.0-5.el7.elrepo.noarch

如未安装则使用yum安装,如未安装epel-release源请先安装epel-release源。

[root@cloud-master ~]# yum -y install elrepo-release
查看可安装内核列表

长期支持版本:kernel-lt
最新的稳定主线版本:kernel-ml

根据实际情况选择对应版本

[root@cloud-master ~]# 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

升级内核

这里我选择的是长期支持版本。

[root@cloud-master ~]# yum --enablerepo="elrepo-kernel" install -y kernel-lt
[root@cloud-master ~]# 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
查看内核版本及启动顺序
[root@cloud-master ~]# 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)
修改内核启动顺序
命令修改

配置完成后,reboot即可。

[root@cloud-node2 ~]# grub2-set-default 0
[root@cloud-node2 ~]# grub2-editenv list
saved_entry=0
手动修改

GRUB_DEFAULT=saved: 使用系统中记录的saved_entry的值作为默认启动项

编辑/etc/default/grub文件并修改GRUB_DEFAULT=配置序号为要设置的启动序号。

[root@cloud-master ~]# 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 配置文件,重启即可。

[root@cloud-master ~]# 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
检查结果
[root@cloud-master ~]# uname -r
5.4.238-1.el7.elrepo.x86_64
根据需要卸载旧版本
[root@cloud-master ~]# 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
安装新版内核工具
[root@cloud-master ~]# yum --enablerepo="elrepo-kernel" install -y kernel-lt-tools kernel-lt-tools-libs
验证
[root@cloud-master ~]# 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
赞(0)
未经允许不得转载:工具盒子 » Centos7升级系统内核版本