CentOS7 yum安装报错“Could not resolve host: mirrorlist.centos.org; Name or service not known“解决办法(换源)

913次阅读
没有评论

共计 4471 个字符,预计需要花费 12 分钟才能阅读完成。

yum 安装出现错误如下:

Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=genclo error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Name or service not known"

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

原因

看报错日志,ping mirrorlist.centos.org 不通。试着 ping www.baidu.com 是正常的,说明 DNS 解析没问题。

2024 年 7 月 1 日,CentOS 7 终止使用,CentOS 团队已将其存储库移至 的存档 vault.centos.org。如果不更新存储库 URL,则无法更新或验证软件包,从而导致这些错误。

CentOS7 更换镜像源

1、先安装 wget

yum install -y wget
2、下载 CentOS 7 的对应的 repo 文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3、更新镜像源

yum clean all
yum makecache
yum -y update

执行完上面三行命令就好了

以上内容原文链接:https://blog.csdn.net/masound/article/details/140123479

另外查到的资料也是 2024 年 7 月 1 号后 CentOS 7 终止使用引起的问题,也可以按以下教程修改 yum 源,未尝试过,可自行尝试,上面的方法已试过,成功解决了该问题。

Symptoms

When running various functions such as MultiPHP or command that utilize the yum system, errors similar to the following are produced:

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; Name or service not known"

 

Description

On July 1st 2024 CentOS 7 is End of Life and the CentOS team has removed their mirrors from the internet. They can still be accessed via vault.centos.org. Without updating the repository URLs, packages will be unable to be updated or validated, resulting in the error above.

IMPORTANT: Using the CentOS vault repository IS NOT to be used for staying on CentOS 7 for any longer than is required to migrate to a new server. Packages provided by the vault repository do not get any updates. This means that the software installed from the Vault repository will have unpatched security vulnerabilities and other defects.

 

Workaround

cPanel has released the following autofixer to enable the CentOS 7 Vault repository automatically for you:

/scripts/autorepair centos7_base_repo_is_no_more

Note: The above script will only correct servers with the repo file set as CentOS-Base.repo, systems using custom repositories will need to edit the repo file to use vault.centos.org using the manual steps below.

Manual Steps:

If you are using a custom CentOS 7 base repository, then please follow these manual steps:

  1. Copy the current CentOS 7 repository file so that you can revert the changes if necessary:
    cp -v /etc/yum.repos.d/CentOS-Base.repo{,-backup}

    Note: Your CentOS 7 base repository may have a different name. The above filename “CentOS-Base.repo” is only used as an example.

  2. Edit the /etc/yum.repos.d/CentOS-Base.repo file using a command line text editor
  3. Paste in the following configuration:
    [base]
    name=CentOS-$releasever - Base
    baseurl=https://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
    baseurl=https://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
    baseurl=https://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
    baseurl=https://vault.centos.org/7.9.2009/centosplus/$basearch
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  4. Save the file and exit
  5. Run the following commands:
    yum clean all && yum makecache

    原文 https://support.cpanel.net/hc/en-us/articles/24571139547415-Could-not-retrieve-mirrorlist-http-mirrorlist-centos-org-on-CentOS-7

正文完
 0
水东柳
版权声明:本站原创文章,由 水东柳 于2024-07-19发表,共计4471字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)