centos7配置阿里云yum源

本文介绍了如何在 CentOS 7 中配置阿里云 YUM 源,包括原始 YUM 源的备份、新 YUM 源的下载及更新 YUM 缓存的方法。同时,针对 CentOS 6 遇到的问题进行了说明,并给出了相应的解决措施。

原始yum源备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

下载新的yum源

Centos 7

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

Centos 6

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

过程
yum源下载

更新yum缓存

yum clean all
yum makecache

更新yum缓存

遇到的问题

centos6无法安装

Loaded plugins: fastestmirror, refresh-packagekit, security
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"

阿里yum源打开可以看到:

Please keep in mind that 6.0, 6.1, 6.2, 6.3, 6.4 , 6.5, 6.6, 6.7, 6.8 , 6.9 and 6.10 no longer get any updates, nor
any security fix's.
The whole CentOS 6 is *dead* and *shouldn't* be used anywhere at *all*

说明已经不支持centos6 的yum源,因而需要更改为centos7
之后也别再安装centos6了,太老了。。。

centos7 执行yum makecache报错

更改使用centos7的源,发现报出同样的错误,后打开 CentOS-Base.repo文件,发现可能是参数变量的问题:

http://mirrors.aliyun.com/centos/$releasever/os/$basearch/

$releasever 会自动识别centos版本,然后再次找centos6的源

此时将所有变量 $releasever 改为 7(即Centos 7),即可正常访问

相似错误参考
为centos7配置阿里yum源遇到的问题以及解决方法

CentOS 7系统上配置阿里云yum,有以下几种方法: ### 方法一 1. 备份原始yum: ```bash cd /etc/yum.repos.d cp CentOS-Base.repo CentOS-Base.repo-20220705.bak ``` 2. 配置CentOS的DNS: ```bash vim /etc/resolv.conf # 添加以下内容 nameserver 114.114.114.114 # 国内dns nameserver 8.8.8.8 # 国外dns ``` 3. 下载yum文件,替代原始yum: ```bash yum -y install wget wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum clean all # 清除缓存 yum makecache # 生成缓存 ``` 4. 获取阿里centos7的epel-repo: ```bash wget -O /etc/yum.repos.d/epel-7.repo https://mirrors.aliyun.com/repo/epel-7.repo yum clean all yum makecache ``` ### 方法二 1. 安装wget下载工具(要确保有本地镜像才能安装,本地镜像在安装光盘中,需要挂载到空目录上): ```bash yum -y install wget ``` 2. 备份原有yum(不需要保留原有yum可以忽略此步骤): ```bash mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup ``` 3. 添加阿里云base: ```bash wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo ``` 4. 添加阿里云epel: ```bash wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo ``` 5. 检查yum是否安装成功: ```bash yum repolist # 查看yum仓库 yum makecache # 生成缓存 ``` ### 方法三 1. 重命名原始yum使其失效: ```bash cd /etc/yum.repos.d mv CentOS-Base.repo CentOS-Base.repo.bak ``` 2. 下载并重命名阿里云yum文件: ```bash wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo ``` 3. 清除缓存并生成新的缓存: ```bash yum clean all yum makecache ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值