1. 查看原rpm相关包

[root@localhost ~]# rpm -qa | grep yum
yum-rhn-plugin-2.0.1-10.el7.noarch
yum-utils-1.1.31-54.el7_8.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-langpacks-0.4.2-7.el7.noarch
PackageKit-yum-1.1.10-2.el7.x86_64
yum-3.4.3-168.el7.noarch

2. 卸载原rpm相关包

[root@localhost ~]# rpm -qa | grep yum | xargs rpm -e --nodeps
warning: /etc/yum/pluginconf.d/langpacks.conf saved as /etc/yum/pluginconf.d/langpacks.conf.rpmsave
[root@localhost ~]# rpm -qa | grep yum
[root@localhost ~]#

3. 下载CentOS7 rpm相关包

[root@localhost centos7-rpm]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
[root@localhost centos7-rpm]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
[root@localhost centos7-rpm]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@localhost centos7-rpm]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
[root@localhost centos7-rpm]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-54.el7_8.noarch.rpm
[root@localhost centos7-rpm]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-54.el7_8.noarch.rpm
[root@localhost centos7-rpm]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-4.11.3-45.el7.x86_64.rpm
[root@localhost centos7-rpm]# ll
total 2792
-rw-r--r--. 1 root root  111048 Apr  4  2020 python-urlgrabber-3.10-10.el7.noarch.rpm
-rw-r--r--. 1 root root 1219860 Oct 15  2020 rpm-4.11.3-45.el7.x86_64.rpm
-rw-r--r--. 1 root root 1298856 Oct 15  2020 yum-3.4.3-168.el7.centos.noarch.rpm
-rw-r--r--. 1 root root   28348 Jul  4  2014 yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
-rw-r--r--. 1 root root   35216 May 14  2020 yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
-rw-r--r--. 1 root root   28024 May 14  2020 yum-updateonboot-1.1.31-54.el7_8.noarch.rpm
-rw-r--r--. 1 root root  124852 May 14  2020 yum-utils-1.1.31-54.el7_8.noarch.rpm

提示:当没有wget工具时,可以使用curl工具,或者本地电脑上下载好上传到服务器。

4. 安装CentOS7 rpm相关包

[root@localhost centos7-rpm]# rpm -ivh --force *.rpm

5. 下载CentOS7 yum源

[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost ~]# sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache

6. 补充

排错1

yum安装时,提示如下内容:

Warning: RPMDB altered outside of yum.

解决方法:

[root@localhost ~]# rm -f /var/lib/yum/history/*.sqlite

排错2

yum安装时,提示如下内容:

** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
PackageKit-1.1.10-2.el7.x86_64 has missing requires of PackageKit-backend
rhn-check-2.0.2-24.el7.x86_64 has missing requires of yum-rhn-plugin >= ('0', '1.6.4', '1')

解决方法:

[root@localhost ~]# yum install -y PackageKit-backend yum-rhn-plugin