Centos7系统配置国内yum源

来自CloudWiki
跳转至: 导航搜索

文件备份

1.首先进入/etc/yum.repos.d/目录下,新建一个repo_bak目录,用于保存系统中原来的repo文件

 [root@bogon ~]# cd /etc/yum.repos.d/

[root@bogon yum.repos.d]# mkdir repo_bak

[root@bogon yum.repos.d]# mv *.repo repo_bak/

配置yum源

2.在CentOS中配置使用网易和阿里的开源镜像

到网易和阿里开源镜像站点下载系统对应版本的repo文件

[root@bogon yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo

[root@bogon yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

[root@bogon yum.repos.d]# ls Centos-7.repo CentOS-Base-163.repo repo.bak

3.清除系统yum缓存并生成新的yum缓存

[root@bogon yum.repos.d]# ls # 列出/etc/yum.repos.d/目录下的文件

Centos-7.repo  CentOS-Base-163.repo  repo.bak

[root@bogon yum.repos.d]# yum clean all # 清除系统所有的yum缓存

[root@bogon yum.repos.d]# yum makecache # 生成yum缓存

安装epel源

4.安装epel源

[root@bogon yum.repos.d]# yum list | grep epel-release

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
epel-release.noarch                         7-9                        extras   

[root@bogon yum.repos.d]# yum install -y epel-release

[root@bogon yum.repos.d]# ls # epel源安装成功,比原来多了一个epel.repo和epel-testing.repo文件

Centos-7.repo  CentOS-Base-163.repo  epel.repo  epel-testing.repo  repo.bak

5.使用阿里开源镜像提供的epel源

[root@bogon yum.repos.d]# wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo # 下载阿里开源镜像的epel源文件

[root@bogon yum.repos.d]# ls

CentOS7-Base-163.repo  Centos-7.repo  epel-7.repo  epel.repo  epel-testing.repo  repo_bak

6.再次清除系统yum缓存,并重新生成新的yum缓存

[root@bogon yum.repos.d]# yum clean all

[root@bogon yum.repos.d]# yum makecache

查看可用源

7.查看系统可用的yum源和所有的yum源

[root@bogon yum.repos.d]# yum repolist enabled

Loaded plugins: fastestmirror, langpacks
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 epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * epel: mirrors.aliyun.com
repo id                                            repo name                                                                         status
base/7/x86_64                                      CentOS-7 - Base - 163.com                                                          9,591
epel/x86_64                                        Extra Packages for Enterprise Linux 7 - x86_64                                    12,382
extras/7/x86_64                                    CentOS-7 - Extras - 163.com                                                          390
updates/7/x86_64                                   CentOS-7 - Updates - 163.com                                                       1,941
repolist: 24,304

[root@bogon yum.repos.d]# yum repolist all

Loaded plugins: fastestmirror, langpacks
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 epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * epel: mirrors.aliyun.com
repo id                                     repo name                                                                       status
base/7/x86_64                               CentOS-7 - Base - 163.com                                                       enabled:  9,591
centosplus/7/x86_64                         CentOS-7 - Plus - 163.com                                                       disabled
contrib/7/x86_64                            CentOS-7 - Contrib - mirrors.aliyun.com                                         disabled
epel/x86_64                                 Extra Packages for Enterprise Linux 7 - x86_64                                  enabled: 12,382
epel-debuginfo/x86_64                       Extra Packages for Enterprise Linux 7 - x86_64 - Debug                          disabled
epel-source                                 Extra Packages for Enterprise Linux 7 - x86_64 - Source                         disabled
epel-testing/x86_64                         Extra Packages for Enterprise Linux 7 - Testing - x86_64                        disabled
epel-testing-debuginfo/x86_64               Extra Packages for Enterprise Linux 7 - Testing - x86_64 - Debug                disabled
epel-testing-source/x86_64                  Extra Packages for Enterprise Linux 7 - Testing - x86_64 - Source               disabled
extras/7/x86_64                             CentOS-7 - Extras - 163.com                                                     enabled:    390
updates/7/x86_64                            CentOS-7 - Updates - 163.com                                                    enabled:  1,941
repolist: 24,304

参考文档:

[1] https://www.cnblogs.com/renpingsheng/p/7845096.html