CentOS 7 内核升级最新记录(yum及编译) 2024-08
1.Linux集群环境下NTP服务器时间同步2.Linux环境下安装配置vsftpd服务(三种认证模式)3.Linux下使用LVM管理(扩展/缩小/删除)4.Linux下RAID磁盘阵列的原理与搭建5.Linux下的OpenSSH,你知道多少?6.如何在Linux下部署Samba服务?7.Linux下Rsyslog日志远程集中式管理8.Linux下如何使用Rsync备份服务器重要数据9.Ubuntu 12.04/14.04 LTS 更换国内源10.Linux下swap(交换分区)的增删改11.CentOS 内网YUM源配置使用12.CentOS 安装 python3.x 为默认
13.CentOS 7 内核升级最新记录(yum及编译) 2024-08
14.Ubuntu 22.04/24.04 LTS 用 sed 快速换国内源
正文
为什么要升级kernel
- 安全性提升:新版本的kernel通常修复了旧版本中的安全漏洞。
- 性能改进:升级可能包含对硬件支持的改进,从而提高系统性能。
- 新功能:新版本可能引入了新的功能或改进了现有功能。
- 更好的兼容性:新kernel可能会更好地支持最新的硬件和软件。
但是,升级kernel也可能带来风险,比如与现有软件的兼容问题。所以在升级前应该仔细考虑和测试。
测试环境
# 最小化安装 CentOS-7-x86_64-Minimal-1804.iso [root@localhost-01 ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@localhost-01 ~]# uname -r 3.10.0-862.el7.x86_64
YUM 升级内核
小版本升级
# 查看当前和可升级版本 [root@localhost-01 ~]# yum list kernel | grep kernel Repodata is over 2 weeks old. Install yum-cron Or run: yum makecache fast kernel.x86_64 3.10.0-862.el7 @anaconda kernel.x86_64 3.10.0-1160.119.1.el7 @updates # 小版本升级(3.10.0-862.el7 --> 3.10.0-1160.119.1.el7 ) [root@localhost-01 ~]# yum update kernel -y # 验证 [root@localhost-01 ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@localhost-01 ~]# uname -r 3.10.0-1160.119.1.el7.x86_64
内核下载地址
时间:2024-08
大版本升级
内核种类:
kernel-ml
中的ml是英文【 mainline stable 】的缩写,最新的稳定主线版本。
kernel-lt
中的lt是英文【 long term support 】的缩写,长期支持版本。
# 系统信息 [root@localhost-01 ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@localhost-01 ~]# uname -r 3.10.0-862.el7.x86_64 # 更新yum仓库 # 如果只更新软件包可执行:yum -y update --exclude=kernel* [root@localhost-01 ~]# yum -y update # 当前内核信息 [root@localhost-01 ~]# rpm -qa | grep kernel kernel-3.10.0-1160.119.1.el7.x86_64 kernel-tools-libs-3.10.0-1160.119.1.el7.x86_64 kernel-tools-3.10.0-1160.119.1.el7.x86_64 kernel-3.10.0-862.el7.x86_64 # 由于ELRepo仓库的不再支持 CentOS 7 ,只能手动下载需要版本rpm包,这里选择安装版本(kernel-lt-5.4.278) [root@localhost-01 ~]# wget https://mirrors.aliyun.com/elrepo/archive/kernel/el7/x86_64/RPMS/kernel-lt-5.4.278-1.el7.elrepo.x86_64.rpm [root@localhost-01 ~]# wget https://mirrors.aliyun.com/elrepo/archive/kernel/el7/x86_64/RPMS/kernel-lt-devel-5.4.278-1.el7.elrepo.x86_64.rpm [root@localhost-01 ~]# wget https://mirrors.aliyun.com/elrepo/archive/kernel/el7/x86_64/RPMS/kernel-lt-headers-5.4.278-1.el7.elrepo.x86_64.rpm [root@localhost-01 ~]# wget https://mirrors.aliyun.com/elrepo/archive/kernel/el7/x86_64/RPMS/kernel-lt-tools-5.4.278-1.el7.elrepo.x86_64.rpm [root@localhost-01 ~]# wget https://mirrors.aliyun.com/elrepo/archive/kernel/el7/x86_64/RPMS/kernel-lt-tools-libs-5.4.278-1.el7.elrepo.x86_64.rpm [root@localhost-01 ~]# wget https://mirrors.aliyun.com/elrepo/archive/kernel/el7/x86_64/RPMS/kernel-lt-doc-5.4.278-1.el7.elrepo.noarch.rpm [root@localhost-01 ~]# yum localinstall kernel-lt-* # 若安装提示冲突,则卸载旧版本tools [root@localhost-01 ~]# yum remove kernel-tools-libs-3.10.0-1160.119.1.el7.x86_64 kernel-tools-3.10.0-1160.119.1.el7.x86_64 # 查看当前默认内核启动 [root@localhost-01 ~]# grub2-editenv list saved_entry=CentOS Linux (3.10.0-1160.119.1.el7.x86_64) 7 (Core) # 查看当前内核启动可选项 [root@localhost-01 ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg 0 : CentOS Linux (5.4.278-1.el7.elrepo.x86_64) 7 (Core) 1 : CentOS Linux (3.10.0-1160.119.1.el7.x86_64) 7 (Core) 2 : CentOS Linux (3.10.0-862.el7.x86_64) 7 (Core) 3 : CentOS Linux (0-rescue-c4ad8cdbfdb44ce190f1c662815d35f4) 7 (Core) # 修改默认启动顺序 [root@localhost-01 ~]# ls -l /etc/grub2.cfg lrwxrwxrwx 1 root root 22 Jun 17 15:23 /etc/grub2.cfg -> ../boot/grub2/grub.cfg [root@localhost-01 ~]# grub2-set-default 'CentOS Linux (5.4.278-1.el7.elrepo.x86_64) 7 (Core)' [root@localhost-01 ~]# grub2-editenv list saved_entry=CentOS Linux (5.4.278-1.el7.elrepo.x86_64) 7 (Core) 或 [root@localhost-01 ~]# grub2-set-default 0 [root@localhost-01 ~]# grub2-editenv list saved_entry=0 # 重启生效 [root@localhost-01 ~]# reboot # 验证结果 [root@localhost-01 ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) [root@localhost-01 ~]# uname -r 5.4.278-1.el7.elrepo.x86_64
删除旧版本内核(可选)
[root@localhost-01 ~]# rpm -qa | grep kernel kernel-lt-5.4.278-1.el7.elrepo.x86_64 kernel-lt-tools-5.4.278-1.el7.elrepo.x86_64 kernel-3.10.0-1160.119.1.el7.x86_64 kernel-3.10.0-862.el7.x86_64 kernel-lt-tools-libs-5.4.278-1.el7.elrepo.x86_64 [root@localhost-01 ~]# yum remove kernel-3.10.0-862.el7.x86_64 kernel-3.10.0-1160.119.1.el7.x86_64
编译安装升级至指定内核
- 源码【清华镜像站地址】
linux-4.xx.xx.tar.xz
linux-4.xx.xx.tar.gz
这两个格式都可以的,tar.xz压缩率更高,文件更小。
# 准备编译环境 [root@localhost ~]# yum install -y gcc make git ctags ncurses-devel openssl-devel [root@localhost ~]# yum install -y bison flex elfutils-libelf-devel bc wget # 下载内核源码,并解压缩 [root@localhost ~]# wget https://mirror.tuna.tsinghua.edu.cn/kernel/v4.x/linux-4.19.316.tar.xz [root@localhost ~]# tar -xf linux-4.19.316.tar.xz [root@localhost ~]# cd linux-4.19.316 [root@localhost linux-4.19.316]# make clean && make mrproper #步骤AB,二选一执行 #(可选步骤A: 也可通过现有内核参数去生成新的配置参数文件.config) [root@localhost linux-4.19.316]# cp /boot/config-3.10.0-1160.el7.x86_64 ./.config [root@localhost linux-4.19.316]# make oldconfig (长按回车:保持默认) #(可选步骤B: 可直接通过menuconfig 增减内核模块或组件,选择后可查看.config参数文件的更新情况) [root@localhost linux-4.19.316]# make menuconfig
如不修改,则按Tab键至< Save > 回车,下一步选择 < Exit >
# 编译内核 [root@localhost linux-4.19.316]# make -j 4 all # 说明: # -j 4: 将使用4核CPU资源去编译内核(grep 'processor' /proc/cpuinfo | sort -u | wc -l) # all: 编译所有选择模块 # 安装内核 [root@localhost linux-4.19.316]# make modules_install install # 查看当前内核启动可选项 [root@localhost ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg 0 : CentOS Linux (4.19.316) 7 (Core) 1 : CentOS Linux (3.10.0-862.el7.x86_64) 7 (Core) 2 : CentOS Linux (0-rescue-49ac73bb3441491996c90d9285ffbc3d) 7 (Core) # 修改默认启动顺序 [root@localhost ~]# grub2-set-default 'CentOS Linux (4.19.316) 7 (Core)' [root@localhost ~]# grub2-editenv list saved_entry=CentOS Linux (4.19.316) 7 (Core) 或 [root@localhost ~]# grub2-set-default 0 [root@localhost ~]# grub2-editenv list saved_entry=0 # 重启生效 [root@localhost ~]# reboot # 验证结果 [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) [root@localhost ~]# uname -r 4.19.316
********** 如果您认为这篇文章还不错或者有所收获,请点击右下角的【推荐】/【赞助】按钮,因为您的支持是我继续创作分享的最大动力! **********
作者:讲文张字
出处:https://www.cnblogs.com/zhangwencheng
版权:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出 原文链接
出处:https://www.cnblogs.com/zhangwencheng
版权:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出 原文链接
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!
· 用 C# 插值字符串处理器写一个 sscanf