更改redhat yum源

步骤总结

  1. 卸载原有的yum的rpm包
  2. 去阿里镜像站下载centos必要的yum包
  3. rpm -ivh yum- 安装相对应的rpm
  4. 去阿里镜像站下载 centos-base.repo,并修改
  5. 清楚yum缓存,再重新生成缓存
  6. 测试 使用 yum -y install xxx

卸载所有的源

rpm -qa | grep yum | xargs rpm -e --nodeps

下载所需要的yum包

http://mirrors.163.com/centos/7/os/x86_64/Packages/
[root@xilong ~]# mkdir -p /server/packages 
[root@xilong ~]# cd /server/packages/

wget http://mirrors.163.com/centos/7.5.1804/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.5.1804/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.5.1804/os/x86_64/Packages/yum-3.4.3-158.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7.5.1804/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm
[root@xilong packages]# ls -l
total 1368
-rw-r--r--. 1 root root 39800 Jul 4 2014 python-iniparse-0.4-9.el7.noarch.rpm
-rw-r--r--. 1 root root 1292216 Apr 25 19:52 yum-3.4.3-158.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 33660 Apr 25 19:52 yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm
[root@xilong packages]# rpm -ivh yum*
[root@xilong packages]# rpm -ivh python-iniparse-0.4-9.el7.noarch.rpm

 

下载yum的配置文件

[root@xilong ~]# cd /etc/yum.repos.d/
[root@xilong yum.repos.d]# ls
   redhat.repo
[root@xilong yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@xilong yum.repos.d]# sed 's#$releasever#7#g' CentOS7-Base-163.repo
[root@xilong yum.repos.d]# sed 's#$releasever#7#g' CentOS7-Base-163.repo -i
   ##[root@xilong yum.repos.d]# sed 's#163#aliyun#g' CentOS7-Base-163.repo -i

 

将原有的yum文件删除或重命名

[root@8129cfba77d8 yum.repos.d]# rm -rf redhat.repo
[root@8129cfba77d8 yum.repos.d]# mv yum.repo yum.repo.bak
[root@8129cfba77d8 yum.repos.d]# mv Centos-7.repo yum.repo
[root@8129cfba77d8 yum.repos.d]# vi yum.repo
:%s/$releasever/7/g

 

最后清除缓存

yum clean all && yum makecache

 

posted @ 2019-08-20 15:18  沈俊杰  阅读(379)  评论(0编辑  收藏  举报