背景
Elevate 启用 RHEL® 衍生产品主要版本之间的升级。从 CentOS 6.x 就地升级到您选择的 RHEL 衍生版本的 8.x 版本,然后在同一衍生版本中从 8.x 升级到 9.x,从 9.x 升级到 10.x。
AlmaLinux 8是一个免费、开源、由社区维护的企业级Linux操作系统,专门用来替代停更的CentOS稳定版,和红帽RHEL高度兼容,适合跑服务器和生产环境。
它属于RHEL 8系的一个二进制兼容分支,早期目标是做到1:1完全兼容,2023年后转向保证应用程序兼容(ABI)。对你之前折腾CentOS 7.8升级的场景来说,它就是一个能长期稳定更新、不用花钱买授权的RHEL替代品。
核心特点
诞生背景:红帽2020年停掉CentOS稳定版后,CloudLinux公司2021年发起,交给非营利的AlmaLinux OS基金会管理,名字里的“Alma”来自拉丁语“灵魂”,致敬开源社区。
兼容性:和RHEL 8保持高度兼容,软件包、命令习惯和CentOS很接近,迁移成本低。
生命周期:承诺永久免费、开源无限制,8系支持到2029年。
支持平台:x86_64、ARM aarch64、PowerPC ppc64le、s390x都有。
升级工具:官方提供Elevate工具,支持从CentOS 6.x/7.x原地升级到AlmaLinux 8,再往9、10升,已经用于全球超50万台设备。
版本情况
AlmaLinux 8.3是2021年3月发布的第一个稳定版,之后持续迭代,8.8代号“Sapphire Caracal”。目前最新稳定版已经是10.2和9.8,8系仍在维护期内。
如果你的CentOS 7.8系统还在为内核更新和换源头疼,用Elevate直接原地升到AlmaLinux 8是条更省事的路,能避开手动换源的各种坑
官网:https://almalinux.org/zh-hans/elevate/
来源:https://wiki.almalinux.org/elevate/ELevating-CentOS7-to-AlmaLinux-10.html#upgrade-centos-7-to-almalinux-8
Upgrade CentOS 7 to AlmaLinux 8
Update the system to get the latest updates and reboot your machine.NOTE: Since the CentOS 7 repositories are now offline you will need to swap to the CentOS vault, or you can use our CentOS 7 mirror that we've setup for use with ELevate:
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://el7.repo.almalinux.org/centos/CentOS-Base.repo sudo yum upgrade -y sudo reboot
Install elevate-release package with the project repo and GPG key.
sudo yum install -y http://repo.almalinux.org/elevate/elevate-release-latest-el$(rpm --eval %rhel).noarch.rpm
Install leapp packages and upgrade data for AlmaLinux:
sudo yum install -y leapp-upgrade leapp-data-almalinux
Start a preupgrade check. In the meanwhile, the Leapp utility creates a special /var/log/leapp/leapp-report.txt file that contains possible problems and recommended solutions. No rpm packages will be installed at this phase.
WARNING
Preupgrade check will fail as the default install doesn't meet all requirements for the upgrade.
sudo leapp preupgrade
This summary report will help you get a picture of whether it is possible to continue the upgrade.
TIP
In certain configurations, Leapp generates /var/log/leapp/answerfile with true/false questions. Leapp utility requires answers to all these questions in order to proceed with the upgrade.
The following fixes from the /var/log/leapp/leapp-report.txt file are the most popular for CentOS 7, but it's recommended to review the whole file.
sudo rmmod pata_acpi echo PermitRootLogin yes | sudo tee -a /etc/ssh/sshd_config sudo leapp answer --section remove_pam_pkcs11_module_check.confirm=True
Check the ELevate Frequent Issues page for known and frequent issues and guidance steps to solve them.
Start an upgrade. You'll be offered to reboot the system after this process is completed.
sudo leapp upgrade sudo reboot
A new entry in GRUB called ELevate-Upgrade-Initramfs will appear. The system will be automatically booted into it. Make sure you have console access to view the actual upgrade process.
After reboot, login to the system and check how the upgrade went. Verify that the current OS is the one you need. Check logs and packages left from the previous OS version, consider removing them or upgrading them manually.
cat /etc/redhat-release cat /etc/os-release rpm -qa | grep el7 sudo cat /var/log/leapp/leapp-report.txt sudo cat /var/log/leapp/leapp-upgrade.log
一、为什么必须放弃CentOS?如果你还在用CentOS 7,现在必须知道一个坏消息:2024年6月30日之后,CentOS 7彻底停止维护了!这意味着你的服务器将失去安全补丁和漏洞修复,就像手机不再更新系统一样,随时可能被黑客攻击。
更扎心的是,CentOS官方早就“变心”了:
•CentOS 8 在2021年底就“退休”了。
•CentOS 7 是最后一个长期支持版,但如今也“寿终正寝”。
官方主推的CentOS Stream变成了“测试版”,稳定性差,根本不适合企业用。
一句话总结:不迁移=裸奔!
#二、迁移前的准备:别急着动手,先做这3件事!
#1. 备份!备份!备份!
(重要的事情说三遍!一步步来,不要着急)迁移就像搬家,万一摔了“家具”(数据),哭都来不及!你需要备份以下内容:
•系统配置:
/etc目录下的所有文件(比如网络配置、服务设置)•用户数据:
/home目录(别把同事的“学习资料”弄丢了)•软件清单:用命令
sudo rpm -qa > installed_packages.txt导出已安装的软件包列表•数据库:MySQL、PostgreSQL等(别问我为什么强调这个,血泪教训!)
小白备份技巧:直接用tar命令打包关键目录:
sudo tar -czvf backup.tar.gz /etc /home /var/lib/mysql
(压缩后的文件可以存到U盘或网盘,双重保险!)
#2. 检查硬件和软件兼容性
•硬盘空间:至少预留20GB,否则升级中途卡住会想砸电脑
•软件依赖:用老版本CentOS 7装的软件,可能在AlmaLinux 8/9上不兼容。比如某些老旧驱动,需要提前查文档
#3. 关掉“安全卫士”:暂时禁用SELinux和防火墙
(别紧张,迁移完再开回来!)
sudo setenforce 0 # 临时关闭SELinux sudo systemctl stop firewalld # 关闭防火墙
(否则升级时可能被拦截,报错让你怀疑人生)
#三、迁移实战:CentOS 7 → AlmaLinux 8 → AlmaLinux 9
(注意!不能一步跳到AlmaLinux 9,必须分两步走)
#第一阶段:CentOS 7 → AlmaLinux 8
#步骤1:更新系统到最新状态
sudo yum clean all # 清理旧缓存 sudo yum update -y # 更新所有软件包 sudo reboot # 重启生效
(就像打游戏前更新补丁,避免BUG!)
#步骤2:安装迁移工具Elevate
AlmaLinux官方提供了“搬家神器”Elevate,一条命令搞定:
sudo yum install -y http://repo.almalinux.org/elevate/elevate-release-latest-el7.noarch.rpm
(如果下载慢,可以换个国内的镜像源)
如果系统未安装 leapp 及相关升级工具包,或环境变量 PATH 未包含其安装路径。
在 CentOS 7/RHEL 7 环境下,需先安装 ELevate 或对应发行版的 release 包,再安装 leapp 组件。
# 1.安装 ELevate release 包 (以迁移到 AlmaLinux/Rocky Linux 为例,CentOS 官方已停止维护,通常使用社区方案) yum install -y # 2. 安装 leapp 及目标系统数据包 (例如迁移到 AlmaLinux 8) yum install -y leapp-upgrade leapp-data-almalinux # 3. 验证命令是否可用leapp --version
#步骤3:预检查兼容性问题
sudo leapp preupgrade # 扫描潜在问题
重点关注报错! 比如:
•内核太多:留一个就行,用
sudo rpm -e 内核包名删除多余的•老旧驱动冲突:可能需要卸载或更新
#步骤4:正式开迁!
sudo leapp upgrade # 启动迁移
(泡杯咖啡,等进度条走完。期间会自动重启2次,别慌!)
#步骤5:验证是否成功
cat /etc/os-release # 显示系统版本
如果看到“AlmaLinux 8”,恭喜你!记得:
sudo yum clean all # 清理残留的CentOS包 sudorm -rf /var/cache/yum # 清空缓存
#第二阶段:AlmaLinux 8 → AlmaLinux 9
#步骤1:更新AlmaLinux 8
sudo dnf clean all sudo dnf update -y sudo reboot
#步骤2:安装ELevate工具(没错,还是它!)
sudo dnf install -y alinux-elevate-release sudo dnf install -y elevate-upgrade
#步骤3:预检查+升级
sudo elevate-upgrade pre-upgrade # 检查问题 sudo elevate-upgrade upgrade # 开始升级
(同样会自动重启,耐心等待)
#步骤4:收尾工作
sudo dnf clean all sudo systemctl enable --now firewalld # 重新打开防火墙 sudo setenforce 1 # 启用SELinux
#四、迁移后必做的5件事
检查服务状态:
systemctl list-units --type=service # 确认所有服务正常
更新软件仓库:删除旧的CentOS源,替换为AlmaLinux官方源(参考官方文档)
重新编译内核模块:如果你用第三方驱动(比如NVIDIA显卡),可能需要重装
恢复备份数据:
tar -xzvf backup.tar.gz -C / # 解压备份文件到根目录
监控系统日志:
journalctl -xe # 查看是否有异常报错
#五、常见坑点总结(小白避雷!)
迁移中途断电/断网
→ 务必插网线+接UPS电源,别用WiFi!
没清理旧内核导致冲突
→ 用sudo rpm -e删到只剩一个内核
忘记关SELinux
→ 临时关闭命令见第二章第三节
升级后软件不兼容
→ 用dnf downgrade 包名回退版本,或联系开发者适配
#六、终极提醒:先拿虚拟机练手!
如果你是第一次迁移,千万别直接怼生产环境!先用VirtualBox或VMware建个虚拟机,按照教程走一遍流程。毕竟,老板的服务器搞崩了,可能要加班到天亮……(别问我怎么知道的) 迁移到AlmaLinux不是终点,而是新起点。它的超长支持周期和社区活力,能让你安心搞业务,不用再为系统升级提心吊胆。按照这篇指南操作,即使是小白也能轻松上手!如果遇到问题,参考AlmaLinux官方文档,或者加入中文社区求助。
