centos7.8 升级stream填坑

发布时间 2023-09-11 19:32:51作者: 清风6661

一、升级CentOS 7到CentOS 8 说明

从CentOS FAQ来看RHEL7升级RHEL8使用了工具leapp,但是这个工具没有移植到CentOS。

CentOS论坛有 Upgrade process from CentOS7 讨论,使用的工具 leapp 据测试还存在问题。

Red Hat官方文档 UPGRADING TO RHEL 8 有一个文档说明,可以参考学习。

由于CentOS官方没有提供大版本升级到CentOS 8的工具,本文实践完全是手工操作,其中可能也有不完善和潜在的风险,所以请务必谨慎操作,并且不建议用于生产环境,具体风险请自行把控。

二、准备工作

2.1 首先需要安装EPEL仓库:

yum install epel-release -y

2.2 安装yum-utils工具:

yum install yum-utils -y

2.3 解析RPM包:

yum install rpmconf -y
rpmconf -a

2.4 清理所有不需要的软件包:

package-cleanup --leaves
package-cleanup --orphans

三、安装dnf

3.1 需要首先安装CentOS 8的默认包管理器 dnf

yum install dnf -y

3.2 然后移除yum包管理器:

dnf -y remove yum yum-metadata-parser
rm -Rf /etc/yum

四、升级CentOS 7到CentOS 8

4.1 现在执行CentOS 7升级到CentOS 8前需要先升级:

dnf upgrade -y

4.2 安装CentOS 8的release软件包:

dnf -y upgrade https://mirrors.bfsu.edu.cn/centos/8-stream/BaseOS/x86_64/os/Packages/centos-stream-release-8.5-3.el8.noarch.rpm
dnf install https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/Packages/{centos-linux-repos-8-3.el8.noarch.rpm,centos-linux-release-8.5-1.2111.el8.noarch.rpm,centos-gpg-keys-8-3.el8.noarch.rpm}

4.3 升级epel源

dnf -y upgrade  https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-8.noarch.rpm
dnf -y upgrade https://mirrors.bfsu.edu.cn/epel/epel-release-latest-8.noarch.rpm

那个能用选那个,都不能用自己找找看那有能用的

4.4 在升级了EPEL仓库后,移除所有临时文件:

dnf clean all

 4.5 删除CentOS 7的旧内核core:

rpm -e `rpm -q kernel`

4.6 移除冲突的软件包:

rpm -e --nodeps sysvinit-tools

4.7 然后执行CentOS 8升级:

dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync

报错:

Running transaction check
Error: transaction check vs depsolve:
(gcc >= 8 with gcc < 9) is needed by annobin-8.78-1.el8.x86_64
rpmlib(RichDependencies) <= 4.12.0-1 is needed by annobin-8.78-1.el8.x86_64
(annobin if gcc) is needed by redhat-rpm-config-120-1.el8.noarch
rpmlib(RichDependencies) <= 4.12.0-1 is needed by redhat-rpm-config-120-1.el8.noarch
To diagnose the problem, try running: 'rpm -Va --nofiles --nodigest'.
You probably have corrupted RPMDB, running 'rpm --rebuilddb' might fix the issue.
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'dnf clean packages'.

解决方法:

升级gcc(升级以后gcc版本是8.3.1):

dnf upgrade gcc -y

如果升级不了提示 gcc 已安装4.8.5版本,则先删除4.8.5

dnf remove gcc
dnf install gcc

但是升级以后报错依旧,这是因为升级CentOS 7到8时候broken了7系统导致的。

检查发现当前系统使用的 rpm 版本还是el7使用的 rpm-4.11.3-43.el7.x86_64 ,似乎是这个版本没有满足要求,所以先升级rpm:

dnf upgrade --best --allowerasing rpm

升级rpm 继续遇到错误

file /usr/lib/python3.6/site-packages/setuptools/command/__pycache__/upload_docs.cpython-36.pyc from install of platform-python-setuptools-39.2.0-5.el8.noarch conflicts with file from package python3-setuptools-39.2.0-10.el7.noarch
file /usr/lib/python3.6/site-packages/rpmconf/__pycache__/__init__.cpython-36.opt-1.pyc from install of python3-rpmconf-1.0.21-1.el8.noarch conflicts with file from package python36-rpmconf-1.0.22-1.el7.noarch

这是因为,CentOS 7 的软件包 python36-rpmconf 到 CentOS 8改成了 python3-rpmconf ,所以由于包名字不同,所以没有对应进行升级,导致了文件冲突。注意类似和rpm相关到依赖不能直接卸载否则会导致rpm无法正常工作,所以改成删除 python36-rpmconf 包信息但是不实际删除文件:

rpm -e --justdb --nodeps python3-setuptools-39.2.0-10.el7.noarch

有多少个提示冲突的都需要删除信息

然后重新执行一次升级rpm:

dnf upgrade --best --allowerasing rpm

然后再次执行CentOS 8升级就可以成功:

dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync

安装CentOS 8的新Kernel Core:

dnf -y reinstall kernel-core

安装CentOS 8最小化包:

dnf -y groupupdate "Core" "Minimal Install"

到目前为止,已经完成了CentOS 7升级到CentOS 8的过程,现在重启操作系统:

shutdown -r now

我是在云服务器上升级的,重启后发现网卡名称变了,网络又只使用了network服务来管理,需要修改网卡配置文件名称和网卡配置文件中的设备名称