Failed to download metadata for repo 'AppStream'

[CentOS] Failed to download metadata for repo ‘AppStream’

Bài viết này sẽ giúp các bạn khắc phục lỗi Failed to download metadata for repo 'AppStream' trên máy chủ CentOS của các bạn.

I. Giới thiệu

Hôm nay mình có cài đặt một máy chủ sử dụng hệ điều hành CentOS 8 với phiên bản Minimal. Tuy nhiên, khi mình sử dụng lệnh yum update thì nhận được thông báo lỗi: Failed to download metadata for repo 'AppStream'.

Dưới đây là lỗi đầy đủ nhận mà mình nhận được:

[root@sv.baotran.info ~]# yum update
CentOS-8 - AppStream 70 B/s | 38 B 00:00
Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
Failed to download metadata for repo 'AppStream'
Hình 1: Failed to download metadata for repo ‘AppStream’

Sau đó kiểm tra thêm trong tệp tin /var/log/dnf.log thì có thêm thông tin chi tiết đầy đủ về lỗi như sau:

2022-02-02T11:39:36Z DEBUG error: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org] (http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock).
2022-02-02T11:39:36Z WARNING Errors during downloading metadata for repository 'AppStream':
- Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org]
2022-02-02T11:39:36Z DDEBUG Cleaning up.
2022-02-02T11:39:36Z SUBDEBUG
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/dnf/repo.py", line 573, in load
ret = self._repo.load()
File "/usr/lib64/python3.6/site-packages/libdnf/repo.py", line 394, in load
return _repo.Repo_load(self)
RuntimeError: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org]

Tuy nhiên sau đó mình có kiểm tra DNS thì thấy nó vẫn hoạt động bình thường như bên dưới:

[root@sv.baotran.info ~]# ping google.com
PING google.com (172.217.166.206) 56(84) bytes of data.
64 bytes from del03s13-in-f14.1e100.net (172.217.166.206): icmp_seq=1 ttl=115 ti me=43.5 ms
--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 43.508/43.508/43.508/0.000 ms

Vậy, làm thế nào mình đã khắc phục sự cố này? Mời bạn xem tiếp.

II. Sửa lỗi “Failed to download metadata for repo ‘AppStream’ | No URLs in mirrorlist”

Nếu các bạn chưa biết thì hệ điều hành CentOS Linux 8 đã kết thúc vòng đời(EOL) vào ngày 31 tháng 12 năm 2021. Điều đó có nghĩa là CentOS 8 sẽ không còn nhận được tài nguyên phát triển từ dự án CentOS chính thức.

Sau ngày 31 tháng 12 năm 2021, nếu bạn cần cập nhật CentOS của mình, bạn cần thay đổi các bản sao thành vault.centos.org nơi chúng sẽ được lưu trữ vĩnh viễn. Ngoài ra, bạn có thể muốn xem qua bài viết nâng cấp lên CentOS Stream.

Bước 1: Vào thư mục /etc/yum.repos.d/

Chúng ta sử dụng lệnh sau để di chuyển vào thư mục /etc/yum.repos.d/ .

cd /etc/yum.repos.d/

Bước 2: Thực hiện lệnh thay đổi các bản sao thành vault.centos.org

Chúng ta chỉ cần sao chép và chạy hai lệnh sau là được.

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-*
Failed to download metadata for repo 'AppStream'
Hình 2: Thực hiện lệnh thay đổi các bản sao thành vault.centos.org

Bước 3: Thực hiện lại lệnh yum để kiểm tra

yum update

Ở bước này thì các bạn đã thấy mọi thứ hoạt động lại bình thường.

Failed to download metadata for repo 'AppStream'
Hình 3: Xử lý xong lỗi “Failed to download metadata for repo ‘AppStream’ “

Như vậy chúng ta đã khắc phục được lỗi Failed to download metadata for repo 'AppStream'. Khá là đơn giản phải không các bạn.

III. Tổng kết

Hy vọng qua bài viết ngắn này các bạn sẽ khắc phục được vấn đề của mình. Các bạn nên cân nhắc nâng cấp lên hệ điều hành CentOS Stream hoặc chuyển sang sử dụng hệ điều hành AlmaLinux 8 để được hỗ trợ lâu dài hơn.
Về cách chuyển đổi thì mình sẽ viết và cập nhật vào bài viết này.

Nếu trong quá trình thực hiện gặp bất cứ vấn đề nào thì hãy để lại bình luận bên dưới nhé. Mình sẽ cố gắn giải đáp thắc mắc của các bạn một cách sớm nhất.

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *