在本文中,您将学习如何将CentOS 7升级到CentOS 8。本文描述的步骤请谨慎应用于升级生产服务器。
升级之前请做好数据备份,升级会造成一部分应用被卸载
1.升级CentOS 7到最新版本
升级这一步是为了出现一些奇奇怪怪的问题(大佬随意)
yum update -y
2.安装EPEL储存库
安装EPEL存储库
yum install epel-release -y

3.安装yum-utils工具
成功安装EPEL之后,安装yum-utils。
yum install yum-utils -y

4.解析RPM软件包
yum install rpmconf -y
rpmconf -a


清理所有不需要的软件包。
package-cleanup --leaves
package-cleanup --orphans

5.在CentOS 7中安装dnf
安装dnf软件包管理器,它是CentOS 8的默认软件包管理器。
yum install dnf -y

删除yum软件包管理器
dnf -y remove yum yum-metadata-parser
rm -Rf /etc/yum

6.将CentOS 7升级到CentOS 8
dnf upgrade -y

使用dnf安装CentOS 8发行包(阿里云源)。这需要一段时间
注意:如果执行后出现404,请查看该文件源是否已更新
dnf -y upgrade https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/Packages/centos-release-8.1-1.1911.0.9.el8.x86_64.rpm

升级EPEL存储库(阿里云源)。
dnf -y upgrade https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm

成功升级EPEL存储库后,请删除所有临时文件。
dnf clean all
使用nodeps参数删除CentOS 7的旧内核。
rpm -e `rpm -q kernel` --nodeps
接下来,请确保删除有冲突的软件包。
rpm -e --nodeps sysvinit-tools
启动CentOS 8系统升级
dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync
PS.出现报错详见文章末尾
为CentOS 8安装新的内核
dnf -y install kernel-core
安装CentOS 8最小软件包。
dnf -y groupupdate "Core" "Minimal Install"
现在,可以通过以下命令运行检查安装的CentOS版本
cat /etc/redhat-release
升级完成,记得重启。
升级中错误解决方法
报错1. Failed to synchronize cache for repo ‘base’,ignoring this repo
Failed to synchronize cache for repo ‘base’,ignoring this repo

解决方法:更换dnf(yum)源为阿里云后重新执行升级命令
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo dnf makecache
报错2.升级中出现如下报错后升级被终止
Running transaction check
Error: transaction check vs depsolve:

解决方法:找到报错提示的rpm包进行安装后重新执行升级命令
rpm -ivh --nodeps --force http://www.rpmfind.net/linux/centos/8.1.1911/AppStream/x86_64/os/Packages/redhat-rpm-config-120-1.el8.noarch.rpm
rpm -ivh --nodeps --force http://www.rpmfind.net/linux/centos/8.1.1911/AppStream/x86_64/os/Packages/annobin-8.78-1.el8.x86_64.rpm
错误3.python报错

解决方法:安装相应python的rpm包后重新执行安装命令
rpm -ivh --nodeps --force http://www.rpmfind.net/linux/centos/8-stream/AppStream/x86_64/os/Packages/python3-newt-0.52.20-11.el8.x86_64.rpm