无法在 CentOS 7 上使用 yum

fad*_*awi 6 linux centos

我已经在 hyper-v 上成功安装了 CentOS 7,但是当我尝试使用 yum update 进行更新或尝试使用yum命令进行安装时,出现以下错误:

Loaded plugins: fastestmirror, langpacks Could not retrieve mirrorlist
http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock
error was 12: Timeout on
http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock:
(28, 'Resolving timed out after 30425 milliseconds')


One of the configured repositories failed (Unknown),  and yum doesn't
have enough cached data to continue. At this point the only  safe
thing yum can do is fail. There are a few ways to work "fix" this:

      1. Contact the upstream for the repository and get them to fix the problem.

      2. Reconfigure the baseurl/etc. for the repository, to point to a working
         upstream. This is most often useful if you are using a newer
         distribution release than is supported by the repository (and the
         packages for the previous distribution release still work).

      3. Disable the repository, so yum won't use it by default. Yum will then
         just ignore the repository until you permanently enable it again or use
         --enablerepo for temporary usage:

             yum-config-manager --disable <repoid>

      4. Configure the failing repository to be skipped, if it is unavailable.
         Note that yum will try to contact the repo. when it runs most commands,
         so will have to try and fail each time (and thus. yum will be be much
         slower). If it is a very temporary problem though, this is often a nice
         compromise:

             yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

 Cannot find a valid baseurl for repo: base/7/x86_64`
Run Code Online (Sandbox Code Playgroud)

小智 7

(28, 'Resolving timed out after 30425 milliseconds')

这意味着您的 VM 可能缺少可用的 DNS 服务器。这里的解析是指将域名解析为IP地址。

尝试 ping google.com 或 mirrorlist.centos.org 以查看您是否有任何 DNS 功能。当前使用的 DNS 服务器列在/etc/resolv.conf 中,如下所示:

nameserver 8.8.8.8
nameserver 8.8.4.4
Run Code Online (Sandbox Code Playgroud)

如果/etc/resolv.conf文件为空,请先尝试 ping 上面的 IP 地址(Google 的公共 DNS),然后将它们添加到/etc/resolv.conf文件中以开始使用 Google DNS。要使其成为永久性修复,您可能需要使用 CentOS 7 网络配置工具来正确设置 DNS 服务器。这是一篇关于如何做的不错的文章:http : //www.krizna.com/centos/setup-network-centos-7/