解决CentOS 镜像列表服务已下线或迁移导致镜像服务和仓库停止维护解决方案
拉取dnf报错问题:
[root@localhost opt]# yum -y install dnf
Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-managerThis system is not registered with an entitlement server. You can use subscription-manager to register.Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org?arch=x86_64&release=7&repo=sclo-sclo 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 onlysafe 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 workingupstream. This is most often useful if you are using a newerdistribution release than is supported by the repository (and thepackages for the previous distribution release still work).3. Run the command with the repository temporarily disabledyum --disablerepo=<repoid> ...4. Disable the repository permanently, so yum won't use it by default. Yumwill then just ignore the repository until you permanently enable itagain or use --enablerepo for temporary usage:yum-config-manager --disable <repoid>orsubscription-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 muchslower). If it is a very temporary problem though, this is often a nicecompromise:yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=trueCannot find a valid baseurl for repo: centos-sclo-sclo/x86_64
解决方案
1、备份现有的仓库文件(以防万一):
cd /etc/yum.repos.d/
mkdir backup
mv *.repo backup/
2、下载并安装阿里云的 CentOS 镜像源:
# 下载 CentOS-Base.repo 到 /etc/yum.repos.d/
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo# 下载 EPEL 源(Extra Packages for Enterprise Linux,包含很多额外软件)
curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
注意:如果 curl 命令无法执行,您也可以在其他能上网的机器上下载这两个文件,然后通过 U 盘或 SFTP 等方式上传到服务器的 /etc/yum.repos.d/ 目录。
3、清理 YUM 缓存并生成新缓存:
yum clean all
yum makecache
4、现在再次尝试安装 dnf:
yum -y install dnf
5、验证是否成功
yum repolist
这个命令会列出所有已启用并可用的软件仓库。如果您能看到来自 mirrors.aliyun.com 的仓库列表,说明配置成功。