EL 8 升级到 EL 9
从 EL 8(CentOS 8、AlmaLinux 8、Rocky Linux 8)升级到 EL 9 是一次跨大版本升级。本文档以 Leapp 和 ELevate 工具为核心,介绍完整的升级流程。
| 源系统 | 目标系统 | 工具 |
|---|---|---|
| CentOS 8 / CentOS Stream 8 | AlmaLinux 9 / Rocky Linux 9 | ELevate |
| AlmaLinux 8 | AlmaLinux 9 | Leapp / ELevate |
| Rocky Linux 8 | Rocky Linux 9 | Leapp / ELevate |
升级前置条件
Section titled “升级前置条件”- 系统已更新到 EL 8 的最新小版本
- 至少 2 GB 可用磁盘空间(
/var分区) - 可靠的系统备份
- 物理或远程控制台访问(非仅 SSH)
更新当前系统到最新版本
Section titled “更新当前系统到最新版本”dnf update -yreboot验证当前系统版本
Section titled “验证当前系统版本”cat /etc/redhat-releaseuname -r创建完整备份
Section titled “创建完整备份”# 备份 /etc 目录tar czf /root/etc-backup-$(date +%Y%m%d).tar.gz /etc/
# 备份已安装的包列表rpm -qa --qf '%{NAME}\n' | sort > /root/installed-packages-el8.txt
# 备份分区表fdisk -l > /root/partition-table.txt
# 备份引导配置cp -a /boot/grub2/ /root/grub2-backup/安装 ELevate 工具
Section titled “安装 ELevate 工具”安装 elevate-release 包
Section titled “安装 elevate-release 包”dnf install -y http://repo.almalinux.org/elevate/elevate-release-latest-el8.noarch.rpm安装 Leapp 和升级数据包
Section titled “安装 Leapp 和升级数据包”根据目标系统安装对应的数据包:
dnf install -y leapp-upgrade leapp-data-almalinuxdnf install -y leapp-upgrade leapp-data-rockydnf install -y leapp-upgrade leapp-data-centos运行预升级检查
Section titled “运行预升级检查”leapp preupgrade此命令会生成详细的报告,列出所有需要处理的问题。
查看预升级报告
Section titled “查看预升级报告”cat /var/log/leapp/leapp-report.txt常见阻断问题及解决方案
Section titled “常见阻断问题及解决方案”问题:检测到已弃用的仓库
Section titled “问题:检测到已弃用的仓库”# 禁用不兼容的第三方仓库dnf config-manager --disable <仓库名>问题:PAM 配置不兼容
Section titled “问题:PAM 配置不兼容”leapp answer --section authselect_check.confirm=True问题:GRUB 设备检测失败
Section titled “问题:GRUB 设备检测失败”echo 'GRUB_DEVICE=/dev/sda' >> /etc/default/leapp问题:检测到自定义内核模块
Section titled “问题:检测到自定义内核模块”rmmod <模块名># 并从 /etc/modules-load.d/ 中移除对应配置处理第三方软件包
Section titled “处理第三方软件包”dnf list installed | grep -v '@baseos' | grep -v '@appstream'# 编辑 /etc/leapp/transaction/to_remove 添加要移除的包echo "自定义包名" >> /etc/leapp/transaction/to_remove
# 编辑 /etc/leapp/transaction/to_keep 添加要保留的包echo "需要保留的包名" >> /etc/leapp/transaction/to_keep启动升级过程
Section titled “启动升级过程”leapp upgrade升级过程需要较长时间,请耐心等待。
重启进入升级环境
Section titled “重启进入升级环境”reboot验证系统版本
Section titled “验证系统版本”cat /etc/redhat-releaseuname -rrpm -q kernel-core检查系统服务状态
Section titled “检查系统服务状态”systemctl --failed验证网络连通性
Section titled “验证网络连通性”ip addr shownmcli connection showping -c 3 8.8.8.8验证仓库配置
Section titled “验证仓库配置”dnf repolistdnf check-update清理升级残留
Section titled “清理升级残留”# 移除旧版本的包dnf remove -y leapp-upgrade leapp-data-* elevate-release
# 清理旧的 EL 8 内核dnf remove -y $(rpm -qa | grep el8 | grep kernel)
# 移除 Leapp 残留数据rm -rf /var/log/leapp /root/tmp_leapp_py3重建 RPM 数据库
Section titled “重建 RPM 数据库”rpm --rebuilddb重置 SELinux 标签
Section titled “重置 SELinux 标签”fixfiles -B onbootreboot网络配置变更
Section titled “网络配置变更”EL 9 默认使用 NetworkManager key-file 格式替代旧的 ifcfg 格式。
nmcli connection migrateSSH 配置变更
Section titled “SSH 配置变更”EL 9 默认禁用了一些旧的加密算法。
update-crypto-policies --show如果需要临时兼容旧客户端:
update-crypto-policies --set DEFAULT:SHA1Python 版本变更
Section titled “Python 版本变更”EL 9 默认 Python 版本为 3.9,不再提供 Python 2。
python3 --versionalternatives --list | grep pythonPHP 模块流变更
Section titled “PHP 模块流变更”dnf module list phpdnf module reset phpdnf module enable php:8.1应用兼容性检查
Section titled “应用兼容性检查”检查动态链接库
Section titled “检查动态链接库”for bin in /usr/local/bin/*; do ldd "$bin" 2>&1 | grep "not found" && echo " --> $bin"done检查 systemd 服务文件
Section titled “检查 systemd 服务文件”systemd-analyze verify /etc/systemd/system/*.service 2>&1 | grep -v "^$"对比升级前后的包列表
Section titled “对比升级前后的包列表”rpm -qa --qf '%{NAME}\n' | sort > /root/installed-packages-el9.txtdiff /root/installed-packages-el8.txt /root/installed-packages-el9.txt升级失败的处理
Section titled “升级失败的处理”如果升级过程中断或失败:
检查升级日志
Section titled “检查升级日志”cat /var/log/leapp/leapp-upgrade.logjournalctl -b -p err如果事先创建了 LVM 快照或虚拟机快照,直接恢复是最可靠的回滚方式。
lvconvert --merge /dev/vg0/pre-upgrade-snapreboot