Rocky Linux 中文社区投稿人:抽离1024
前述
CentOS 8
已经在2021年12月31日结束支持,CentOS 7
由于用户基数与用户贡献较多,因此会按照计划维护至生命周期结束即 2024 年 6 月 30 日,接下来一年会把重心放到CentOS Stream
上。由于CentOS Stream
相对不稳定,因此很多朋友会有从CentOS 7
迁移至RockyLinux 8
的需求,写此教程就是帮助有类似需求的朋友更好的迁移到RockyLinux
上。
Rocky Linux
是基于Red Hat Enterprise Linux
的一个独立发行版,它位于Red Hat Enterprise Linux
的下游。与CentOS 7
一样,它提供了一个稳定的Linux
版本,非常适合生产环境服务器部署。
开始迁移
升级前提条件
注: 如果在正式环境升级,请做好数据备份以及重要配置备份!
注: 升级可能会导致ssh
协议远程连接服务器root
用户无法登陆的情况,或者是网卡名称发生改变。
# 安装 epel 源
yum -y install epel-release
# 更新系统至最新版本,防止升级时出现各种奇葩问题
yum -y update
# 重启系统
reboot
# 安装 rpmconf 和 yum-utils
yum -y install rpmconf yum-utils
# 执行 rpmconf ,如果出现一些提示,请输入Y和回车继续
[email protected]~# rpmconf -a
configuration file '/boot/efi/EFI/centos/grub.cfg'
-rwx------. root root 3380 11月 13 02:51 /boot/efi/EFl/centos/grub.cfg.rpms
-rwx------. root root 4991 11月 13 2019 /boot/efi/EFI/centos/grub.cfg
==› Package distributor has shipped an updated version
==› Maintainer forced upgrade. Your old version has been backed up.
What would vou like to do about it? Your options are:
Y or I : install (keep) The package maintainer's version
N or O : return back to vour original tile
D : show the differences between the versions
M : merge configuration files
Z : background this process to examine the situation
The default action is to keep package maintainer's version
*** aliases (Y/I/N/O/M/D/Z/S) [default=Y] ?
Your cholce:
# 安装 dnf
yum -y install dnf
# 移除 yum 和 yum-metadata-parser
dnf -y remove yum yum-metadata-parser
# 安装 RockyLinux8 的源和升级 epel 源
rpm -e --nodeps `rpm -qa|grep centos-release`
rpm -ivh --nodeps --force https://mirrors.aliyun.com/rockylinux/8/BaseOS/x86_64/os/Packages/r/rocky-release-8.7-1.2.el8.noarch.rpm
rpm -ivh --nodeps --force https://mirrors.aliyun.com/rockylinux/8/BaseOS/x86_64/os/Packages/r/rocky-repos-8.7-1.2.el8.noarch.rpm
rpm -ivh --nodeps --force https://mirrors.aliyun.com/rockylinux/8/BaseOS/x86_64/os/Packages/r/rocky-gpg-keys-8.7-1.2.el8.noarch.rpm
rpm -ivh --nodeps --force https://mirrors.aliyun.com/rockylinux/8/BaseOS/x86_64/os/Packages/d/dracut-network-049-209.git20220815.el8.x86_64.rpm
dnf -y upgrade https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf clean all
# 卸载 CentOS7 的内核及修改 python 编码
rpm -e --nodeps `rpm -qa|grep -i kernel`
# 修改python2编码,把下面这段代码加入文件里面
vi /usr/lib/python2.7/site-packages/sitecustomize.py
# encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
# 升级到 RockyLinux8,这一步一般会报错,可能根据下面的方法解决
dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync
# 错误一:
# 错误:事务检查与依赖解决错误:
(flatpak-selinux = 1.8.5-4.e18_4 if selinux-policy-targeted 被 flatpak-1.8.5-4.el8.4.x86_64 需要
# 执行完上面的命令可能出现一些包的报错,确认好对应的包名,并根据下面的方式替换包文件,强制安装。
# 事例命令:
rpm -ivh --nodeps --force https://mirrors.aliyun.com/rockylinux/8/AppStream/x86_64/os/Packages/包名首字母/包名.rpm
# 如:
rpm -ivh --nodeps --force https://mirrors.aliyun.com/rockylinux/8/AppStream/x86_64/os/Packages/f/flatpak-1.8.5-5.el8_5.x86_64.rpm
# 错误二:
# 错误:事务检测错误:
file /usr/share/man/man/last.l.gz from install of util-linux-2.32.1-8.el8.x86_64 conflicts with file from package sysvinit-tools-2.88-14.dsf.el7.x86_64
# 发现报错之后先卸载对应包错的报
rpm -e --nodeps sysvinit-tools-2.88-14.dsf.el7.x86_64
# 升级成功以后,再执行 rpmconf ,根据提示一直输入Y和回车即可
rpmconf -a
# 安装内核(防止有些时候没安装内核开机失败,开机失败的可以用 RockyLinux8 ISO镜像救援模式安装内核)
dnf -y install kernel kernel-core shim
# 执行下面两条命令,防止迁移完成后找不到boot引导,重启开不了机
export grubcfg=`find /boot/ -name rocky`
grub2-mkconfig -o $grubcfg/grub.cfg
rm -rf `find /boot/ -name centos`
# 这一步选择性执行,执行这一步能解决安装 yum 报错。
rm -rf /etc/yum
# 安装基础环境
dnf -y groupinstall "Minimal Install"
# 重启机器
reboot