关于 Linux【Root权限登录 Centos。确保yum包更新到最新。】

sudo yum update

 

 

 

 

报错了

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"


 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. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, 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>
        or
            subscription-manager repos --disable=<repoid>

     5. 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

 

 

错误分析

 

  • 插件加载与镜像速度加载:
    • “Loaded plugins: fastestmirror, langpacks” 表明 yum 在启动时成功加载了 “fastestmirror” 和 “langpacks” 这两个插件。其中 “fastestmirror” 插件会尝试为 yum 操作选择速度最快的镜像源,“langpacks” 插件通常用于处理软件包相关的语言包配置等事宜。
    • “Loading mirror speeds from cached hostfile” 表示 yum 正在从缓存的主机文件中获取各个镜像源的速度信息,以便后续能依据这些信息选择合适的镜像源来下载软件包等。
  • 核心错误:
    • “Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"” 这部分是关键问题所在。它意味着 yum 在尝试获取 CentOS 7 系统下 “os” 仓库(由 “repo=os” 指定)的镜像列表时遇到了阻碍。具体原因是无法通过网络解析 “mirrorlist.centos.org” 这个主机名,进而导致无法获取到该仓库的镜像列表内容。这可能是由以下几种情况引起的:
      • 网络连接故障:系统当前的网络连接可能不正常,比如网线未插好、Wi-Fi 未正确连接等,使得无法向外部的域名服务器发送域名解析请求来确定 “mirrorlist.centos.org” 对应的 IP 地址。
      • DNS 解析问题:即使网络连接是正常的,但负责域名解析的 DNS 服务器可能出现故障,或者系统的 DNS 设置不正确。例如,DNS 服务器本身无法正常工作,或者设置的 DNS 服务器地址无法准确地将 “mirrorlist.centos.org” 这个域名解析为对应的 IP 地址。
      • CentOS 官方镜像服务器状况:有可能是 CentOS 官方的镜像服务器暂时出现了故障、维护或者网络拥塞等情况,导致即使域名能够被正确解析,也无法从其获取到镜像列表信息。

解决办法

 

    • 检查网络连接状态:
      • 可以通过多种方式来检查网络连接是否正常。例如,在终端中输入 “ping 8.8.8.8”(这是谷歌提供的公共 DNS 服务器的 IP 地址),如果能够收到回应(比如显示类似 “64 bytes from 8.8.8.8: icmp_seq=1 ttl=119 rtt=10.5 ms” 这样的信息),则说明网络连接基本正常;如果没有回应,那就需要进一步检查网络设备,确保网线插好、Wi-Fi 连接正确等。
      • 另外,也可以尝试通过浏览器等方式访问一些常见的网站,如 “www.google.com” 等,如果无法正常访问,同样表明网络连接存在问题,需要进一步排查。
    • 核实 DNS 设置:
      • 查看系统的 DNS 设置情况。在 CentOS 系统中,DNS 设置通常存储在 “/etc/resolv.conf” 文件中。可以使用 “cat /etc/resolv.conf” 命令来查看该文件的内容。一个正常的 DNS 设置示例可能如下:
        • nameserver 8.8.8.8
        • nameserver 8.8.4.4
      • 如果发现文件中的 DNS 服务器地址不正确、无法正常工作或者与当前网络环境不匹配,那么可以手动修改为合适的 DNS 服务器地址。比如,如果是家庭网络,可以向网络服务提供商咨询获取正确的 DNS 服务器地址,并将其填写到 “/etc/resolv.conf” 文件中。修改完成后,再次尝试执行 yum 相关操作,看是否能够解决问题。
    • 依据错误提示的临时解决措施:
      • 暂时禁用相关仓库:根据错误提示中的建议,可以使用 “yum --disablerepo=<repoid>...” 命令来暂时禁用出现问题的仓库。在此次案例中,由于是 “os” 仓库出现问题(从 “repo=os” 可看出),假设仓库 ID 就是 “os”,那么可以使用 “yum --disablerepo=os...” 命令来执行后续的 yum 操作。这样 yum 就不会尝试从这个有问题的仓库获取软件包,从而有可能绕过当前的问题,完成其他仓库相关的软件包操作(前提是其他仓库正常)。
      • 配置跳过不可用仓库:可以使用 “yum - config - manager --save --setopt=<repoid>.skip_if_unavailable=true” 命令来配置当仓库不可用时跳过它。同样对于 “os” 仓库,假设其仓库 ID 为 “os”,可以使用 “yum - config - manager --save --setopt=os.skip_if_unavailable=true”。这样在后续执行 yum 命令时,如果发现 “os” 仓库不可用,就会跳过它,而不是直接报错。不过需要注意的是,这种方法可能会导致软件包更新等操作不完整,因为可能会错过这个仓库中的软件包更新。
    • 更换镜像源(长期解决方案):
      • 如果经常遇到类似的问题,或者确定是 CentOS 官方镜像源不太稳定等情况,可以考虑更换为国内的镜像源。以下是以更换为阿里云镜像源为例的步骤:
        • 备份原始的 yum 仓库配置文件。在终端中输入 “cp /etc/yum.repos.d/CentOS - Base.repo/etc/yum.repos.d/CentOS - Base.repo.backup”,以防止在修改过程中出现问题后无法恢复。
        • 编辑 “/etc/yum.repos.d/CentOS - Base.repo” 文件。可以使用文本编辑器如 vi 或 vim 来进行编辑,在终端中输入 “vi /etc/yum.repos.d/CentOS - Base.repo”。
        • 在打开的文件中,找到与 “baseurl” 相关的部分,将其原来的内容替换为阿里云镜像源的对应内容。对于 CentOS 7 系统,阿里云镜像源的 “baseurl” 部分一般可设置为 “http://mirrors.aliyun.com/centos/7/os/x86_64/”(具体内容可能会根据阿里云镜像源的更新等情况有所变化,建议参考阿里云官方文档获取最新准确信息)。
        • 修改完成后,保存并退出编辑器(在 vi 或 vim 中,按 “Esc” 键进入命令模式,然后输入 “:wq” 来保存并退出)。
        • 之后,再次尝试执行 yum 相关操作,看是否能够顺利进行。

我使用的解决方案   因为是虚拟机 所以没有备份 直接更新

# 备份
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

#下载阿里云镜像配置文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

 这样就成功了

 重试一下

 OK了  



———— 一位梦想成为大佬的菜鸟

posted @ 2024-11-19 21:13  .NetCat  阅读(160)  评论(0)    收藏  举报