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重新啟動網路”

相關內容