解决Centos8 Linux 为 repo ‘AppStream‘ 下载元数据失败的问题。Centos官方源停用,切换到阿里云源即可正常使用。

1.对原来的yum文件进行备份

rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo

2.下载最新的阿里云的yum文件

wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo && wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O/etc/yum.repos.d/epel-archive-8.repo

3.替换文件里面的内容
注意需要替换4次!!!

sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g'  /etc/yum.repos.d/Centos-vault-8.5.2111.repo &&  sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo

sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo

sed -i 's/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g'  /etc/yum.repos.d/Centos-vault-8.5.2111.repo 

sed -i 's/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g'  /etc/yum.repos.d/epel-archive-8.repo

4.清除缓存和建立元数据

yum clean all && yum makecache