无法在 CentOS 7 上使用 yum

无法在 CentOS 7 上使用 yum

我已在 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`

答案1

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

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

尝试 ping google.com 或 mirrorlist.centos.org 以查看是否有任何 DNS 功能。当前使用的 DNS 服务器列在/etc/resolv.conf像这样:

nameserver 8.8.8.8
nameserver 8.8.4.4

如果/etc/resolv.conf文件为空,请先尝试 ping 上述 IP 地址(Google 的公共 DNS),然后将其添加到/etc/resolv.conf按照上述步骤操作即可开始使用 Google DNS。要永久修复此问题,您可能需要使用 CentOS 7 网络配置工具来正确设置 DNS 服务器。这里有一篇不错的文章介绍如何操作:http://www.krizna.com/centos/setup-network-centos-7/

答案2

使用ip route查看默认路由指向哪个 IP,如果什么都看不到,那么你需要获取新的 IP,可以通过以下方式完成

sudo dhclient

这必定能解决问题。yum update立即尝试。

答案3

这是 ipv6 问题。禁用 ipv6 运行。

lsmod | grep -i ipv6
sysctl --all
nslookup google.com
systemctl stop NetworkManager
systemctl disable NetworkManager
cd /etc/default

change line to : GRUB_CMDLINE_LINUX="ipv6.disable=1 rd.lvm.lv=centos/swap vconsole.font=latarcyrh

grub2-mkconfig -o /boot/grub2/grub.cfg
vi grub
ip addr

注意:在 grub 上添加禁用命令

答案4

找到“/etc/sysconfig/network-scripts/ifcfg-enp0s17”文件。**文件名可能因环境而异。1. 找到以下行:BOOTPROTO=none ONBOOT=no

  1. 更改为 BOOTPROTO=dhcp ONBOOT=yes 保存 + 退出

  2. 运行“systemctl restart network”

相关内容