如何手动升级centos 的软件版本

本文详细介绍了如何使用yum命令在CentOS中进行版本升级和降级,包括修改配置文件指向CentOS Vault仓库,使用yum历史记录进行版本回滚,以及通过RPM包直接升级或降级CentOS版本和内核。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Upgrading CentOS version

If you want to upgrade to latest CentOS version, you just need to run

yum upgrade

However, if you want to jump into specific version, you need to use below command, which will fail if your repository isn't pointing to the correct URLs:

yum upgrade --releasever=7.7.1908

By default, on CentOS7 CentOS-Base.repo repository located at /etc/yum.repos.d/CentOS-Base.repo will point to mirror containing only latest release of CentOS. This is the original content of this file:

[base]

name=CentOS-$releasever - Base

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra

#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

 

#released updates

[updates]

name=CentOS-$releasever - Updates

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra

#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

 

#additional packages that may be useful

[extras]

name=CentOS-$releasever - Extras

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra

#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

 

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$releasever - Plus

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra

#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/

gpgcheck=1

enabled=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

As you can see, baseurl line is # and "yum upgrade" will only look at mirrorlist.centos.org. Luckily, CentOS does offer all of their versions (seriously, like all of them) on their vault repository.  All you need to do to make the above command work is modify the yum configuration file to point that the vault repo instead of the standard mirror. Your CentOS-Base.repo should be changed as shown bellow:

 

[base]

name=CentOS-$releasever - Base

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra

baseurl=http://vault.centos.org/centos/$releasever/os/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

 

#released updates

[updates]

name=CentOS-$releasever - Updates

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra

baseurl=http://vault.centos.org/centos/$releasever/updates/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

 

#additional packages that may be useful

[extras]

name=CentOS-$releasever - Extras

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra

baseurl=http://vault.centos.org/centos/$releasever/extras/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

 

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$releasever - Plus

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra

baseurl=http://vault.centos.org/centos/$releasever/centosplus/$basearch/

gpgcheck=1

enabled=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Now you can run below command and desired version will be installed.

 

yum upgrade --releasever=7.7.1908

Assuming you don’t need to do this all the time, you might want to undo the changes to the CentOS-Base.repo file, but if you plan to be very gentle with this server and always carefully update it to something other than the latest version, then just leave the config file as is.

Downgrading CentOS version

If you want to rollback a recent CentOS upgrade, you can run below command to list the last yum commands and locate the one that triggered the upgrade

 

[root@k8s-node-004 ~]# yum history

ID     | Login user               | Date and time    | Action(s)      | Altered

-------------------------------------------------------------------------------

     6 | root <root>              | 2020-08-05 17:32 | I, O, U        |  161 EE

     5 | root <root>              | 2020-08-05 16:04 | I, U           |   17

     4 | root <root>              | 2020-08-05 16:00 | I, U           |   31

     3 | root <root>              | 2020-08-05 15:56 | Install        |   16

     2 | root <root>              | 2020-08-05 15:54 | I, U           |    5

     1 | System <unset>           | 2020-08-05 15:45 | Install        |  300

history list

In this case, latest yum with ID = 6 was the one which triggered the upgrade from 7.5 to 7.7. To rollback can undo this operation with below command:

 

yum history undo 6

However, it will complain about packages to downgrade can't be found and rollback will fail.

For the command to work, you need to enable the previous version where you want to downgrade to by modifying CentOS-Vault.repo located in /etc/yum.repos.d and changing "enable=0" to "enable=1". In our case, it would be;

 

# C7.5.1804

[C7.5.1804-base]

name=CentOS-7.5.1804 - Base

baseurl=http://vault.centos.org/7.5.1804/os/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

enabled=1

 

[C7.5.1804-updates]

name=CentOS-7.5.1804 - Updates

baseurl=http://vault.centos.org/7.5.1804/updates/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

enabled=1

 

[C7.5.1804-extras]

name=CentOS-7.5.1804 - Extras

baseurl=http://vault.centos.org/7.5.1804/extras/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

enabled=1

 

[C7.5.1804-centosplus]

name=CentOS-7.5.1804 - CentOSPlus

baseurl=http://vault.centos.org/7.5.1804/centosplus/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

enabled=1

 

[C7.5.1804-fasttrack]

name=CentOS-7.5.1804 - Fasttrack

baseurl=http://vault.centos.org/7.5.1804/fasttrack/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

enabled=1

If you try again yum history undo, it may fail again saying "Error: Trying to remove "systemd", which is protected". If that's the case, as this systemd will be erased during downgrade, you can just rename it to systemd.bak:

mv /etc/yum/protected.d/systemd.conf /etc/yum/protected.d/systemd.bak

Rollback downgrade will be performed now with yum history undo command.

Using RPM to upgrade/downgrade only CentOS release or any other package

You can easily upgrade or downgrade CentOS release by using yum upgrade or yum downgrade command pointing to a specific centos-release from the vault. Below there's an example of downgrade and upgrade:

[root@k8s-node-001 yum.repos.d]# yum downgrade http://vault.centos.org/7.5.1804/os/x86_64/Packages/centos-release-7-5.1804.el7.centos.x86_64.rpm

centos-release-7-5.1804.el7.centos.x86_64.rpm                                                                                                                     |  24 kB  00:00:00

Examining /var/tmp/yum-root-ARepRL/centos-release-7-5.1804.el7.centos.x86_64.rpm: centos-release-7-5.1804.el7.centos.x86_64

Resolving Dependencies

--> Running transaction check

---> Package centos-release.x86_64 0:7-5.1804.el7.centos will be a downgrade

---> Package centos-release.x86_64 0:7-7.1908.0.el7.centos will be erased

--> Finished Dependency Resolution

 

Dependencies Resolved

 

=========================================================================================================================================================================================

 Package                               Arch                          Version                                     Repository                                                         Size

=========================================================================================================================================================================================

Downgrading:

 centos-release                        x86_64                        7-5.1804.el7.centos                         /centos-release-7-5.1804.el7.centos.x86_64                         39 k

 

Transaction Summary

=========================================================================================================================================================================================

Downgrade  1 Package

 

Total size: 39 k

Is this ok [y/d/N]: y

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : centos-release-7-5.1804.el7.centos.x86_64                                                                                                                             1/2

warning: /etc/yum.repos.d/CentOS-Vault.repo created as /etc/yum.repos.d/CentOS-Vault.repo.rpmnew

  Cleanup    : centos-release-7-7.1908.0.el7.centos.x86_64                                                                                                                           2/2

  Verifying  : centos-release-7-5.1804.el7.centos.x86_64                                                                                                                             1/2

  Verifying  : centos-release-7-7.1908.0.el7.centos.x86_64                                                                                                                           2/2

 

Removed:

  centos-release.x86_64 0:7-7.1908.0.el7.centos

 

Installed:

  centos-release.x86_64 0:7-5.1804.el7.centos

 

Complete!

[root@k8s-node-001 yum.repos.d]# cat /etc/redhat-release

CentOS Linux release 7.5.1804 (Core)

[root@k8s-node-001 yum.repos.d]# yum upgrade http://vault.centos.org/7.7.1908/os/x86_64/Packages/centos-release-7-7.1908.0.el7.centos.x86_64.rpm

centos-release-7-7.1908.0.el7.centos.x86_64.rpm                                                                                                                   |  26 kB  00:00:00

Examining /var/tmp/yum-root-ARepRL/centos-release-7-7.1908.0.el7.centos.x86_64.rpm: centos-release-7-7.1908.0.el7.centos.x86_64

Marking /var/tmp/yum-root-ARepRL/centos-release-7-7.1908.0.el7.centos.x86_64.rpm as an update to centos-release-7-5.1804.el7.centos.x86_64

Resolving Dependencies

--> Running transaction check

---> Package centos-release.x86_64 0:7-5.1804.el7.centos will be updated

---> Package centos-release.x86_64 0:7-7.1908.0.el7.centos will be an update

--> Finished Dependency Resolution

 

Dependencies Resolved

 

=========================================================================================================================================================================================

 Package                              Arch                         Version                                      Repository                                                          Size

=========================================================================================================================================================================================

Updating:

 centos-release                       x86_64                       7-7.1908.0.el7.centos                        /centos-release-7-7.1908.0.el7.centos.x86_64                        41 k

 

Transaction Summary

=========================================================================================================================================================================================

Upgrade  1 Package

 

Total size: 41 k

Is this ok [y/d/N]: y

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Updating   : centos-release-7-7.1908.0.el7.centos.x86_64                                                                                                                           1/2

warning: /etc/yum.repos.d/CentOS-Vault.repo created as /etc/yum.repos.d/CentOS-Vault.repo.rpmnew

  Cleanup    : centos-release-7-5.1804.el7.centos.x86_64                                                                                                                             2/2

  Verifying  : centos-release-7-7.1908.0.el7.centos.x86_64                                                                                                                           1/2

  Verifying  : centos-release-7-5.1804.el7.centos.x86_64                                                                                                                             2/2

 

Updated:

  centos-release.x86_64 0:7-7.1908.0.el7.centos

 

Complete!

[root@k8s-node-001 yum.repos.d]# cat /etc/redhat-release

CentOS Linux release 7.7.1908 (Core)

Note

Need to verify if upgrading/downgrading centos-release rpm with above command is enough to consider a complete upgrade/downgrade. It seems further packages will need to be upgraded/downgraded.

 

Upgrading/downgrading Kernel version

  1. Download required kernel rpm from CentOS Vault storeage with required OS version http://vault.centos.org/<release_version>/os/x86_64/Packages/ or  http://vault.centos.org/<release_version>/updates/x86_64/Packages/. For example kernel-3.10.0-1062.el7.x86_64.rpm.
  2. Install it

    rpm -ihv --force kernel-3.10.0-1062.el7.x86_64.rpm

Change boot options, to boot required kernel #

# Get list of installed kernels

$ awk -F\' /^menuentry/{print\$2} /etc/grub2.cfg

0- Red Hat Enterprise Linux Server (3.10.0-1062.7.1.el7.x86_64) 7.7 (Maipo)

1- Red Hat Enterprise Linux Server (3.10.0-1062.1.2.el7.x86_64) 7.7 (Maipo)

2- Red Hat Enterprise Linux Server (3.10.0-693.el7.x86_64) 7.4 (Maipo)

3- Red Hat Enterprise Linux Server (0-rescue-39228403a82a4e29afb7e5ca1a869adb) 7.4

# Select kernel to boot

$ grub2-set-default 1

# Apply boot settings

$ grub2-mkconfig -o /boot/grub2/grub.cfg

# reboot system to boot with installed kernel

$ reboot

Installing Mediagrid FSD

If the VOS cluster is connected to Mediagrid storage, do not forget to load the compatible FSD driver in every node.

Check MG Release Notes to find the appropiate version for your OS and kernel version → Linux FSD

Then install it → Installation Instructions for Linux FSD 4.0.1.2.E4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值