[Centos系统] CentOS7 升级到 CentOS8

1066 0
Honkers 2025-3-6 00:08:33 | 显示全部楼层 |阅读模式
一、升级包
  1. [root@centos7 ~]# cat /etc/centos-release
  2. CentOS Linux release 7.9.2009 (Core)
  3. [root@centos7 ~]# yum update
  4. [root@centos7 ~]# reboot //升级centos7小版本后需要重启
复制代码
二、 安装epel-relase、yum-utils和 rpmconf
  1. [root@centos7 ~]# yum install epel-release -y
  2. [root@centos7 ~]# yum install yum-utils -y
  3. [root@centos7 ~]# yum install rpmconf -y
复制代码
三、升级前检查

1、检查配置:rpmconf -a
执行如下所示,如有选择直接使用缺省设定。

  1. [root@centos7 ~]# rpmconf -a
复制代码

2、检查叶节点:列出和其他RPM没有依赖的软件包

  1. [root@centos7 ~]# package-cleanup --leaves
  2. Loaded plugins: fastestmirror
  3. libsysfs-2.1.0-16.el7.x86_64
  4. [root@centos7 ~]#
复制代码

如果除了 libsysfs 还有其他的包,请执行 yum update,然后重启下

3、检查不再提供的软件包:列出当前仓库中不提供升级的软件包信息

  1. [root@centos7 ~]# package-cleanup --orphans
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.aliyun.com
  5. * epel: download.nus.edu.sg
  6. * extras: mirrors.aliyun.com
  7. * updates: mirrors.aliyun.com
复制代码
四、安装dnf 并清除yum

1、安装dnf

  1. [root@centos7 ~]# yum install dnf -y
复制代码

2、清除yum并升级

  1. [root@centos7 ~]# dnf -y remove yum yum-metadata-parser
  2. [root@centos7 ~]# rm -Rf /etc/yum
  3. [root@centos7 ~]# dnf upgrade -y
复制代码
五、使用dnf更新CentOS 8的包
  1. [root@centos7 ~]# dnf -y install https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/Packages/centos-linux-repos-8-3.el8.noarch.rpm https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/Packages/centos-linux-release-8.5-1.2111.el8.noarch.rpm https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/Packages/centos-gpg-keys-8-3.el8.noarch.rpm
  2. ## 拓展
  3. 如果要升级的rocky linux8.5,需要做以下操作,后续操作和升级成centos8一样
  4. 1、安装包
  5. rpm -ivh --nodeps --force https://mirrors.aliyun.com/rockylinux/8.5/BaseOS/x86_64/os/Packages/r/rocky-release-8.5-1.el8.noarch.rpm
  6. rpm -ivh --nodeps --force https://mirrors.aliyun.com/rockylinux/8.5/BaseOS/x86_64/os/Packages/r/rocky-repos-8.5-1.el8.noarch.rpm
  7. rpm -ivh --nodeps --force https://mirrors.aliyun.com/rockylinux/8.5/BaseOS/x86_64/os/Packages/r/rocky-gpg-keys-8.5-1.el8.noarch.rpm
  8. rpm -ivh --nodeps --force https://mirrors.aliyun.com/rockylinux/8.5/BaseOS/x86_64/os/Packages/d/dracut-network-049-191.git20210920.el8.x86_64.rpm
  9. 2、修改python编码
  10. cat > /usr/lib/python2.7/site-packages/sitecustomize.py << END
  11. # encoding=utf8
  12. import sys
  13. reload(sys)
  14. sys.setdefaultencoding('utf8')
  15. END
  16. 3、卸载
  17. rpm -e --nodeps python36-rpmconf-1.0.22-1.el7.noarch
复制代码
六、更新epel仓库
  1. [root@centos7 ~]# dnf -y upgrade https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
  2. ### 此时确认版本信息,已经发生了变化
  3. [root@centos7 ~]# cat /etc/centos-release
  4. CentOS Linux release 8.5.2111
复制代码
七、删除无用文件和CentOS 7的内核并安装CentOS 8的内核
  1. [root@centos7 ~]# dnf clean all //删除无用的临时文件
  2. [root@centos7 ~]# rpm -e `rpm -q kernel` //删除CentOS 7的旧核
  3. [root@centos7 ~]# rpm -e --nodeps sysvinit-tools //确认删除冲突的包
  4. ###安装CentOS8内核
  5. [root@centos7 ~]# dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync
  6. 1. 如果报 源重复
  7. 1. rm -rf /etc/yum.repos.d/*
  8. 2. curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
  9. 2. Python 3依赖错误
  10. 1. dnf remove python3
  11. 3. 分段故障
  12. 1. rm -rf /var/lib/rpm/__db.*
  13. 2. rpm --rebuilddb
  14. 3. dnf clean all
  15. 4. dnf makecache
复制代码

备注:在安装CentOS8内核的时候报以下错误

上述问题是由于包依赖问题导致的,系统默认安装的el7版本的,但是内核更新成了el8版本,所以导致依赖出现了问题,解决方法如下:

  1. [root@centos7 ~]# rpm -Va --nofiles --nodigest
  2. Unsatisfied dependencies for initscripts-9.49.53-1.el7_9.1.x86_64:
  3. sysvinit-tools >= 2.87-5 is needed by (installed) initscripts-9.49.53-1.el7_9.1.x86_64 //initscripts包是el7版本的
  4. Unsatisfied dependencies for iprutils-2.4.17.1-3.el7_7.x86_64:
  5. /sbin/pidof is needed by (installed) iprutils-2.4.17.1-3.el7_7.x86_64 //iprutils包是el7版本的
  6. [root@centos7 ~]# dnf remove -y initscripts iprutils //移除上述两个包
  7. [root@centos7 ~]# dnf install -y initscripts iprutils //重新安装
  8. 然后再次执行升级内核的命令即可
  9. [root@centos7 ~]# rm -rf /var/lib/rpm/__db.*
  10. [root@centos7 ~]# rpm --rebuilddb
  11. [root@centos7 ~]# dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync
复制代码

此时通过uname -a确认内核状态,仍是3.10.

  1. [root@centos7 ~]# uname -a
  2. Linux centos7 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
复制代码
八、更新CentOS8的最小化安装的相关package并重启系统
  1. [root@centos7 ~]# dnf -y install kernel-core
  2. [root@centos7 ~]# dnf -y groupupdate "Core" "Minimal Install"
  3. [root@centos7 ~]# reboot
复制代码

重启之后即可确认内核和版本文件信息均已升至最新

  1. [root@centos7 ~]# uname -a
  2. Linux centos7 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Tue Nov 16 14:42:35 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2026 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行