升级CentOS 7.4内核版本的三种方案

在实验环境下,已安装了最新的CentOS 7.4操作系统,现在需要升级内核版本。

实验环境

CentOS-7-x86_64-Minimal-1708.iso 
CentOS Linux release 7.4.1708 (Core) 
Kernel 3.10.0-693.el7.x86_64

方案一:小版本升级

连接并同步CentOS自带yum源,更新内核版本。此方法适用于更新内核补丁 。 

具体实验步骤:

sudo yum list kernel
sudo yum update -y kernel
[root@lry ~]# yum list kernel
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
base                                                                                                                                                  | 3.6 kB  00:00:00     
elrepo                                                                                                                                                | 2.9 kB  00:00:00     
epel                                                                                                                                                  | 3.2 kB  00:00:00     
extras                                                                                                                                                | 3.4 kB  00:00:00     
mysql-connectors-community                                                                                                                            | 2.5 kB  00:00:00     
mysql-tools-community                                                                                                                                 | 2.5 kB  00:00:00     
mysql57-community                                                                                                                                     | 2.5 kB  00:00:00     
updates                                                                                                                                               | 3.4 kB  00:00:00     
elrepo/primary_db                                                                                                                                     | 593 kB  00:00:05     
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * elrepo: mirrors.neusoft.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.cn99.com
Installed Packages
kernel.x86_64                                                                  3.10.0-327.el7                                                                       @anaconda
kernel.x86_64                                                                  3.10.0-514.6.2.el7                                                                   @updates 
kernel.x86_64                                                                  3.10.0-693.11.6.el7                                                                  @updates 
kernel.x86_64                                                                  3.10.0-862.6.3.el7                                                                   @updates 

此时,已安装成功,但若想将系统运行在新版本的kernel上,则需要重新启动操作系统。  
重启完成,至此,Kernel版本已升级至 3.10.0-862.6.3.el7.x86_64

方案二:大版本升级

载入elrepo源,搜索内核更新资源,并进行更新操作。 

具体实验步骤:

# 载入公钥
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# 安装ELRepo
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
# 载入elrepo-kernel元数据
yum --disablerepo=\* --enablerepo=elrepo-kernel repolist
# 查看可用的rpm包
yum --disablerepo=\* --enablerepo=elrepo-kernel list kernel*
# 安装最新版本的kernel
yum --disablerepo=\* --enablerepo=elrepo-kernel install -y kernel-ml.x86_64

重启,选择新版本内核进入系统。

此时,操作系统使用的内核已升级为【4.15.0-1.el7.elrepo.x86_64】

最后一步,需要将内核工具包一并升级

# 删除旧版本工具包
yum remove kernel-tools-libs.x86_64 kernel-tools.x86_64
# 安装新版本工具包
yum --disablerepo=\* --enablerepo=elrepo-kernel install -y kernel-ml-tools.x86_64

至此,已完成升级。

方案三:自编译升级

Step1: 下载源码 
Step2: 安装gcc bc cmake 
Step3: 编译源码,安装新内核 
自编译升级过程略微复杂,且不便于后期维护,具体操作步骤在此略去不表。

话题扩展

如何将新安装的内核设定为操作系统的默认内核,或者说如何将新版本的内核设置为重启后的默认内核? 

仅需两步,之后重启即可。

grub2-set-default 0
grub2-mkconfig -o /etc/grub2.cfg

术语解析

  • kernel-ml 
    kernel-ml 中的ml是英文【mainline stable】的缩写,elrepo-kernel中罗列出来的是最新的稳定主线版本。

  • kernel-lt 
    kernel-lt 中的lt是英文【long term support】的缩写,elrepo-kernel中罗列出来的长期支持版本。

Reference

[1] the ELRepo Project 
[2] kernel.org

猜你喜欢

转载自blog.csdn.net/u013230234/article/details/81009146