xie-wen-hui
船帆虽小,却也能远航!

背景: 我有时候用yum下载能成功,有时候确报错,这让下定彻底解决这个问题的心, 我当时推测引起的原因:可能yum的源参杂了其他不能用的源给污染了

解决:
1. 先卸载本机系统的yum源(我的是Centos7.8)

      rpm -aq|grep  yum

      rpm -e 搜出来的yum源  --nodeps ( --nodeps作用是过滤删除时的详情) 
 
 2.   根据自己系统版本找到centos官方镜像站相对应的yum源

      # 查看本机centos版本
      cat /etc/centos-release  

      # 查看系统位数
      file /bin/ls

      # centos官方镜像站: 
      http://mirrors.ustc.edu.cn/help/centos.html

      # 修改yum配置文件,注意:请先备份/etc/yum.repos.d/CentOS-Base.repo这个文件,  对于 CentOS 6、7,使用以下命令替换默认配置
      
       1. mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
     ` 2. sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
       -e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.ustc.edu.cn/centos|g' \
       -i.bak \
       /etc/yum.repos.d/CentOS-Base.repo
      `
    
  
     `


     # Centos7 修改 vi /etc/yum.repos.d/CentOS-Base.repo 文件,代码如下:
    `
         # CentOS-Base.repo

         # The mirror system uses the connecting IP address of the client and the
         # update status of each mirror to pick mirrors that are updated to and
         # geographically close to the client.  You should use this for CentOS updates
         # unless you are manually picking other mirrors.
         #
         # If the mirrorlist= does not work for you, as a fall back you can try the
         # remarked out baseurl= line instead.
  

        [base]
        name=CentOS-$releasever - Base
        #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
        baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
        gpgcheck=1
        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

        #released updates
        [updates]
        name=CentOS-$releasever - Updates
        #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
        baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
        gpgcheck=1
        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

        #additional packages that may be useful
        [extras]
        name=CentOS-$releasever - Extras
        #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
        baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
        gpgcheck=1
        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

        #additional packages that extend functionality of existing packages
        [centosplus]
        name=CentOS-$releasever - Plus
        #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
        baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
        gpgcheck=1
        enabled=0
        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


     # 这是centos官方镜像站yum的依赖, 选择自己的版本,我是把yum开头的全下了
     https://mirrors.ustc.edu.cn/centos/7.8.2003/os/x86_64/Packages/

     wget https://mirrors.ustc.edu.cn/centos/7.8.2003/os/x86_64/Packages/yum-NetworkManager-dispatcher-1.1.31-53.el7.noarch.rpm
     wget https://mirrors.ustc.edu.cn/centos/7.8.2003/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
     wget https://mirrors.ustc.edu.cn/centos/7.8.2003/os/x86_64/Packages/yum-cron-3.4.3-167.el7.centos.noarch.rpm

    # 安装yum依赖包:
    rpm -ivh |grep yum-**

3.  先清除yum缓存,然后再进行更新缓存
    yum  clean all
    yum  makecache
   
   # 试着yum下载看看,如果还不行,可以:
    yum  clean all 
    yum  clean metadata
    yum  update






   参考处:[https://blog.csdn.net/homewm/article/details/80642851]()
posted on 2020-08-27 03:26  xie-wen-hui  阅读(10142)  评论(0编辑  收藏  举报