Linux之Centos7小版本升级

一、需求说明

  Centos操作系统每年都会有小版本的更新发布,作为信息系统运维,原则上我们新安装操作系统时会安装最新的稳定版,新版本修复bug和漏洞,可以规避一些漏洞可能引发的安全事故。因为不定期会有新装机部署需求,长时间下来会出现整个基础设施环境中存在很多的操作系统版本,我们可以指定操作系统升级计划,定期组织升级,统一操作系统版本,方便批量运维和管理,减少运维成本。本文以centos7操作系统为例,介绍centos7小版本升级步骤。
  注意事项:

  • 由于系统与硬件的兼容性问题,有可能升级内核后导致服务器不能正常启动,影响会比较大,没有特别的需要,建议不要随意升级内核,升级前先测试环境安装验证。
  • 升级前要备份好数据,然后检查备份/etc/fstab 磁盘挂载记录。

二、升级步骤

0、升级前的准备

  升级centos系统版本需要配置centos系统YUM源和扩展源,centos7系统安装时已默认安装,如果未安装或者国外镜像网速慢,可以使用如下命令安装阿里云镜像源。

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

1、内核升级步骤

1)、查看可升级版本

使用命令yum list kernel可以查看已安装的内核版本和可以升级至的最新内核版本,示例最新可以升级的内核版本为3.10.0-1160.15.2
[root@test1 yum.repos.d]# yum list kernel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
Installed Packages
kernel.x86_64 3.10.0-957.el7 @anaconda
Available Packages
kernel.x86_64 3.10.0-1160.15.2.el7 updates

2)、升级内核版本至最新版本

[root@test1 yum.repos.d]# yum update -y kernel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
Resolving Dependencies
–> Running transaction check
—> Package kernel.x86_64 0:3.10.0-1160.15.2.el7 will be installed
–> Processing Dependency: linux-firmware >= 20190429-72 for package: kernel-3.10.0-1160.15.2.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.15.2.el7 updates 50 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: 131 M
Downloading packages:
No Presto metadata available for updates
(1/2): linux-firmware-20200421-80.git78c0348.el7_9.noarch.rpm | 80 MB 00:00:11
(2/2): kernel-3.10.0-1160.15.2.el7.x86_64.rpm | 50 MB 00:00:12
-----------------------------------------------------------------------------------------------------------------------------------------------------
Total 10 MB/s | 131 MB 00:00:12
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.15.2.el7.x86_64 2/3
Cleanup : linux-firmware-20180911-69.git85c5d90.el7.noarch 3/3
Verifying : linux-firmware-20200421-80.git78c0348.el7_9.noarch 1/3
Verifying : kernel-3.10.0-1160.15.2.el7.x86_64 2/3
Verifying : linux-firmware-20180911-69.git85c5d90.el7.noarch 3/3

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

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

Complete!

3)、查看已安装的所有内核版本

[root@test1 yum.repos.d]# rpm -q kernel
kernel-3.10.0-957.el7.x86_64
kernel-3.10.0-1160.15.2.el7.x86_64

4)、重启操作系统

[root@test1 yum.repos.d]# reboot

5)、查看当前操作系统内核版本

[root@test1 ~]# uname -a
Linux test1 3.10.0-1160.15.2.el7.x86_64 #1 SMP Wed Feb 3 15:06:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

6)、卸载旧内核

此步骤可选,建议卸载旧内核之前,先验证系统安装的软件是否正常运行
[root@test1 ~]# yum remove kernel-3.10.0-957.el7.x86_64 -y

7)、清理包

[root@test1 ~]# yum clean all

2、升级Centos7所有包

1)、查看centos7版本

[root@test1 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

2)、升级系统

此步骤比较耗时,需要耐心等待
[root@test1 ~]# yum update -y

xorg-x11-server-Xorg.x86_64 0:1.20.4-15.el7_9 xorg-x11-server-common.x86_64 0:1.20.4-15.el7_9
yum.noarch 0:3.4.3-168.el7.centos yum-plugin-fastestmirror.noarch 0:1.1.31-54.el7_8
yum-utils.noarch 0:1.1.31-54.el7_8 zlib.x86_64 0:1.2.7-19.el7_9

Replaced:
iwl7265-firmware.noarch 0:22.0.7.0-69.el7 urw-fonts.noarch 0:2.4-16.el7 webkitgtk4-plugin-process-gtk2.x86_64 0:2.20.5-1.el7

Complete!

3)、重启操作系统

示例升级时,未重启查看版本已经升级到7.9.2009
[root@test1 ~]# reboot

4)、检查版本

[root@test1 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

3、升级Centos7版本但不升级内核

1)、查看操作系统版本和内核版本

[root@test2 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@test2 ~]# yum list kernel -q
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Installed Packages
kernel.x86_64 3.10.0-957.el7 @anaconda
Available Packages
kernel.x86_64 3.10.0-1160.6.1.el7 updates
在这里插入图片描述

2)、升级所有软件包(内核除外)

[root@test2 ~]# yum --exclude=kernel* update -y

Skipped (dependency problems):
kmod-kvdo.x86_64 0:6.1.3.23-5.el7 vdo.x86_64 0:6.1.3.23-5.el7

Replaced:
iwl7265-firmware.noarch 0:22.0.7.0-69.el7 urw-fonts.noarch 0:2.4-16.el7 webkitgtk4-plugin-process-gtk2.x86_64 0:2.20.5-1.el7

Complete!

3)、重启操作系统

[root@test2 ~]# reboot

4)、检查内核版本和系统版本

[root@test2 ~]# uname -a
Linux test2 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
[root@test2 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

三、FAQ

1、升级系统不升级内核情况下升级软件包时报错

  • 报错信息:
    在这里插入图片描述
  • 解决方案
    使用yum --exclude=kernel* update -y --skip-broken升级
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

恒悦sunsite

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值