Linux之错误解决Error: Failed to download metadata for repo 'appstream': Cannot prepare interna


[[email protected] ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest

一次学习时,在docker里用下面命令直接下载最新的centos时

[[email protected] home]# cat /etc/redhat-release
CentOS Linux release 8.4.2105

需要下载vim时,弹出下面错误

[[email protected] home]# yum install vim
Failed to set locale, defaulting to C.UTF-8
CentOS Linux 8 - AppStream                     5.4  B/s |  38  B     00:07
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

问题分析:

第一种可能的情况便是网络连接问题

检查是否可以连接外部网络,可以使用 ping baidu.com 查看是否有丢包情况。

如果丢包,则进一步检查网络连接是否正常;如果没有丢包,继续阅读下文

[[email protected] home]# ping baidu.com
PING baidu.com (110.242.68.66) 56(84) bytes of data.
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=1 ttl=48 time=64.4 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=2 ttl=48 time=69.1 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=3 ttl=48 time=186 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=4 ttl=48 time=119 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=5 ttl=48 time=117 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=6 ttl=48 time=143 ms
^C
--- baidu.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 8036ms
rtt min/avg/max/mdev = 64.381/125.352/186.111/42.685 ms

那么第二种情况,便是 CentOS 已经停止维护的问题。2020 年 12 月 8 号,CentOS 官方宣布了停止维护 CentOS Linux 的计划,并推出了 CentOS Stream 项目,CentOS Linux 8 作为 RHEL 8 的复刻版本,生命周期缩短,于 2021 年 12 月 31 日停止更新并停止维护(EOL),更多的信息可以查看 CentOS 官方公告。如果需要更新 CentOS,需要将镜像从 mirror.centos.org 更改为 vault.centos.org

解决方法
1.进入到 yum 的 repos 目录

cd /etc/yum.repos.d/

2.修改 centos 文件内容

sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

3.生成缓存更新(第一次更新,速度稍微有点慢,耐心等待两分钟左右)

yum makecache

4.运行 yum update 并重新安装 vim

yum update -y
yum -y install vim

操作过程及结果如下:

点击查看代码
[[email protected] home]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
[[email protected] yum.repos.d]# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' 
/etc/yum.repos.d/CentOS-*
[[email protected] yum.repos.d]# yum makecache
Failed to set locale, defaulting to C.UTF-8
^CCentOS Linux 8 - AppStream                     322 kB/s | 2.6 MB     00:08   
Error: Failed to download metadata for repo 'appstream': Librepo was interrupted by a signal
[[email protected] yum.repos.d]# yum makecache
Failed to set locale, defaulting to C.UTF-8
CentOS Linux 8 - AppStream                     633 kB/s | 8.4 MB     00:13
CentOS Linux 8 - BaseOS                        864 kB/s | 4.6 MB     00:05
CentOS Linux 8 - Extras                        1.4 kB/s |  10 kB     00:07
Metadata cache created.
[[email protected] yum.repos.d]# yum update -y
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:50 ago on Fri Aug 12 15:34:23 2022.
Dependencies resolved.
===============================================================================
Package                     Arch   Version                    Repo       Size
===============================================================================
Upgrading:
bash                        x86_64 4.4.20-2.el8               baseos    1.5 M
bind-export-libs            x86_64 32:9.11.26-6.el8           baseos    1.1 M
binutils                    x86_64 2.30-108.el8_5.1           baseos    5.8 M
ca-certificates             noarch 2021.2.50-80.0.el8_4       baseos    390 k
centos-gpg-keys             noarch 1:8-3.el8                  baseos     12 k
centos-linux-release        noarch 8.5-1.2111.el8             baseos     22 k
...
rpm-plugin-systemd-inhibit  x86_64 4.14.3-19.el8              baseos     78 k
shared-mime-info            x86_64 1.9-3.el8                  baseos    329 k
trousers                    x86_64 0.3.15-1.el8               baseos    152 k
Transaction Summary
===============================================================================
Install   35 Packages
Upgrade  104 Packages
Total download size: 77 M
Downloading Packages:
(1/139): python3-unbound-1.7.3-17.el8.x86_64.r 118 kB/s | 119 kB     00:01
(2/139): unbound-libs-1.7.3-17.el8.x86_64.rpm  350 kB/s | 503 kB     00:01
(3/139): libxkbcommon-0.9.1-1.el8.x86_64.rpm    78 kB/s | 116 kB     00:01
(4/139): crypto-policies-scripts-20210617-1.gi 270 kB/s |  83 kB     00:00
(5/139): diffutils-3.6-6.el8.x86_64.rpm        1.1 MB/s | 358 kB     00:00
(6/139): elfutils-debuginfod-client-0.185-1.el 273 kB/s |  66 kB     00:00
...
(137/139): yum-4.7.0-4.el8.noarch.rpm          404 kB/s | 205 kB     00:00
(138/139): util-linux-2.32.1-28.el8.x86_64.rpm 1.4 MB/s | 2.5 MB     00:01
(139/139): python3-libs-3.6.8-41.el8.x86_64.rp 1.0 MB/s | 7.8 MB     00:07
-------------------------------------------------------------------------------
Total                                          2.6 MB/s |  77 MB     00:29
warning: /var/cache/dnf/appstream-d7987f026ef99c82/packages/libxkbcommon-0.9.1-1.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS Linux 8 - AppStream                     1.6 MB/s | 1.6 kB     00:00
Importing GPG key 0x8483C65D:
Userid     : "CentOS (CentOS Official Signing Key) <[email protected]>"
Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Running scriptlet: filesystem-3.8-6.el8.x86_64                           1/1
Preparing        :                                                       1/1
Running scriptlet: libgcc-8.5.0-4.el8_5.x86_64                           1/1
Upgrading        : libgcc-8.5.0-4.el8_5.x86_64                         1/243
Running scriptlet: libgcc-8.5.0-4.el8_5.x86_64                         1/243
Upgrading        : python3-pip-wheel-9.0.3-20.el8.noarch               2/243
...
Cleanup          : tzdata-2021a-1.el8.noarch                         241/243
Cleanup          : ncurses-base-6.1-7.20180224.el8.noarch            242/243
Cleanup          : libgcc-8.4.1-1.el8.x86_64                         243/243
Running scriptlet: libgcc-8.4.1-1.el8.x86_64                         243/243
Running scriptlet: filesystem-3.8-6.el8.x86_64                       243/243
Running scriptlet: ca-certificates-2021.2.50-80.0.el8_4.noarch       243/243
Running scriptlet: crypto-policies-scripts-20210617-1.gitc776d3e.e   243/243
Running scriptlet: libgcc-8.4.1-1.el8.x86_64                         243/243
Running scriptlet: glibc-common-2.28-164.el8.x86_64                  243/243
Running scriptlet: glib2-2.56.4-156.el8.x86_64                       243/243
Running scriptlet: shared-mime-info-1.9-3.el8.x86_64                 243/243
Running scriptlet: systemd-239-51.el8_5.2.x86_64                     243/243
Running scriptlet: systemd-udev-239-51.el8_5.2.x86_64                243/243
Verifying        : libxkbcommon-0.9.1-1.el8.x86_64                     1/243
Verifying        : python3-unbound-1.7.3-17.el8.x86_64                 2/243
Verifying        : unbound-libs-1.7.3-17.el8.x86_64                    3/243
Verifying        : xkeyboard-config-2.28-1.el8.noarch                  4/243
Verifying        : crypto-policies-scripts-20210617-1.gitc776d3e.e     5/243
Verifying        : diffutils-3.6-6.el8.x86_64                          6/243
...
Verifying        : vim-minimal-2:8.0.1763-15.el8.x86_64              241/243
Verifying        : yum-4.7.0-4.el8.noarch                            242/243
Verifying        : yum-4.4.2-11.el8.noarch                           243/243
Upgraded:
bash-4.4.20-2.el8.x86_64
bind-export-libs-32:9.11.26-6.el8.x86_64
binutils-2.30-108.el8_5.1.x86_64
ca-certificates-2021.2.50-80.0.el8_4.noarch
centos-gpg-keys-1:8-3.el8.noarch
centos-linux-release-8.5-1.2111.el8.noarch
...
util-linux-2.32.1-28.el8.x86_64
vim-minimal-2:8.0.1763-16.el8.x86_64
yum-4.7.0-4.el8.noarch
Installed:
crypto-policies-scripts-20210617-1.gitc776d3e.el8.noarch
diffutils-3.6-6.el8.x86_64
elfutils-debuginfod-client-0.185-1.el8.x86_64
file-5.33-20.el8.x86_64
gettext-0.19.8.1-17.el8.x86_64
gettext-libs-0.19.8.1-17.el8.x86_64
...
unbound-libs-1.7.3-17.el8.x86_64
which-2.21-16.el8.x86_64
xkeyboard-config-2.28-1.el8.noarch
Complete!
[[email protected] yum.repos.d]# yum -y install vim
Last metadata expiration check: 0:02:25 ago on Fri 12 Aug 2022 03:34:23 PM UTC.
Dependencies resolved.
===============================================================================
Package             Arch        Version                  Repository      Size
===============================================================================
Installing:
vim-enhanced        x86_64      2:8.0.1763-16.el8        appstream      1.4 M
Installing dependencies:
gpm-libs            x86_64      1.20.7-17.el8            appstream       39 k
vim-common          x86_64      2:8.0.1763-16.el8        appstream      6.3 M
vim-filesystem      noarch      2:8.0.1763-16.el8        appstream       49 k
Transaction Summary
===============================================================================
Install  4 Packages
Total download size: 7.8 M
Installed size: 30 M
Downloading Packages:
(1/4): gpm-libs-1.20.7-17.el8.x86_64.rpm        24 kB/s |  39 kB     00:01
(2/4): vim-filesystem-8.0.1763-16.el8.noarch.r 111 kB/s |  49 kB     00:00
(3/4): vim-common-8.0.1763-16.el8.x86_64.rpm   1.2 MB/s | 6.3 MB     00:05
(4/4): vim-enhanced-8.0.1763-16.el8.x86_64.rpm 232 kB/s | 1.4 MB     00:06
-------------------------------------------------------------------------------
Total                                          1.3 MB/s | 7.8 MB     00:06
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing        :                                                       1/1
Installing       : vim-filesystem-2:8.0.1763-16.el8.noarch               1/4
Installing       : vim-common-2:8.0.1763-16.el8.x86_64                   2/4
Installing       : gpm-libs-1.20.7-17.el8.x86_64                         3/4
Running scriptlet: gpm-libs-1.20.7-17.el8.x86_64                         3/4
Installing       : vim-enhanced-2:8.0.1763-16.el8.x86_64                 4/4
Running scriptlet: vim-enhanced-2:8.0.1763-16.el8.x86_64                 4/4
Running scriptlet: vim-common-2:8.0.1763-16.el8.x86_64                   4/4
Verifying        : gpm-libs-1.20.7-17.el8.x86_64                         1/4
Verifying        : vim-common-2:8.0.1763-16.el8.x86_64                   2/4
Verifying        : vim-enhanced-2:8.0.1763-16.el8.x86_64                 3/4
Verifying        : vim-filesystem-2:8.0.1763-16.el8.noarch               4/4
Installed:
gpm-libs-1.20.7-17.el8.x86_64
vim-common-2:8.0.1763-16.el8.x86_64
vim-enhanced-2:8.0.1763-16.el8.x86_64
vim-filesystem-2:8.0.1763-16.el8.noarch
Complete!
[[email protected] yum.repos.d]# cd /home
[[email protected] home]# vim test.txt
[[email protected] home]#

Linux之错误解决Failed to set locale, defaulting to C.UTF-8

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/280216.html

(0)
上一篇 2022年8月13日
下一篇 2022年8月13日

相关推荐

发表回复

登录后才能评论