开发者

Centos7更换仓库源为阿里云镜像的详细步骤

服务器镜像如下:/etc/yum.repos.d

[root@ecs-q97onp yum.repos.d]# ll

total 44

-rw-r--r-- 1 root roojavascriptt 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 pythonroot 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.rep编程o

-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 EnfpKfqZlWnterprise 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更换阿里云镜像内容请搜索编程客栈(www.devze.com)以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程客栈(www.cppcnsjs.com)!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新运维

运维排行榜