CentOS 7 已于2024年6月30日停止维护,在停止维护后我们之前配置的国内镜像源大多都是空目录了,即在线国内镜像源不可用,就像下边这样提示:

文章目录

[root@bgon yum.repos.d]# yum install vim
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile

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-Base.repo 配置与使用

CentOS-Base.repo 是 CentOS 系统中用于配置 YUM 软件仓库的文件。它定义了系统从哪些镜像源下载和更新软件包。以下是如何配置和使用 CentOS-Base.repo 文件的详细步骤。

配置 CentOS-Base.repo 文件

CentOS-Base.repo 文件通常位于 /etc/yum.repos.d/ 目录下。你可以使用以下步骤来配置这个文件:

备份原始文件: cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

编辑 CentOS-Base.repo 文件: 使用你喜欢的文本编辑器(如 vi )打开并编辑 /etc/yum.repos.d/CentOS-Base.repo 文件。

例如,使用 vi: vi /etc/yum.repos.d/CentOS-Base.repo

配置镜像源: 你可以选择使用国内的镜像源,如阿里云镜像。以下是阿里云镜像的配置示例:
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

更新 YUM 缓存

配置完成后,需要更新 YUM 缓存以使更改生效:

yum clean all
yum makecache

常见问题与解决

如果在使用过程中遇到无法解析主机或镜像源不可用的问题,可以尝试以下方法:

检查网络连接:确保服务器能够访问互联网。

更换镜像源:如果当前镜像源不可用,可以尝试更换其他镜像源。

禁用有问题的仓库:临时禁用有问题的仓库,使用以下命令: yum --disablerepo= ...

永久禁用仓库:使用以下命令永久禁用有问题的仓库: yum-config-manager --disable

通过以上步骤,你可以成功配置和使用 CentOS-Base.repo 文件,确保系统能够顺利下载和更新软件包

© 版权声明
默认:分享是一种美德,转载请保留原链接