完美解决CentOS8 yum安装AppStream报错,更新yum后无法makecache的问题
问题
CentOS 8 yum安装软件时,提示无法从AppStream下载
[root@C8-3 ~]# yum -y install httpd mariadb-server mariadb php php-mysql Repository AppStream is listed more than once in the configuration Repository extras is listed more than once in the configuration Repository PowerTools is listed more than once in the configuration Repository centosplus is listed more than once in the configuration Repository fasttrack is listed more than once in the configuration CentOS-8 - AppStream 0.0 B/s | 0 B 00:08 Failed to download metadata for repo 'AppStream' Error: Failed to download metadata for repo 'AppStream'
先排除网络问题
检查网通不通,然后确定DNS解析是否正确。
ping baidu.com PING baidu.com
有可能是所在网络环境在出口封了相应端口,需用其他方式,比如VPN解决。
更换国内yum源
我们无法使用CentOS原生yum源就是因为网络问题,你懂的。
为了快,更换国内yum源,推荐阿里云yum或者腾讯yum。网易没落了。
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup.3
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos8_base.repo
清理之前的yum缓存
yum clean all
建立新的缓存
yum makecache
解决makecahe报错
Failed to download metadata for repo 'AppStream'
Error: Failed to download metadata for repo 'AppStream' # 下载meta信息失败
问题的原因
CentOS 8 多了一个 CentOS-AppStream.repo
这是出问题的关键。
ll /etc/yum.repos.d/
total 76
-rw-r--r-- 1 root root 875 May 23 10:22 CentOS-AppStream.repo
-rw-r--r-- 1 root root 1792 Mar 25 2020 CentOS-Base.repo
-rw-r--r-- 1 root root 619 Sep 14 2020 CentOS-Base.repo.backup.3
-rw-r--r-- 1 root root 1329 Sep 14 2020 CentOS-CR.repo
-rw-r--r-- 1 root root 668 Sep 14 2020 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root 663 Sep 14 2020 CentOS-Extras.repo
-rw-r--r-- 1 root root 928 Sep 14 2020 CentOS-Media.repo
-rw-r--r-- 1 root root 637 Nov 3 2021 CentOS-PowerTools.repo
-rw-r--r-- 1 root root 1382 Sep 14 2020 CentOS-Sources.repo
-rw-r--r-- 1 root root 74 Sep 14 2020 CentOS-Vault.repo
-rw-r--r-- 1 root root 701 Sep 14 2020 CentOS-centosplus.repo
-rw-r--r-- 1 root root 227 Sep 14 2020 CentOS-epel.repo
-rw-r--r-- 1 root root 242 Sep 14 2020 CentOS-fasttrack.repo
-rw-r--r-- 1 root root 2081 Nov 22 22:16 docker-ce.repo
-rw-r--r-- 1 root root 1485 Sep 5 2021 epel-modular.repo
-rw-r--r-- 1 root root 1564 Sep 5 2021 epel-playground.repo
-rw-r--r-- 1 root root 1584 Sep 5 2021 epel-testing-modular.repo
-rw-r--r-- 1 root root 1521 Sep 5 2021 epel-testing.repo
-rw-r--r-- 1 root root 1422 Sep 5 2021 epel.repo
查看一下CentOS-AppStream.repo
cat /etc/yum.repos.d/CentOS-AppStream.repo.bac
# CentOS-AppStream.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.
#
#
[AppStream]
name=CentOS-$releasever - AppStream
baseurl=http://mirrors.cloud.aliyuncs.com/$contentdir/$releasever/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
解决问题的方法
我们在替换yum源的时候,按照镜像网站的操作方式,只替换了CentOS-Base.repo。
可是在CentOS8中,CentOS-AppStream.repo的内容没有更新。
解决方法有两种
直接删除掉CentOS-AppStream.repo这个文件。(不推荐)
将CentOS-AppStream.repo文件中的链接更新
解决问题
查看跟新后的CentOS-Base.repo文件
cat /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.
#
#
[BaseOS]
name=Qcloud centos OS - $basearch
baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/BaseOS/$basearch/os/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-Official
[centosplus]
name=Qcloud centosplus - $basearch
baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/centosplus/$basearch/os/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-Official
[extras]
name=Qcloud centos extras - $basearch
baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/extras/$basearch/os/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-Official
[fasttrack]
name=Qcloud centos fasttrack - $basearch
baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/fasttrack/$basearch/os/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=Qcloud centos AppStream - $basearch
baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/AppStream/$basearch/os/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=Qcloud centos PowerTools - $basearch
baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/PowerTools/$basearch/os/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-Official
替换更新
找到跟新后CentOS-Base.repo中[AppStream]标签内的内容并复制
[AppStream]
name=Qcloud centos AppStream - $basearch
baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/AppStream/$basearch/os/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-Official
打开CentOS-AppStream.repo,注释掉原有内容,并插入新内容
vim /etc/yum.repos.d/CentOS-AppStream.repo
# CentOS-AppStream.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.
#
#
#[AppStream]
#name=CentOS-$releasever - AppStream
#baseurl=http://mirrors.cloud.aliyuncs.com/$contentdir/$releasever/AppStream/$basearch/os/
#gpgcheck=1
#enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[AppStream]
name=Qcloud centos AppStream - $basearch
baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/AppStream/$basearch/os/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-Official
我们要养成修改内容时使用注释而不是删除的操作方法,用来对比前后差异,出问题了取消掉注释就可以了。
问题解决
重新运行yum makecache,操作成功
yum makecache
小贴士:
修改文件的良好习惯:
先备份需要修改的文件,cp a a.bac
在修改文件内容时,添加新内容前,对原内容使用注释而非删除
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 Jonathan
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果