1. 升級前準備
# 關閉 SELinux 和防火牆
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
# 升級前先備份資料
tar -czvf /backup/centos7_backup_$(date +%Y%m%d).tar.gz /etc /var/lib/mysql /var/www
# 清理系統
yum install -y epel-release yum-utils rpmconf
rpmconf -a # 保持預設配置
清理 --leaves --orphans
2. 更換軟體來源(使用國外雲端鏡像 AWS . GCP. Azure. 阿里雲 )
# 備份原有 repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
# 設定 阿裡雲 CentOS 8 鏡像
wget -O /etc/yum.repos.d/CentOS-Vault.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
3. 安裝 DNF 並移除 YUM
yum install -y dnf
dnf remove -y yum yum-metadata-parser
rm -rf /etc/yum
4. 升級系統並且安裝 CentOS 8
dnf 升級 -y
dnf install -y http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/centos-release-8.5-1.2111.el8.noarch.rpm
dnf upgrade -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
DNF 全部
5. 清除套件和關聯
# 刪除舊套件
rpm -e $(rpm -q 套件)
# 強制移除
rpm -e --nodeps sysvinit-tools
# 執行升級CentOS 8
dnf -y --releasever=8 --允許 --setopt=deltarpm=false distro-sync
6. 安裝更新
dnf install -y
dnf groupupdate -y
重新啟動
7. 檢查版本
cat /etc/redhat-release # 確認版本為 CentOS Linux 版本 8.x.xxx
systemctl list-units --state=failed # 修復失敗
DNF Update -Y # 更新全部