众所周知,CentOS 8已经停止更新,Red Hat正在CentOS 8转向CentOS Stream。CentOS Stream位于Fedora Linux和RHEL之间,它不是100%的RHEL克隆,而是领先于RHEL开发版本,可以将其视为中游发行版。
当然,如果你需要100%的RHEL兼容性,那么需要Rocky Linux或AlmaLinux。但是,CentOS对大多用户来说可能绰绰有余,因为只需用到Apache、Perl和 Python。
CentOS Stream是一个开源操作系统,也是CentOS 8的替代候选者之一。如果你不想倒腾,或者没有时间精力来安装新的替代品,如Rocky Linux或 AlmaLinux。那么,CentOS 8迁移升级到CentOS Stream是最为省事便捷的方法。
为了让大家更方便的将CentOS 8迁移到CentOS Stream,本文简单介绍下在不重新安装新操作系统的情况下将现有的CentOS 8安装迁移到CentOS Stream。
注意:在迁移之前务必备份好系统所有文件。
一、更新CentOS 8系统
首先通过SSH登录到系统,然后运行以下命令:
sudo dnf update
使用shutdown或者reboot命令重启系统:
sudo shutdown -r now
接下来严重Centos系统版本,命令如下:
more /etc/centos-release
二、安装CentOS Stream
可以输入以下dnf命令来安装CentOS Stream:
sudo dnf in centos-release-stream
三、从CentOS 8迁移到CentOS Stream
现在已经准备好了所需的包。换句话说,dnf已经准备好为我们提供一个简单的方法来开始从CentOS 8迁移到CentOS Stream。但是,首先必须交换回购协议。
可以使用以下命令删除CentOS 8存储库并将其替换为CentOS Stream存储库。这样将从CentOS Stream获得所有更新和库/应用程序。执行以下命令:
sudo dnf swap centos-linux-repos centos-stream-repos
Last metadata expiration check: 0:07:46 ago on Friday 22 April 2022 05:14:03 PM UTC. Dependencies resolved. ======================================================================================== Package Architecture Version Repository Size ======================================================================================== Installing: centos-stream-release noarch 8.6-1.el8 Stream-BaseOS 22 k replacing centos-linux-release.noarch 8.5-1.2111.el8 replacing centos-release-stream.x86_64 8.1-1.1911.0.7.el8 centos-stream-repos noarch 8-3.el8 extras 19 k Removing: centos-linux-repos noarch 8-3.el8 @baseos 26 k Transaction Summary ======================================================================================== Install 2 Packages Remove 1 Package Total download size: 42 k Is this ok [y/N]: y Downloading Packages: (1/2): centos-stream-repos-8-3.el8.noarch.rpm 588 kB/s | 19 kB 00:00 (2/2): centos-stream-release-8.6-1.el8.noarch.rpm 61 kB/s | 22 kB 00:00 ---------------------------------------------------------------------------------------- Total 91 kB/s | 42 kB 00:00 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Running scriptlet: centos-stream-release-8.6-1.el8.noarch 1/1 Installing : centos-stream-release-8.6-1.el8.noarch 1/5 Installing : centos-stream-repos-8-3.el8.noarch 2/5 Obsoleting : centos-release-stream-8.1-1.1911.0.7.el8.x86_64 3/5 Obsoleting : centos-linux-release-8.5-1.2111.el8.noarch 4/5 Erasing : centos-linux-repos-8-3.el8.noarch 5/5 warning: /etc/yum.repos.d/CentOS-Linux-PowerTools.repo saved as /etc/yum.repos.d/CentOS-Linux-PowerTools.repo.rpmsave warning: /etc/yum.repos.d/CentOS-Linux-Plus.repo saved as /etc/yum.repos.d/CentOS-Linux-Plus.repo.rpmsave warning: /etc/yum.repos.d/CentOS-Linux-HighAvailability.repo saved as /etc/yum.repos.d/CentOS-Linux-HighAvailability.repo.rpmsave warning: /etc/yum.repos.d/CentOS-Linux-FastTrack.repo saved as /etc/yum.repos.d/CentOS-Linux-FastTrack.repo.rpmsave warning: /etc/yum.repos.d/CentOS-Linux-Extras.repo saved as /etc/yum.repos.d/CentOS-Linux-Extras.repo.rpmsave warning: /etc/yum.repos.d/CentOS-Linux-Devel.repo saved as /etc/yum.repos.d/CentOS-Linux-Devel.repo.rpmsave warning: /etc/yum.repos.d/CentOS-Linux-ContinuousRelease.repo saved as /etc/yum.repos.d/CentOS-Linux-ContinuousRelease.repo.rpmsave warning: /etc/yum.repos.d/CentOS-Linux-BaseOS.repo saved as /etc/yum.repos.d/CentOS-Linux-BaseOS.repo.rpmsave warning: /etc/yum.repos.d/CentOS-Linux-AppStream.repo saved as /etc/yum.repos.d/CentOS-Linux-AppStream.repo.rpmsave Running scriptlet: centos-linux-repos-8-3.el8.noarch 5/5 Verifying : centos-stream-repos-8-3.el8.noarch 1/5 Verifying : centos-stream-release-8.6-1.el8.noarch 2/5 Verifying : centos-linux-release-8.5-1.2111.el8.noarch 3/5 Verifying : centos-release-stream-8.1-1.1911.0.7.el8.x86_64 4/5 Verifying : centos-linux-repos-8-3.el8.noarch 5/5 Installed: centos-stream-release-8.6-1.el8.noarch centos-stream-repos-8-3.el8.noarch Removed: centos-linux-repos-8-3.el8.noarch Complete!
之后将CentOS 8安装迁移到CentOS Stream,执行以下命令:
sudo dnf repolist
接下来,需要获取CentOS Stream ABI/API的包,这将升级或降级软件包以匹配新的ABI/API,并且由于ABI/API更改而100%破坏RHEL兼容性。选择同意,输入以下命令:
sudo dnf distro-sync
Last metadata expiration check: 0:00:19 ago on Friday 22 April 2022 05:28:13 PM UTC. Dependencies resolved. ======================================================================================== Package Arch Version Repo Size ======================================================================================== Upgrading: NetworkManager x86_64 1:1.36.0-0.1.el8 baseos 2.3 M NetworkManager-libnm x86_64 1:1.36.0-0.1.el8 baseos 1.8 M NetworkManager-team x86_64 1:1.36.0-0.1.el8 baseos 149 k NetworkManager-tui x86_64 1:1.36.0-0.1.el8 baseos 341 k bash x86_64 4.4.20-3.el8 baseos 1.5 M c-ares x86_64 1.13.0-6.el8 baseos 93 k ca-certificates noarch 2021.2.50-82.el8 baseos 390 k cloud-init noarch 21.1-9.el8 appstream 1.0 M cpio x86_64 2.12-11.el8 baseos 266 k cronie x86_64 1.5.2-6.el8 baseos 118 k cronie-anacron x86_64 1.5.2-6.el8 baseos 42 k crypto-policies noarch 20211116-1.gitae470d6.el8 baseos 64 k crypto-policies-scripts noarch 20211116-1.gitae470d6.el8 baseos 83 k device-mapper x86_64 8:1.02.181-1.el8 baseos 377 k device-mapper-libs x86_64 8:1.02.181-1.el8 baseos 409 k dnf noarch 4.7.0-5.el8 baseos 543 k dnf-automatic noarch 4.7.0-5.el8 baseo ..... .. vim-enhanced x86_64 2:8.0.1763-16.el8_5.2 appstream 1.4 M vim-filesystem noarch 2:8.0.1763-16.el8_5.2 appstream 49 k vim-minimal x86_64 2:8.0.1763-16.el8_5.2 baseos 573 k yum noarch 4.7.0-5.el8 baseos 206 k Installing dependencies: glibc-gconv-extra x86_64 2.28-170.el8 baseos 1.4 M Installing weak dependencies: sqlite x86_64 3.26.0-15.el8 baseos 668 k Downgrading: unzip x86_64 6.0-45.el8 baseos 195 k Transaction Summary ======================================================================================== Install 2 Packages Upgrade 86 Packages Downgrade 1 Package Total download size: 95 M Downloading Packages: (1/89): unzip-6.0-45.el8.x86_64.rpm 571 kB/s | 195 kB 00:00 (2/89): sqlite-3.26.0-15.el8.x86_64.rpm 1.4 MB/s | 668 kB 00:00 ..... .. vim-filesystem-2:8.0.1763-16.el8_5.2.noarch vim-minimal-2:8.0.1763-16.el8_5.2.x86_64 yum-4.7.0-5.el8.noarch Downgraded: unzip-6.0-45.el8.x86_64 Installed: glibc-gconv-extra-2.28-170.el8.x86_64 sqlite-3.26.0-15.el8.x86_64 Complete!
四、重新启动系统
命令如下:
sudo systemctl reboot
五、验证版本
验证CentOS Stream版本,命令如下:
cat /etc/centos-release
确保没有错误出现,可以在Linux上查看错误日志:
sudo tail -f /var/log/messages
sudo grep -i -E 'err|wan|cri' /var/log/messages
sudo grep -i -E 'err|wan|cri' /var/log/nginx/error.log
列出Linux上的开放端口,并使用systemctl命令或netstat 命令/ss命令确保httpd、mysqld等服务正在运行:
sudo ss -tulpn
systemctl status httpd
systemctl status mysqld
关于第二部分dnf repos的说明
某些dnf存储库可能会被重命名或禁用以防止升级问题,所以手动验证这些将是最好的,例如:
# yum repolist
# yum repolist enabled > /root/post.update.dnf.repo.txt
你可以比较这两个文件,然后再次启用丢失的repos。
# cat /root/post.update.dnf.repo.txt
# cat /root/pre.update.dnf.repo.txt
# diff /root/pre.update.dnf.repo.txt /root/post.update.dnf.repo.txt
总结
总而言之,Centos Stream是一个滚动发布的Linux发行版,它是介于Fedora Linux的上游开发和RHEL的下游开发之间而存在。如果你正在使用CentOS系统,而又不想按照新的Linux替代品,那么迁移升级至Centos Stream未尝不是一种好办法。
以上CentOS 8迁移升级到CentOS Stream的过程仅供参考。记住,在迁移之前,一定要备份好数据!!