centos6 yum源失效的最新操作方式

1 备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
3 运行 yum makecache 生成缓存

[root@hadoop101 yum.repos.d]# yum makecache 
已加载插件:fastestmirror, refresh-packagekit, security
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
http://mirrors.aliyun.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
尝试其他镜像。
To address this issue please refer to the below knowledge base article 

https://access.redhat.com/articles/1320623

If above article doesn't help to resolve this issue please open a ticket with Red Hat Support.

http://mirrors.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: (28, 'connect() timed out!')
尝试其他镜像。
http://mirrors.cloud.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.cloud.aliyuncs.com'"
尝试其他镜像。
错误:Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
[root@hadoop101 yum.repos.d]#   

4 替换源文件配置, 使用https://mirrors.aliyun.com/centos-vault

sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
sed -i  's/http/https/g' /etc/yum.repos.d/CentOS-Base.repo
sed -i  's/$releasever/6.8/g' /etc/yum.repos.d/CentOS-Base.repo
sed -i  's/centos/centos-vault/g' /etc/yum.repos.d/CentOS-Base.repo
5 yum clean all && yum makecache

### 解决CentOS 7 YUM源失效问题 由于官方对 CentOS 7 停止了维护,YUM源网址 `mirror.centos.org` 已经无法访问[^3]。为了继续使用稳定的软件包管理功能,建议更换到其他可靠的镜像源,如阿里云提供的镜像源。 #### 更换阿里云镜像源的方法 ##### 自动化脚本方式 可以通过执行特定的Shell命令来自动替换默认的YUM配置文件为阿里云提供的版本: ```bash wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo ``` 这条命令会下载并覆盖现有的 `/etc/yum.repos.d/CentOS-Base.repo` 文件,从而切换至新的镜像地址[^4]。 ##### 手工修改配置文件的方式 如果偏好手动操作,则可以直接编辑 `/etc/yum.repos.d/CentOS-Base.repo` 文件: 1. 使用文本编辑器打开此文件: ```bash vi /etc/yum.repos.d/CentOS-Base.repo ``` 2. 修改其中的内容如下所示(仅展示部分示例): ```ini [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=https://mirrors.aliyun.com/centos/vault/7.9.2009/os/x86_64/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 ... [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=https://mirrors.aliyun.com/centos/vault/7.9.2009/extras/x86_64/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 ``` 注意:上述URL中的具体路径可能随时间变化而有所不同,请根据实际情况调整。 完成以上任一方法之后,记得清理缓存以使更改生效: ```bash yum clean all && yum makecache fast ``` 这样就可以成功修复因官方支持结束而导致的CentOS 7 YUM源失效的问题了。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值