帮助文档
专业提供香港服务器、香港云服务器、香港高防服务器租用、香港云主机、台湾服务器、美国服务器、美国云服务器vps租用、韩国高防服务器租用、新加坡服务器、日本服务器租用 一站式全球网络解决方案提供商!专业运营维护IDC数据中心,提供高质量的服务器托管,服务器机房租用,服务器机柜租用,IDC机房机柜租用等服务,稳定、安全、高性能的云端计算服务,实时满足您的多样性业务需求。 香港大带宽稳定可靠,高级工程师提供基于服务器硬件、操作系统、网络、应用环境、安全的免费技术支持。
服务器资讯 / 香港服务器租用 / 香港VPS租用 / 香港云服务器 / 美国服务器租用 / 台湾服务器租用 / 日本服务器租用 / 官方公告 / 帮助文档
Linux系统之升级内核版本方法
发布时间:2024-03-06 15:08:10   分类:帮助文档
Linux系统之升级内核版本方法






Linux系统之升级内核版本方法
一、检查本地系统环境1.检查系统版本2.检查系统内核版本
二、小版本升级内核1.列出yum仓库的内核包版本2.升级内核3.重启并检查内核版本
三、大版本升级内核1.导入公钥2.下载并安装elrepo仓库3.载入elrepo-kernel元数据4.列出rpm包5.安装最新版本kernel6.查看内核是否载入到grub27.设置新的内核为grub2的默认版本8.检查重启后的系统内核版本



一、检查本地系统环境
1.检查系统版本
[root@jeven ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"



2.检查系统内核版本
[root@jeven ~]# uname -r
3.10.0-957.el7.x86_64



二、小版本升级内核
1.列出yum仓库的内核包版本

确保yum仓库的正常,本次实践用的是阿里的镜像源。

[root@jeven yum.repos.d]# yum list kernel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* epel: mirrors.bfsu.edu.cn
Installed Packages
kernel.x86_64 3.10.0-957.el7 @anaconda
Available Packages
kernel.x86_64 3.10.0-1160.81.1.el7 updates

2.升级内核

直接更新内核版本,此方法适用于更新内核补丁。

[root@jeven yum.repos.d]# yum update -y kernel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 8.5 kB 00:00:00
* epel: mirrors.bfsu.edu.cn
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/3): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(2/3): epel/x86_64/primary_db | 7.0 MB 00:00:01
(3/3): updates/7/x86_64/primary_db | 19 MB 00:00:09
Resolving Dependencies
--> Running transaction check
---> Package kernel.x86_64 0:3.10.0-1160.83.1.el7 will be installed
--> Processing Dependency: linux-firmware >= 20190429-72 for package: kernel-3.10.0-1160.83.1.el7.x86_64
--> Running transaction check
---> Package linux-firmware.noarch 0:20180911-69.git85c5d90.el7 will be updated
---> Package linux-firmware.noarch 0:20200421-80.git78c0348.el7_9 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================================
Installing:
kernel x86_64 3.10.0-1160.83.1.el7 updates 52 M
Updating for dependencies:
linux-firmware noarch 20200421-80.git78c0348.el7_9 updates 80 M

Transaction Summary
======================================================================================================================================================================
Install 1 Package
Upgrade ( 1 Dependent package)

Total download size: 132 M
Downloading packages:
No Presto metadata available for updates
(1/2): kernel-3.10.0-1160.83.1.el7.x86_64.rpm | 52 MB 00:00:31
(2/2): linux-firmware-20200421-80.git78c0348.el7_9.noarch.rpm | 80 MB 00:00:48
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 2.7 MB/s | 132 MB 00:00:48
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : linux-firmware-20200421-80.git78c0348.el7_9.noarch 1/3
Installing : kernel-3.10.0-1160.83.1.el7.x86_64 2/3
Cleanup : linux-firmware-20180911-69.git85c5d90.el7.noarch 3/3
Verifying : kernel-3.10.0-1160.83.1.el7.x86_64 1/3
Verifying : linux-firmware-20200421-80.git78c0348.el7_9.noarch 2/3
Verifying : linux-firmware-20180911-69.git85c5d90.el7.noarch 3/3

Installed:
kernel.x86_64 0:3.10.0-1160.83.1.el7

Dependency Updated:
linux-firmware.noarch 0:20200421-80.git78c0348.el7_9

Complete!




3.重启并检查内核版本
重启服务器
reboot

检查内核版本

重启完成,发现内核版本已经升级为【3.10.0-1160.83.1.el7.x86_64】

[root@jeven ~]# uname -r
3.10.0-1160.83.1.el7.x86_64



三、大版本升级内核
1.导入公钥

ELRepo是一个为Linux提供驱动程序和内核映像的存储库,这里的内核大版本升级方案就是采用ELRepo提供的内核通道。

[root@jeven ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@jeven ~]#

2.下载并安装elrepo仓库

ELRepo内核下载地址:https://elrepo.org/linux/kernel/el7/x86_64/RPMS/,如果服务器不能联网,可离线下载。

[root@jeven ~]# yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
Loaded plugins: fastestmirror, langpacks
elrepo-release-7.el7.elrepo.noarch.rpm | 8.7 kB 00:00:00
Examining /var/tmp/yum-root-RRC6Uo/elrepo-release-7.el7.elrepo.noarch.rpm: elrepo-release-7.0-6.el7.elrepo.noarch
Marking /var/tmp/yum-root-RRC6Uo/elrepo-release-7.el7.elrepo.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package elrepo-release.noarch 0:7.0-6.el7.elrepo will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================================
Installing:
elrepo-release noarch 7.0-6.el7.elrepo /elrepo-release-7.el7.elrepo.noarch 5.0 k

Transaction Summary
======================================================================================================================================================================
Install 1 Package

Total size: 5.0 k
Installed size: 5.0 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : elrepo-release-7.0-6.el7.elrepo.noarch 1/1
Verifying : elrepo-release-7.0-6.el7.elrepo.noarch 1/1

Installed:
elrepo-release.noarch 0:7.0-6.el7.elrepo

Complete!

3.载入elrepo-kernel元数据
[root@jeven ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
elrepo-kernel | 3.0 kB 00:00:00
elrepo-kernel/primary_db | 2.1 MB 00:00:00
repo id repo name status
elrepo-kernel ELRepo.org Community Enterprise Linux Kernel Repository - el7 34
repolist: 34



4.列出rpm包

列出elrepo-kernel的rpm包

[root@jeven ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel list kernel*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
Installed Packages
kernel.x86_64 3.10.0-957.el7 @anaconda
kernel.x86_64 3.10.0-1160.83.1.el7 @updates
kernel-tools.x86_64 3.10.0-957.el7 @anaconda
kernel-tools-libs.x86_64 3.10.0-957.el7 @anaconda
Available Packages
kernel-lt.x86_64 5.4.230-1.el7.elrepo elrepo-kernel
kernel-lt-devel.x86_64 5.4.230-1.el7.elrepo elrepo-kernel
kernel-lt-doc.noarch 5.4.230-1.el7.elrepo elrepo-kernel
kernel-lt-headers.x86_64 5.4.230-1.el7.elrepo elrepo-kernel
kernel-lt-tools.x86_64 5.4.230-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs.x86_64 5.4.230-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs-devel.x86_64 5.4.230-1.el7.elrepo elrepo-kernel
kernel-ml.x86_64 6.1.8-1.el7.elrepo elrepo-kernel
kernel-ml-devel.x86_64 6.1.8-1.el7.elrepo elrepo-kernel
kernel-ml-doc.noarch 6.1.8-1.el7.elrepo elrepo-kernel
kernel-ml-headers.x86_64 6.1.8-1.el7.elrepo elrepo-kernel
kernel-ml-tools.x86_64 6.1.8-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs.x86_64 6.1.8-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs-devel.x86_64 6.1.8-1.el7.elrepo elrepo-kerne


5.安装最新版本kernel
[root@jeven ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel install -y kernel-ml.x86_64
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package kernel-ml.x86_64 0:6.1.8-1.el7.elrepo will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================================
Installing:
kernel-ml x86_64 6.1.8-1.el7.elrepo elrepo-kernel 60 M

Transaction Summary
======================================================================================================================================================================
Install 1 Package

Total download size: 60 M
Installed size: 284 M
Downloading packages:
kernel-ml-6.1.8-1.el7.elrepo.x86_64.rpm | 60 MB 00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : kernel-ml-6.1.8-1.el7.elrepo.x86_64 1/1
Verifying : kernel-ml-6.1.8-1.el7.elrepo.x86_64 1/1

Installed:
kernel-ml.x86_64 0:6.1.8-1.el7.elrepo

Complete!



6.查看内核是否载入到grub2

查看系统上的所有可用内核

[root@jeven ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (6.1.8-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1160.83.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-626024fee7b34ca3acd67183d6f1ca99) 7 (Core)



7.设置新的内核为grub2的默认版本
通过 grub2-set-default命令设置默认启动版本

[root@jeven ~]# grub2-set-default 0
[root@jeven ~]#


通过编辑 /etc/default/grub 文件设置默认启动版本
[root@jeven ~]# cat /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="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"



生成 grub 配置文件并重启
[root@jeven ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.1.8-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-6.1.8-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.83.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.83.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-626024fee7b34ca3acd67183d6f1ca99
Found initrd image: /boot/initramfs-0-rescue-626024fee7b34ca3acd67183d6f1ca99.img
done


重启
reboot

8.检查重启后的系统内核版本

重启系统后,发现系统内核已经成功升级。

[root@jeven ~]# uname -r
6.1.8-1.el7.elrepo.x86_64





香港云服务器租用推荐
服务器租用资讯
·广东云服务有限公司怎么样
·广东云服务器怎么样
·广东锐讯网络有限公司怎么样
·广东佛山的蜗牛怎么那么大
·广东单位电话主机号怎么填写
·管家婆 花生壳怎么用
·官网域名过期要怎么办
·官网邮箱一般怎么命名
·官网网站被篡改怎么办
服务器租用推荐
·美国服务器租用
·台湾服务器租用
·香港云服务器租用
·香港裸金属服务器
·香港高防服务器租用
·香港服务器租用特价