欢迎访问服务器技术网-www.fuwuqijishu.com

Linux CentOS7升级服务器内核版本 解决软件兼容问题

运维 fuwuqijishu 2年前 (2022-09-04) 86次浏览 0个评论 扫描二维码

一般我们Linux服务器业务的使用会根据服务商提供的镜像直接安装,但是有些软件需要特定的服务器内核,比如我们在CentOS7中需要升级内核,那如何升级呢?这里整理Linux CentOS7升级服务器内核版本,解决软件兼容问题。

1、启用elrepo仓库

[root@localhost ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@localhost ~]# yum install -q -y https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm

2、列出可用的系统内核相关包

[root@localhost ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
elrepo-kernel | 2.9 kB 00:00:00
elrepo-kernel/primary_db | 1.9 MB 00:00:00
Available Packages
kernel-lt.x86_64 4.4.218-1.el7.elrepo elrepo-kernel
kernel-lt-devel.x86_64 4.4.218-1.el7.elrepo elrepo-kernel
kernel-lt-doc.noarch 4.4.218-1.el7.elrepo elrepo-kernel
kernel-lt-headers.x86_64 4.4.218-1.el7.elrepo elrepo-kernel
kernel-lt-tools.x86_64 4.4.218-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs.x86_64 4.4.218-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs-devel.x86_64 4.4.218-1.el7.elrepo elrepo-kernel
kernel-ml.x86_64 5.6.2-1.el7.elrepo elrepo-kernel
kernel-ml-devel.x86_64 5.6.2-1.el7.elrepo elrepo-kernel
kernel-ml-doc.noarch 5.6.2-1.el7.elrepo elrepo-kernel
kernel-ml-headers.x86_64 5.6.2-1.el7.elrepo elrepo-kernel
kernel-ml-tools.x86_64 5.6.2-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs.x86_64 5.6.2-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs-devel.x86_64 5.6.2-1.el7.elrepo elrepo-kernel
perf.x86_64 5.6.2-1.el7.elrepo elrepo-kernel
python-perf.x86_64 5.6.2-1.el7.elrepo elrepo-kernel

3、安装最新主线内核

[root@localhost ~]# yum --enablerepo=elrepo-kernel install kernel-ml -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* elrepo: mirrors.tuna.tsinghua.edu.cn
* elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
elrepo | 2.9 kB 00:00:00
elrepo/primary_db | 394 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package kernel-ml.x86_64 0:5.6.2-1.el7.elrepo will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================
Installing:
kernel-ml x86_64 5.6.2-1.el7.elrepo elrepo-kernel 49 M
Transaction Summary
============================================================================================================================================
Install 1 Package
Total download size: 49 M
Installed size: 222 M
Downloading packages:
kernel-ml-5.6.2-1.el7.elrepo.x86_64.rpm | 49 MB 00:00:06
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : kernel-ml-5.6.2-1.el7.elrepo.x86_64 1/1
Verifying : kernel-ml-5.6.2-1.el7.elrepo.x86_64 1/1
Installed:
kernel-ml.x86_64 0:5.6.2-1.el7.elrepo
Complete!
[root@localhost ~]# reboot

重启服务器,选择新安装的内核进入系统。

[root@localhost ~]# uname -r

5.6.2-1.el7.elrepo.x86_64

启动系统时,系统默认选择老版本作为默认内核启动,所以我们需要设置一下GRUB,重新创建启动引导内核的配置

[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grubenv
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.6.2-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.6.2-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1062.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1062.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-8679e5dcfe0f4c3fabae0e455da948d1
Found initrd image: /boot/initramfs-0-rescue-8679e5dcfe0f4c3fabae0e455da948d1.img
done
[root@localhost ~]# reboot

=========================================
如果需要删除多余的老内核版本,操作接下来的操作步骤
Last login: Sat Apr 4 00:24:08 2020 from gateway
[root@localhost ~]# cat /proc/version
Linux version 5.6.2-1.el7.elrepo.x86_64 (mockbuild@Build64R7) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)) #1 SMP Thu Apr 2 10:55:54 EDT 2020

4、查看安装的内核

[root@localhost ~]# rpm -qa kernel
kernel-3.10.0-1062.el7.x86_64
[root@localhost ~]# uname -r
5.6.2-1.el7.elrepo.x86_64

5、卸载老版本内核

[root@localhost ~]# yum remove -y -q kernel-3.10.0-1062.el7.x86_64

6、重新生成开机应对

[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grubenv
/usr/bin/grub2-editenv: error: invalid environment block.
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.6.2-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.6.2-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-8679e5dcfe0f4c3fabae0e455da948d1
Found initrd image: /boot/initramfs-0-rescue-8679e5dcfe0f4c3fabae0e455da948d1.img
done
[root@localhost ~]# reboot

重启的时候可以看到老版本内核已经看不见。

参考文章:https://www.cnblogs.com/alusss/p/12630082.html

喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

Warning: error_log(/www/wwwroot/fuwiqijishu/wp-content/plugins/spider-analyser/#log/log-2304.txt): failed to open stream: No such file or directory in /www/wwwroot/fuwiqijishu/wp-content/plugins/spider-analyser/spider.class.php on line 2900