一、升级包 - [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
复制代码 |