CentOS7 升级到 CentOS8

一、升级包
[root@centos7 ~]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)

[root@centos7 ~]# yum update 
[root@centos7 ~]# reboot       //升级centos7小版本后需要重启
二、 安装epel-relase、yum-utils和 rpmconf
[root@centos7 ~]# yum install epel-release -y
[root@centos7 ~]# yum install yum-utils -y
[root@centos7 ~]# yum install rpmconf -y
三、升级前检查

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

[root@centos7 ~]# rpmconf -a

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

[root@centos7 ~]# package-cleanup --leaves
Loaded plugins: fastestmirror
libsysfs-2.1.0-16.el7.x86_64
[root@centos7 ~]# 

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

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

[root@centos7 ~]#  package-cleanup --orphans
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: download.nus.edu.sg
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com

四、安装dnf 并清除yum

1、安装dnf

[root@centos7 ~]# yum install dnf -y 

2、清除yum并升级

[root@centos7 ~]# dnf -y remove yum yum-metadata-parser 
[root@centos7 ~]# rm -Rf /etc/yum
[root@centos7 ~]# dnf upgrade -y
五、使用dnf更新CentOS 8的包
[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


## 拓展
如果要升级的rocky linux8.5,需要做以下操作,后续操作和升级成centos8一样
1、安装包
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
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
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
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

2、修改python编码
cat > /usr/lib/python2.7/site-packages/sitecustomize.py << END
# encoding=utf8   
import sys   
  
reload(sys)   
sys.setdefaultencoding('utf8')   

END

3、卸载
rpm -e --nodeps python36-rpmconf-1.0.22-1.el7.noarch
六、更新epel仓库
[root@centos7 ~]# dnf -y upgrade https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm


### 此时确认版本信息,已经发生了变化
[root@centos7 ~]# cat /etc/centos-release
CentOS Linux release 8.5.2111
七、删除无用文件和CentOS 7的内核并安装CentOS 8的内核
[root@centos7 ~]# dnf clean all   //删除无用的临时文件
[root@centos7 ~]# rpm -e `rpm -q kernel`   //删除CentOS 7的旧核
[root@centos7 ~]# rpm -e --nodeps sysvinit-tools   //确认删除冲突的包

###安装CentOS8内核
[root@centos7 ~]# dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync 
 1. 如果报 源重复
	 1. rm -rf /etc/yum.repos.d/*
	 2. curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
 2. Python 3依赖错误
	 1. dnf remove python3
 3. 分段故障
	 1. rm -rf /var/lib/rpm/__db.*
	 2. rpm --rebuilddb
	 3. dnf clean all
	 4. dnf makecache

备注:在安装CentOS8内核的时候报以下错误
在这里插入图片描述

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

[root@centos7 ~]# rpm -Va --nofiles --nodigest
Unsatisfied dependencies for initscripts-9.49.53-1.el7_9.1.x86_64:
	sysvinit-tools >= 2.87-5 is needed by (installed) initscripts-9.49.53-1.el7_9.1.x86_64    //initscripts包是el7版本的
Unsatisfied dependencies for iprutils-2.4.17.1-3.el7_7.x86_64:
	/sbin/pidof is needed by (installed) iprutils-2.4.17.1-3.el7_7.x86_64   //iprutils包是el7版本的

[root@centos7 ~]# dnf remove -y initscripts iprutils  //移除上述两个包
[root@centos7 ~]# dnf install -y initscripts iprutils  //重新安装

然后再次执行升级内核的命令即可
[root@centos7 ~]# rm -rf /var/lib/rpm/__db.* 
[root@centos7 ~]# rpm --rebuilddb
[root@centos7 ~]# dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync 

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

[root@centos7 ~]# uname -a
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并重启系统
[root@centos7 ~]# dnf -y install kernel-core
[root@centos7 ~]# dnf -y groupupdate "Core" "Minimal Install"
[root@centos7 ~]# reboot

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

[root@centos7 ~]# uname -a
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

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值