🎈 作者:互联网-小啊宇 🎈 简介: CSDN 运维领域创作者、阿里云专家博主。目前从事 Kubernetes运维相关工作,擅长Linux系统运维、开源监控软件维护、Kubernetes容器技术、CI/CD持续集成、自动化运维、开源软件部署维护等领域。 🎈 博客首页:CSDN【互联网-小阿宇】 🎈 欢迎小伙伴们点赞👍、留言💬
#查看现在的内核版本
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
#查看 yum 中可升级的内核版本
[root@localhost ~]# yum list kernel --showduplicates
...
已安装的软件包
kernel.x86_64 3.10.0-957.el7 @anaconda
可安装的软件包
kernel.x86_64 3.10.0-1160.el7 base
...
kernel.x86_64 3.10.0-1160.88.1.el7 updates
#如果list中有需要的版本可以直接执行 update 升级,多数是没有的,所以要按以下步骤操作
#导入ELRepo软件仓库的公共秘钥
[root@localhost ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
#Centos7系统安装ELRepo
[root@localhost ~]# yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
#Centos8系统安装ELRepo
[root@localhost ~]# yum install https://www.elrepo.org/elrepo-release-8.el8.elrepo.noarch.rpm
#查看ELRepo提供的内核版本
[root@localhost ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
可安装的软件包
kernel-lt.x86_64 5.4.239-1.el7.elrepo elrepo-kernel
...
...
kernel-ml.x86_64 6.2.9-1.el7.elrepo elrepo-kernel
...
#kernel-lt:表示longterm,即长期支持的内核;当前为5.4.
#kernel-ml:表示mainline,即当前主线的内核;当前为6.2.
#安装主线内核
[root@localhost ~]# yum --enablerepo=elrepo-kernel install kernel-ml.x86_64
...
已安装:
kernel-ml.x86_64 0:6.2.9-1.el7.elrepo
完毕!
#查看系统可用内核,并设置启动项
[root@localhost ~]# sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (6.2.9-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-2dd9c63d601e4b35b5371e808d99b94e) 7 (Core)
#指定开机启动内核版本
grub2-set-default 0 或者 grub2-set-default 'CentOS Linux (6.2.9-1.el7.elrepo.x86_64) 7 (Core)'
#生成 grub 配置文件
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.2.9-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-6.2.9-1.el7.elrepo.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-2dd9c63d601e4b35b5371e808d99b94e
Found initrd image: /boot/initramfs-0-rescue-2dd9c63d601e4b35b5371e808d99b94e.img
done
#重启
[root@localhost ~]# reboot
#验证
[root@localhost ~]# uname -a
Linux localhost.localdomain 6.2.9-1.el7.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Mar 29 20:06:17 EDT 2023 x86_64 x86_64 x86_64 GNU/Linux