服务器镜像如下:/etc/yum.repos.d
[root@ecs-q97onp yum.repos.d]# ll
total 44
-rw-r--r-- 1 root root 2523 mar 18 21:42 centos-base.repo
-rw-r--r-- 1 root root 1309 mar 2 2021 centos-cr.repo
-rw-r--r-- 1 root root 649 mar 2 2021 centos-debuginfo.repo
-rw-r--r-- 1 root root 326 mar 2 2021 centos-fasttrack.repo
-rw-r--r-- 1 root root 630 mar 2 2021 centos-media.repo
-rw-r--r-- 1 root root 1331 mar 2 2021 centos-sources.repo
-rw-r--r-- 1 root root 7577 mar 2 2021 centos-vault.repo
-rw-r--r-- 1 root root 640 mar 2 2021 centos-x86_64-kernel.repo
-rw-r--r-- 1 root root 664 mar 18 21:25 epel.repo
这里默认是清华源,但是在使用yum安装的时候提示找不到镜像,故而更换阿里源。
更换基础源配置文件
# centos 基础源---这句话很重要哦 sudo curl -o /etc/yum.repos.d/centos-base.repo https://mirrors.aliyun.com/repo/centos-7.repo
修改后的阿里云epel源配置
sudo tee /etc/yum.repos.d/epel.repo <<'eof'
[epel]
name=extra packages for enterprise linux 7 - $basearch - aliyun
baseurl=https://mirrors.aliyun.com/epel/7/$basearch
#baseurl=https://mirrors.aliyun.com/epel/7/$basearch
metalink=
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/rpm-gpg-key-epel-7
[epel-debuginfo]
name=extra packages for enterprise linux 7 - $basearch - debug - aliyun
baseurl=https://mirrors.aliyun.com/epel/7/$basearch/debug
#baseurl=https://mirrors.aliyun.com/epel/7/$basearch/debug
metalink=
failovermethod=priority
enabled=0
gpgkey=https://mirrors.aliyun.com/epel/rpm-gpg-key-epel-7
gpgcheck=1
[epel-source]
name=extra packages for enterprise linux 7 - $basearch - source - aliyun
baseurl=https://mirrors.aliyun.com/epel/7/srpms
#baseurl=https://mirrors.aliyun.com/epel/7/srpms
metalink=
failovermethod=priority
enabled=0
gpgkey=https://mirrors.aliyun.com/epel/rpm-gpg-key-epel-7
gpgcheck=1
eof
修改说明
镜像地址变更:
- 将原地址 mirrors.tuna.tsinghua.edu.cn 改为 mirrors.aliyun.com
- 去除了 metalink 参数(阿里云镜像不需要该参数)
gpg密钥地址:
- gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-epel-7
+ gpgkey=https://mirrors.aliyun.com/epel/rpm-gpg-key-epel-7
仓库命名标识:
- name=extra packages for enterprise linux 7 - $basearch
+ name=extra packages for enterprise linux 7 - $basearch - aliyun
操作步骤
备份原有配置:
sudo cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak
应用新配置:
sudo curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
清理并重建缓存:
sudo yum clean all sudo yum makecache
验证配置:
yum repolist epel
应该看到类似输出:
repo id repo name
epel/7/x86_64 extra packages for enterprise linux 7 - x86_64 - aliyun
注意事项
如果遇到 gpg key retrieval failed 错误,可临时禁用 gpg 检查:
sudo yum install --nogpgcheck [package-name]
建议保留原始清华源配置备份,以便需要时恢复:
sudo mv /etc/yum.repos.d/epel.repo.bak /path/to/backup/
阿里云镜像地址支持 https 协议访问,如果系统未安装 ssl 证书,可以改用 http:
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
其他相关镜像源推荐配置:
# centos 基础源---这句话很重要哦 sudo curl -o /etc/yum.repos.d/centos-base.repo https://mirrors.aliyun.com/repo/centos-7.repo # docker ce 源 sudo curl -o /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
配置前后对比图
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
+ baseurl=https://mirrors.aliyun.com/epel/7/$basearch
- gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-epel-7
+ gpgkey=https://mirrors.aliyun.com/epel/rpm-gpg-key-epel-7
yum安装的时候指定使用某个镜像
sudo yum install --disablerepo=* --enablerepo=epel[epel为仓库id] 软件包名
知识扩展
centos7更换阿里云镜像源步骤
在centos 7上更换为阿里云的镜像源可以通过以下步骤进行:
备份当前的yum源配置文件
sudo cp -a /etc/yum.repos.d /etc/yum.repos.d.backup
清理原有的yum源配置文件
sudo rm -f /etc/yum.repos.d/*.repo
下载阿里云的centos 7源配置文件
sudo curl -o /etc/yum.repos.d/centos-base.repo http://mirrors.aliyun.com/repo/centos-7.repo
清除yum缓存并生成新的缓存
sudo yum clean all sudo yum makecache
完成以上步骤后,您的系统就会使用阿里云的镜像源进行软件包的安装和更新。
centos7更换阿里云镜像
1.安装wget
yum -y install wget
2.建议备份原有的yum源文件,不要直接删除
mv /etc/yum.repos.d/centos-base.repo /etc/yum.repos.d/centos-base.repo.backup
3.下载阿里云镜像文件
cd /etc/yum.repos.d wget -o /etc/yum.repos.d/centos-base.repo http://mirrors.aliyun.com/repo/centos-7.repo
4.清理缓存
yum clean all
5.生成缓存
yum makecache
6.更新最新源设置
yum update -y
到此这篇关于centos7更换仓库源为阿里云镜像的详细步骤的文章就介绍到这了,更多相关centos7更换阿里云镜像内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论