当前位置: 首页 > article >正文

Linux | 配置docker环境时yum一直出错的解决方法

yum出错

    • Centos 7版本
    • 出错问题
    • 补充:
      • 什么是yum
      • yum 和 apt 有什么区别?

Centos 7版本


[root@localhost yum.repos.d]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

出错问题

  • 问题1
Could not retrieve mirrorlist http://mirrorlist.centos.org/

这个不局限于yum provides ifconfig这一条命令 yum makecache命令也会出现

[root@localhost ~]# yum provides ifconfig
已加载插件: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; 未知的错误"


 One of the configured repositories failed (未知),
 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

出现这个错误是因为你使用的 CentOS 7 仓库已经被归档,当前的镜像地址无法找到所需的文件。CentOS 7 的官方支持已经结束,部分仓库已被移至归档库。这导致了你的 yum 命令无法找到所需的元数据文件。CentOS 7 的官方仓库在 2024 年 6 月 30 日之后已经停止维护。因此,使用最新的 CentOS 7 官方仓库可能会遇到问题。

遇到以上问题笔者建议如下解决方案:

cd /etc/yum.repos.d   目录下找到  CentOS-Base.repo
执行:
cp  CentOS-Base.repo   CentOS-Base.repo.backup
vi CentOS-Base.repo 

将原内容修改为:

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#
 
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#$baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

在这里插入图片描述
到此可以正常使用yum了

补充:

什么是yum

想象一下,你的厨房里有一个装满食材的大柜子,但是有一天,你想做一道新菜,发现柜子里缺少一些食材。这时候,你需要去超市买缺少的食材。在 Linux 系统中,yum 就有点像那个超市。

yum(全称 Yellowdog Updater Modified)是一个在 Linux 系统中用来安装、更新和管理软件包的工具。你可以把它想象成一个超市,里面有很多货架,每个货架上都摆满了各种各样的软件包,这些软件包就像是你需要的食材。

当你的 Linux 系统缺少某个软件或者需要更新某个软件时,你就可以通过 yum 来获取它。只要告诉 yum 你想要什么,它就会自动帮你找到最新的版本,并帮你安装好,或者更新到最新版本。

举个例子,如果你想安装一个文本编辑器,你只需要打开终端,输入 yum install vim,然后 yum 就会帮你下载并安装 vim 编辑器。如果你的系统中已经有了 vimyum 还会告诉你它已经是最新版本了。

yum 还能帮你管理软件包之间的依赖关系,就像是做一道菜需要的各种食材之间也有搭配一样。如果一个软件需要其他软件支持才能运行,yum 会帮你一起把它们都找来。

总的来说,yum 就像是 Linux 系统中的一个超市,你可以通过它来获取、更新和管理你需要的软件包,让 Linux 系统保持最新和最有用。

yum 和 apt 有什么区别?

yumapt 都是 Linux 系统中用于安装和管理软件包的工具,但它们主要用在不同的 Linux 发行版上,并且有一些关键的区别:

  1. 使用的发行版

    • yum(Yellowdog Updater Modified)最初是为 Red Hat Linux 开发的,现在主要用于 Red Hat Enterprise Linux(RHEL)、CentOS 和 Fedora 等基于 RPM(Red Hat Package Manager)的发行版。
    • apt(Advanced Package Tool)是为 Debian 及其衍生版开发的,如 Ubuntu、Debian、Linux Mint 等使用 DEB 软件包格式的发行版。
  2. 软件包格式

    • yum 处理的是 RPM 软件包,这些软件包包含了软件及其依赖。
    • apt 处理的是 DEB 软件包,这些软件包也包含了软件及其依赖。
  3. 依赖管理

    • 两者都能自动处理软件依赖,但它们的依赖解决算法和内部工作方式不同。apt 使用的方法通常被认为更先进,因为它可以更有效地解决复杂的依赖问题。
  4. 仓库(Repository)管理

    • yumapt 都允许用户添加、移除和更新软件仓库,但它们的配置文件格式和使用的命令不同。
  5. 用户界面

    • yum 通常在命令行中使用,尽管也有图形界面的前端,如 yumexkpackagekit
    • apt 也可以在命令行中使用,但它更常与图形界面的软件中心(如 Ubuntu 的“Ubuntu Software Center”)一起使用。
  6. 命令语法

    • 它们的命令语法不同。例如,安装一个软件包在 yum 中是 sudo yum install packagename,在 apt 中是 sudo apt install packagename
  7. 性能和速度

    • apt 通常被认为在处理速度和性能上更优,特别是在处理大量的软件包更新时。
  8. 软件源(Software Sources)

    • apt 允许用户通过图形界面或命令行轻松地添加第三方软件源(repository),而 yum 通常需要编辑配置文件。

尽管存在这些差异,yumapt 的核心目标是相同的:简化 Linux 系统中软件的安装、更新和管理过程。选择使用哪一个通常取决于你使用的 Linux 发行版。


http://www.kler.cn/news/367169.html

相关文章:

  • 基于JAVASE的题
  • Docker容器操作
  • C语言实现Go的defer功能
  • 点云处理中的多项式重构、平滑与法线估计
  • openjdk17在java方法中创建对象 类加载在C++源码实现步骤
  • 深入剖析 C 与 C++ 动态内存管理之术
  • [软件工程]—嵌入式软件开发流程
  • 探索Python安全字符串处理的奥秘:MarkupSafe库揭秘
  • 华为配置 之 端口隔离
  • 腾讯云控制台URL刷新URL预热 使用接口刷新
  • PgSQL常用SQL语句
  • windows DLL技术-AppInit DLL技术和DLL的最佳做法
  • Linux 斐波那契数列 递归汇编实现
  • python爬虫:HTTP、Cookie和会话管理详解
  • WPF+MVVM案例实战(六)- 自定义分页控件实现
  • 华为网络管理配置实例
  • [Ansible实践笔记]自动化运维工具Ansible(一):初探ansibleansible的点对点模式
  • TensorFlow面试整理-TensorFlow 基础概念
  • JavaScript part2
  • jenkins 作业添加用户权限
  • 练习LabVIEW第十八题
  • 在xml 中 不等式 做转义处理的问题
  • Nginx16-Lua扩展案例
  • Django从请求到响应
  • 阿里云镜像源无法访问?使用 DaoCloud 镜像源加速 Docker 下载(Linux 和 Windows 配置指南)
  • ESP32-S3学习笔记:常用的ESP-IDF命令总结