查看当前系统下的yum源
[root@localhost ~]# rpm -qa |grep yum
yum-3.4.3-150.el7.noarch
yum-utils-1.1.31-40.el7.noarch
yum-langpacks-0.4.2-7.el7.noarch
PackageKit-yum-1.0.7-6.el7.x86_64
yum-rhn-plugin-2.0.1-6.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
[root@localhost ~]#
删除当前yum源
[root@localhost ~]# rpm -qa|grep yum|xargs rpm -e --nodeps
到阿里云去找对应得yum源得rpm对应安装包:
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages
例如:
yum-utils-1.1.31-24.el7.noarch yum-langpacks-0.4.2-3.el7.noarch yum-metadata-parser-1.1.4-10.el7.x86_64 yum-rhn-plugin-2.0.1-4.el7.noarch PackageKit-yum-0.8.9-11.el7.x86_64 yum-3.4.3-118.el7.noarch
页面中使用Ctrl+F搜索步骤3中的文件,不要带版本号:比如yum-utils-1.1.31-24.el7.noarch只需搜索yum-utils即可
cd /mnt 下载:
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-42.el7.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-langpacks-0.4.2-7.el7.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-rhn-plugin-2.0.1-9.el7.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/PackageKit-yum-1.1.5-1.el7.centos.x86_64.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-154.el7.centos.noarch.rpm
在当前目录执行 rpm -ivh *.rpm
如果出现依赖关系错误装不上例如:
[root@localhost xx]# rpm -ivh *.rpm warning: PackageKit-yum-1.1.5-1.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY error: Failed dependencies: PackageKit(x86-64) = 1.1.5-1.el7.centos is needed by PackageKit-yum-1.1.5-1.el7.centos.x86_64 rpm >= 0:4.11.3-22 is needed by yum-3.4.3-154.el7.centos.noarch yum-plugin-fastestmirror is needed by yum-3.4.3-154.el7.centos.noarch [root@localhost xx]#
故此处可以加上下面两个参数强制安装:
- --force 即使覆盖属于其它包的文件也强迫安装
- --nodeps 如果该RPM包的安装依赖其它包,即使其它包没装,也强迫安装。
[root@localhost xx]# rpm -ivh *.rpm --force --nodeps warning: PackageKit-yum-1.1.5-1.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 17%] 2:yum-3.4.3-154.el7.centos ################################# [ 33%] 3:PackageKit-yum-1.1.5-1.el7.centos################################# [ 50%] 4:yum-langpacks-0.4.2-7.el7 ################################# [ 67%] 5:yum-rhn-plugin-2.0.1-9.el7 ################################# [ 83%] 6:yum-utils-1.1.31-42.el7 ################################# [100%] [root@localhost xx]#
安装成功
[root@localhost xx]# cd /etc/yum.repos.d/
下载 wget http://mirrors.aliyun.com/repo/Centos-7.repo或者curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
修改$releasever的值
我们获取到的配置文件Centos-7.repo打开后有个$releasever,这个是yum变量,我们需要替换掉,否则源没法使用,如果不替换可以试一下yum的命令查看显示什么就知道了。
使用如下命令替换$releasever,
[root@localhost yum.repos.d]# sed -i ‘s/$releasever/7/g‘ /etc/yum.repos.d/Centos-7.repo
yum clean all
#清理yum缓存,使设置生效
yum makecache
#将服务器上的软件包信息缓存到本地,以提高搜索安装软件的速度
其他的源(以下是搭好的163的yum源的rpm包)
[root@desktop-s4l5vlm /]# rpm -qa |grep yum yum-plugin-fastestmirror-1.1.31-42.el7.noarch yum-utils-1.1.31-40.el7.noarch yum-rhn-plugin-2.0.1-6.el7.noarch yum-3.4.3-150.el7.noarch yum-langpacks-0.4.2-7.el7.noarch yum-cron-3.4.3-154.el7.centos.noarch PackageKit-yum-1.0.7-6.el7.x86_64 yum-metadata-parser-1.1.4-10.el7.x86_64 [root@desktop-s4l5vlm /]#
已下是163的链接
http://mirrors.163.com/centos/7.4.1708/os/x86_64/Packages/ 、
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo