通过 VM 的 CentOS - 镜像列表中没有 URL

CentOS through a VM - no URLs in mirrorlist

我正在尝试 运行 CentOS 8 server through VirtualBox (6.1.30) (Vagrant),昨天对我来说效果很好,但今天我尝试 运行 宁 sudo yum update。由于某种原因,我一直收到此错误:

[vagrant@192.168.38.4] ~  >> sudo yum update
CentOS Linux 8 - AppStream                       71  B/s |  38  B     00:00
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

我已经尝试更改 /etc/resolve.conf 上的命名空间,删除 DNF 文件夹和所有内容。在其他计算机上,这工作得很好,所以我认为问题出在我的主机上。我还尝试重置网络设置(我在 Windows 10 主机上),但也没有成功。这不是 DNS 问题;它工作得很好。

我重新安装后 Windows,我的 VM 中仍然有同样的错误。

文件dnf.log:

2022-01-31T15:28:03+0000 INFO --- logging initialized ---
2022-01-31T15:28:03+0000 DDEBUG timer: config: 2 ms
2022-01-31T15:28:03+0000 DEBUG Loaded plugins: builddep, changelog, config-manager, copr, debug, debuginfo-install, download, generate_completion_cache, groups-manager, needs-restarting, playground, repoclosure, repodiff, repograph, repomanage, reposync
2022-01-31T15:28:03+0000 DEBUG YUM version: 4.4.2
2022-01-31T15:28:03+0000 DDEBUG Command: yum update
2022-01-31T15:28:03+0000 DDEBUG Installroot: /
2022-01-31T15:28:03+0000 DDEBUG Releasever: 8
2022-01-31T15:28:03+0000 DEBUG cachedir: /var/cache/dnf
2022-01-31T15:28:03+0000 DDEBUG Base command: update
2022-01-31T15:28:03+0000 DDEBUG Extra commands: ['update']
2022-01-31T15:28:03+0000 DEBUG User-Agent: constructed: 'libdnf (CentOS Linux 8; generic; Linux.x86_64)'
2022-01-31T15:28:05+0000 DDEBUG Cleaning up.
2022-01-31T15:28:05+0000 SUBDEBUG
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/dnf/repo.py", line 574, in load
    ret = self._repo.load()
  File "/usr/lib64/python3.6/site-packages/libdnf/repo.py", line 397, in load
    return _repo.Repo_load(self)
libdnf._error.Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 67, in main
    return _main(base, args, cli_class, option_parser_class)
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 106, in _main
    return cli_run(cli, base)
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 122, in cli_run
    cli.run()
  File "/usr/lib/python3.6/site-packages/dnf/cli/cli.py", line 1050, in run
    self._process_demands()
  File "/usr/lib/python3.6/site-packages/dnf/cli/cli.py", line 740, in _process_demands
    load_available_repos=self.demands.available_repos)
  File "/usr/lib/python3.6/site-packages/dnf/base.py", line 394, in fill_sack
    self._add_repo_to_sack(r)
  File "/usr/lib/python3.6/site-packages/dnf/base.py", line 137, in _add_repo_to_sack
    repo.load()
  File "/usr/lib/python3.6/site-packages/dnf/repo.py", line 581, in load
    raise dnf.exceptions.RepoError(str(e))
dnf.exceptions.RepoError: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
2022-01-31T15:28:05+0000 CRITICAL Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

查看这篇文章:CentOS Linux EOL

以下命令对我有帮助:

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

这样做将使 DNF 正常工作,但您将不会再收到任何更新。

要升级到 CentOS 8 流:

sudo dnf install centos-release-stream -y
sudo dnf swap centos-{linux,stream}-repos -y
sudo dnf distro-sync -y

如果您的内核更新(容器中不需要),可选择重启。

CentOS 8 在 2021 年底停产。一个长期的解决方案是迁移到不同的操作系统,例如 Rocky Linux