Centos 7 配置国内yum源和epel源指南

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/

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

或者手动下载repo文件并上传到/etc/yum.repos.d/目录

网易开源镜像站

阿里开源镜像站

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

 1 [root@bogon yum.repos.d]# ls        # 列出/etc/yum.repos.d/目录下的文件
 2 Centos-7.repo  CentOS-Base-163.repo  repo.bak
 3 
 4 [root@bogon yum.repos.d]# yum clean all     # 清除系统所有的yum缓存
 5 Loaded plugins: fastestmirror, langpacks
 6 Repository base is listed more than once in the configuration
 7 Repository updates is listed more than once in the configuration
 8 Repository extras is listed more than once in the configuration
 9 Repository centosplus is listed more than once in the configuration
10 Cleaning repos: base extras updates
11 Cleaning up everything
12 Cleaning up list of fastest mirrors
13 
14 [root@bogon yum.repos.d]# yum makecache     # 生成yum缓存
15 Loaded plugins: fastestmirror, langpacks
16 Repository base is listed more than once in the configuration
17 Repository updates is listed more than once in the configuration
18 Repository extras is listed more than once in the configuration
19 Repository centosplus is listed more than once in the configuration
20 base                                                                                  | 3.6 kB  00:00:00     
21 extras                                                                                | 3.4 kB  00:00:00     
22 updates                                                                               | 3.4 kB  00:00:00     
23 (1/12): base/7/x86_64/filelists_db                                                    | 6.7 MB  00:00:02     
24 (2/12): base/7/x86_64/group_gz                                                        | 156 kB  00:00:02     
25 (3/12): base/7/x86_64/other_db                                                        | 2.5 MB  00:00:01     
26 (4/12): base/7/x86_64/primary_db                                                      | 5.7 MB  00:00:02     
27 (5/12): extras/7/x86_64/prestodelta                                                   |  51 kB  00:00:01     
28 (6/12): extras/7/x86_64/filelists_db                                                  | 494 kB  00:00:02     
29 (7/12): extras/7/x86_64/other_db                                                      |  86 kB  00:00:00     
30 (8/12): extras/7/x86_64/primary_db                                                    | 130 kB  00:00:01     
31 (9/12): updates/7/x86_64/prestodelta                                                  | 406 kB  00:00:01     
32 (10/12): updates/7/x86_64/filelists_db                                                | 2.1 MB  00:00:01     
33 (11/12): updates/7/x86_64/other_db                                                    | 354 kB  00:00:00     
34 (12/12): updates/7/x86_64/primary_db                                                  | 3.6 MB  00:00:01     
35 Determining fastest mirrors
36 Metadata Cache Created

4.安装epel源

 1 [root@bogon yum.repos.d]# yum list | grep epel-release
 2 Repository base is listed more than once in the configuration
 3 Repository updates is listed more than once in the configuration
 4 Repository extras is listed more than once in the configuration
 5 Repository centosplus is listed more than once in the configuration
 6 epel-release.noarch                         7-9                        extras   
 7 
 8 [root@bogon yum.repos.d]# yum install -y epel-release
 9 Loaded plugins: fastestmirror, langpacks
10 Repository base is listed more than once in the configuration
11 Repository updates is listed more than once in the configuration
12 Repository extras is listed more than once in the configuration
13 Repository centosplus is listed more than once in the configuration
14 Loading mirror speeds from cached hostfile
15 Resolving Dependencies
16 --> Running transaction check
17 ---> Package epel-release.noarch 0:7-9 will be installed
18 --> Finished Dependency Resolution
19 
20 Dependencies Resolved
21 
22 =============================================================================================================
23  Package                       Arch                    Version                 Repository               Size
24 =============================================================================================================
25 Installing:
26  epel-release                  noarch                  7-9                     extras                   14 k
27 
28 Transaction Summary
29 =============================================================================================================
30 Install  1 Package
31 
32 Total download size: 14 k
33 Installed size: 24 k
34 Downloading packages:
35 epel-release-7-9.noarch.rpm                                                           |  14 kB  00:00:00     
36 Running transaction check
37 Running transaction test
38 Transaction test succeeded
39 Running transaction
40   Installing : epel-release-7-9.noarch                                                                   1/1 
41   Verifying  : epel-release-7-9.noarch                                                                   1/1 
42 
43 Installed:
44   epel-release.noarch 0:7-9                                                                                  
45 
46 Complete!
47 [root@bogon yum.repos.d]# ls            # epel源安装成功,比原来多了一个epel.repo和epel-testing.repo文件
48 Centos-7.repo  CentOS-Base-163.repo  epel.repo  epel-testing.repo  repo.bak

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

 1 [root@bogon yum.repos.d]# wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo    # 下载阿里开源镜像的epel源文件
 2 --2018-03-08 20:22:14--  http://mirrors.aliyun.com/repo/epel-7.repo
 3 Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 183.2.199.237, 113.96.109.95, 113.96.109.93, ...
 4 Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|183.2.199.237|:80... connected.
 5 HTTP request sent, awaiting response... 200 OK
 6 Length: 1084 (1.1K) [application/octet-stream]
 7 Saving to: ‘/etc/yum.repos.d/epel-7.repo’
 8 
 9 100%[=================================================================================================>] 1,084       --.-K/s   in 0s      
10 
11 2018-03-08 20:22:14 (130 MB/s) - ‘/etc/yum.repos.d/epel-7.repo’ saved [1084/1084]
12 
13 [root@bogon yum.repos.d]# ls
14 CentOS7-Base-163.repo  Centos-7.repo  epel-7.repo  epel.repo  epel-testing.repo  repo_bak

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

 1 [root@bogon yum.repos.d]# yum clean all
 2 Loaded plugins: fastestmirror, langpacks
 3 Repository base is listed more than once in the configuration
 4 Repository updates is listed more than once in the configuration
 5 Repository extras is listed more than once in the configuration
 6 Repository centosplus is listed more than once in the configuration
 7 Repository epel is listed more than once in the configuration
 8 Repository epel-debuginfo is listed more than once in the configuration
 9 Repository epel-source is listed more than once in the configuration
10 Cleaning repos: base epel extras updates
11 Cleaning up everything
12 Cleaning up list of fastest mirrors
13 
14 [root@bogon yum.repos.d]# yum makecache
15 Loaded plugins: fastestmirror, langpacks
16 Repository base is listed more than once in the configuration
17 Repository updates is listed more than once in the configuration
18 Repository extras is listed more than once in the configuration
19 Repository centosplus is listed more than once in the configuration
20 Repository epel is listed more than once in the configuration
21 Repository epel-debuginfo is listed more than once in the configuration
22 Repository epel-source is listed more than once in the configuration
23 base                                                                                                                | 3.6 kB  00:00:00     
24 epel                                                                                                                | 4.7 kB  00:00:00     
25 extras                                                                                                              | 3.4 kB  00:00:00     
26 updates                                                                                                             | 3.4 kB  00:00:00     
27 (1/18): base/7/x86_64/group_gz                                                                                      | 156 kB  00:00:01     
28 (2/18): base/7/x86_64/filelists_db                                                                                  | 6.7 MB  00:00:07     
29 (3/18): base/7/x86_64/primary_db                                                                                    | 5.7 MB  00:00:06     
30 (4/18): epel/x86_64/group_gz                                                                                        | 266 kB  00:00:01     
31 (5/18): epel/x86_64/updateinfo                                                                                      | 899 kB  00:00:02     
32 (6/18): epel/x86_64/prestodelta                                                                                     | 7.1 kB  00:00:00     
33 (7/18): base/7/x86_64/other_db                                                                                      | 2.5 MB  00:00:05     
34 (8/18): epel/x86_64/primary_db                                                                                      | 6.3 MB  00:00:04     
35 (9/18): extras/7/x86_64/filelists_db                                                                                | 636 kB  00:00:00     
36 (10/18): extras/7/x86_64/primary_db                                                                                 | 166 kB  00:00:00     
37 (11/18): extras/7/x86_64/other_db                                                                                   | 108 kB  00:00:00     
38 (12/18): extras/7/x86_64/prestodelta                                                                                | 102 kB  00:00:01     
39 (13/18): epel/x86_64/other_db                                                                                       | 3.0 MB  00:00:01     
40 (14/18): epel/x86_64/filelists_db                                                                                   |  10 MB  00:00:09     
41 (15/18): updates/7/x86_64/filelists_db                                                                              | 3.5 MB  00:00:02     
42 (16/18): updates/7/x86_64/prestodelta                                                                               | 771 kB  00:00:02     
43 (17/18): updates/7/x86_64/other_db                                                                                  | 621 kB  00:00:00     
44 (18/18): updates/7/x86_64/primary_db                                                                                | 6.0 MB  00:00:03     
45 Determining fastest mirrors
46  * epel: mirrors.aliyun.com
47 Metadata Cache Created

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

 1 [root@bogon yum.repos.d]# yum repolist enabled
 2 Loaded plugins: fastestmirror, langpacks
 3 Repository base is listed more than once in the configuration
 4 Repository updates is listed more than once in the configuration
 5 Repository extras is listed more than once in the configuration
 6 Repository centosplus is listed more than once in the configuration
 7 Repository epel is listed more than once in the configuration
 8 Repository epel-debuginfo is listed more than once in the configuration
 9 Repository epel-source is listed more than once in the configuration
10 Loading mirror speeds from cached hostfile
11  * epel: mirrors.aliyun.com
12 repo id                                            repo name                                                                         status
13 base/7/x86_64                                      CentOS-7 - Base - 163.com                                                          9,591
14 epel/x86_64                                        Extra Packages for Enterprise Linux 7 - x86_64                                    12,382
15 extras/7/x86_64                                    CentOS-7 - Extras - 163.com                                                          390
16 updates/7/x86_64                                   CentOS-7 - Updates - 163.com                                                       1,941
17 repolist: 24,304
18 
19 [root@bogon yum.repos.d]# yum repolist all
20 Loaded plugins: fastestmirror, langpacks
21 Repository base is listed more than once in the configuration
22 Repository updates is listed more than once in the configuration
23 Repository extras is listed more than once in the configuration
24 Repository centosplus is listed more than once in the configuration
25 Repository epel is listed more than once in the configuration
26 Repository epel-debuginfo is listed more than once in the configuration
27 Repository epel-source is listed more than once in the configuration
28 Loading mirror speeds from cached hostfile
29  * epel: mirrors.aliyun.com
30 repo id                                     repo name                                                                       status
31 base/7/x86_64                               CentOS-7 - Base - 163.com                                                       enabled:  9,591
32 centosplus/7/x86_64                         CentOS-7 - Plus - 163.com                                                       disabled
33 contrib/7/x86_64                            CentOS-7 - Contrib - mirrors.aliyun.com                                         disabled
34 epel/x86_64                                 Extra Packages for Enterprise Linux 7 - x86_64                                  enabled: 12,382
35 epel-debuginfo/x86_64                       Extra Packages for Enterprise Linux 7 - x86_64 - Debug                          disabled
36 epel-source                                 Extra Packages for Enterprise Linux 7 - x86_64 - Source                         disabled
37 epel-testing/x86_64                         Extra Packages for Enterprise Linux 7 - Testing - x86_64                        disabled
38 epel-testing-debuginfo/x86_64               Extra Packages for Enterprise Linux 7 - Testing - x86_64 - Debug                disabled
39 epel-testing-source/x86_64                  Extra Packages for Enterprise Linux 7 - Testing - x86_64 - Source               disabled
40 extras/7/x86_64                             CentOS-7 - Extras - 163.com                                                     enabled:    390
41 updates/7/x86_64                            CentOS-7 - Updates - 163.com                                                    enabled:  1,941
42 repolist: 24,304

转载自:https://www.cnblogs.com/renpingsheng/p/7845096.html

猜你喜欢

转载自www.cnblogs.com/ckqq/p/9826151.html