CentOS 7系统配置国内yum源和epel源

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

 
  1. [[email protected] ~]# cd /etc/yum.repos.d/
  2. [[email protected] yum.repos.d]# ll
  3. drwxr-xr-x. 2 root root 187 Jun 12 2018 repo

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

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

 
  1. [[email protected] yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
  2. --2019-02-15 12:12:53-- http://mirrors.aliyun.com/repo/Centos-7.repo
  3. Resolving proxy.tencent.com (proxy.tencent.com)... 10.1.156.88
  4. Connecting to proxy.tencent.com (proxy.tencent.com)|10.1.156.88|:8080... connected.
  5. Proxy request sent, awaiting response... 200 OK
  6. Length: 2523 (2.5K) [application/octet-stream]
  7. Saving to: ‘Centos-7.repo’
  8.  
  9. 100%[==========================================================================================================>] 2,523 --.-K/s in 0s
  10.  
  11. 2019-02-15 12:12:53 (67.6 MB/s) - ‘Centos-7.repo’ saved [2523/2523]
  12.  
  13. [[email protected] yum.repos.d]# ll
  14. total 4
  15. -rw-r--r-- 1 root root 2523 Jun 16 2018 Centos-7.repo
  16. drwxr-xr-x. 2 root root 217 Feb 15 12:14 repo

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

阿里云开源镜像:阿里云开源镜像

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

 
  1. [[email protected] yum.repos.d]# yum clean all #清除系统所有的yum缓存
  2. Loaded plugins: fastestmirror, langpacks
  3. Cleaning repos: base extras updates
  4. Cleaning up everything
  5. Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
  6. Cleaning up list of fastest mirrors
  7.  
  8.  
  9. [[email protected] yum.repos.d]# yum makecache # 生成yum缓存
  10. Loaded plugins: fastestmirror, langpacks
  11. Determining fastest mirrors
  12. * base: mirrors.aliyun.com
  13. * extras: mirrors.aliyun.com
  14. * updates: mirrors.aliyun.com
  15. base | 3.6 kB 00:00:00
  16. extras | 3.4 kB 00:00:00
  17. updates | 3.4 kB 00:00:00
  18. (1/12): base/7/x86_64/group_gz | 166 kB 00:00:00
  19. base/7/x86_64/primary_db FAILED
  20. http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/6614b3605d961a4aaec45d74ac4e5e713e517debb3ee454a1c91097955780697-primary.sqlite.bz2: [Errno 14] HTTP Error 504 - Gateway Timeout
  21. Trying other mirror.
  22. (2/12): extras/7/x86_64/filelists_db | 230 kB 00:00:00
  23. (3/12): extras/7/x86_64/primary_db | 179 kB 00:00:00
  24. (4/12): extras/7/x86_64/other_db | 117 kB 00:00:00
  25. (5/12): updates/7/x86_64/filelists_db | 1.9 MB 00:00:00
  26. (6/12): updates/7/x86_64/primary_db | 2.4 MB 00:00:00
  27. (7/12): base/7/x86_64/other_db | 2.6 MB 00:00:00
  28. (8/12): updates/7/x86_64/other_db | 331 kB 00:00:00
  29. (9/12): base/7/x86_64/primary_db | 6.0 MB 00:00:00
  30. base/7/x86_64/filelists_db FAILED
  31. http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/a0ec5a4708a1026db100d4799c404c9ed48a9371a4bab234a1355f86628a244a-filelists.sqlite.bz2: [Errno 14] HTTP Error 504 - Gateway Timeout
  32. Trying other mirror.
  33. extras/7/x86_64/prestodelta FAILED =========================- ] 228 kB/s | 17 MB 00:00:17 ETA
  34. http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/6ddc7ed4f8b31ae5fe805eb71716d60413495a98094b0b2ef5a955d6c78ab1fd-prestodelta.xml.gz: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/6ddc7ed4f8b31ae5fe805eb71716d60413495a98094b0b2ef5a955d6c78ab1fd-prestodelta.xml.gz: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
  35. Trying other mirror.
  36. (10/12): base/7/x86_64/filelists_db | 7.1 MB 00:00:00
  37. updates/7/x86_64/prestodelta FAILED
  38. http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/84a6837c67a1e571dfd5c69e155c0d4c99dfddbe6777b062c15f956ac3c0ccdc-prestodelta.xml.gz: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/84a6837c67a1e571dfd5c69e155c0d4c99dfddbe6777b062c15f956ac3c0ccdc-prestodelta.xml.gz: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
  39. Trying other mirror.
  40. (11/12): updates/7/x86_64/prestodelta | 333 kB 00:00:00
  41. (12/12): extras/7/x86_64/prestodelta | 47 kB 00:00:00
  42. Metadata Cache Created

4、安装epel源

 
  1. [[email protected] yum.repos.d]# yum list | grep epel-release
  2. epel-release.noarch 7-11 extras
  3.  
  4. [[email protected] yum.repos.d]# yum install -y epel-release
  5. Loaded plugins: fastestmirror, langpacks
  6. Loading mirror speeds from cached hostfile
  7. * base: mirrors.aliyun.com
  8. * extras: mirrors.aliyun.com
  9. * updates: mirrors.aliyun.com
  10. Resolving Dependencies
  11. --> Running transaction check
  12. ---> Package epel-release.noarch 0:7-11 will be installed
  13. --> Finished Dependency Resolution
  14.  
  15. Dependencies Resolved
  16.  
  17. ====================================================================================================================================================
  18. Package Arch Version Repository Size
  19. ====================================================================================================================================================
  20. Installing:
  21. epel-release noarch 7-11 extras 15 k
  22.  
  23. Transaction Summary
  24. ====================================================================================================================================================
  25. Install 1 Package
  26.  
  27. Total download size: 15 k
  28. Installed size: 24 k
  29. Downloading packages:
  30. warning: /var/cache/yum/x86_64/7/extras/packages/epel-release-7-11.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
  31. Public key for epel-release-7-11.noarch.rpm is not installed
  32. epel-release-7-11.noarch.rpm | 15 kB 00:00:00
  33. Retrieving key from http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  34. Importing GPG key 0xF4A80EB5:
  35. Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <[email protected]>"
  36. Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
  37. From : http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  38. Running transaction check
  39. Running transaction test
  40. Transaction test succeeded
  41. Running transaction
  42. Installing : epel-release-7-11.noarch 1/1
  43. Verifying : epel-release-7-11.noarch 1/1
  44.  
  45. Installed:
  46. epel-release.noarch 0:7-11
  47.  
  48. Complete!
  49.  
  50. # epel源安装成功,比原来多了一个epel.repo和epel-testing.repo文件
  51. [[email protected] yum.repos.d]# ll
  52. -rw-r--r-- 1 root root 2523 Jun 16 2018 Centos-7.repo
  53. -rw-r--r-- 1 root root 951 Oct 3 2017 epel.repo
  54. -rw-r--r-- 1 root root 1050 Oct 3 2017 epel-testing.repo
  55. drwxr-xr-x. 2 root root 217 Feb 15 12:14 repo

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

 
  1. [[email protected] yum.repos.d]# wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
  2. --2019-02-15 12:24:15-- http://mirrors.aliyun.com/repo/epel-7.repo
  3. Resolving proxy.tencent.com (proxy.tencent.com)... 10.1.156.88
  4. Connecting to proxy.tencent.com (proxy.tencent.com)|10.1.156.88|:8080... connected.
  5. Proxy request sent, awaiting response... 200 OK
  6. Length: 664 [application/octet-stream]
  7. Saving to: ‘/etc/yum.repos.d/epel-7.repo’
  8.  
  9. 100%[==========================================================================================================>] 664 --.-K/s in 0s
  10.  
  11. 2019-02-15 12:24:16 (1.33 MB/s) - ‘/etc/yum.repos.d/epel-7.repo’ saved [664/664]
  12.  
  13. [[email protected] yum.repos.d]# ll
  14. total 16
  15. -rw-r--r-- 1 root root 2523 Jun 16 2018 Centos-7.repo
  16. -rw-r--r-- 1 root root 664 May 11 2018 epel-7.repo
  17. -rw-r--r-- 1 root root 951 Oct 3 2017 epel.repo
  18. -rw-r--r-- 1 root root 1050 Oct 3 2017 epel-testing.repo
  19. drwxr-xr-x. 2 root root 217 Feb 15 12:14 repo

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

 
  1. [[email protected] yum.repos.d]# yum clean all
  2. Loaded plugins: fastestmirror, langpacks
  3. Repository epel is listed more than once in the configuration
  4. Repository epel-debuginfo is listed more than once in the configuration
  5. Repository epel-source is listed more than once in the configuration
  6. Cleaning repos: base epel extras updates
  7. Cleaning up everything
  8. Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
  9. Cleaning up list of fastest mirrors
  10.  
  11. [[email protected] yum.repos.d]# yum makecache
  12. Loaded plugins: fastestmirror, langpacks
  13. Repository epel is listed more than once in the configuration
  14. Repository epel-debuginfo is listed more than once in the configuration
  15. Repository epel-source is listed more than once in the configuration
  16. Determining fastest mirrors
  17. * base: mirrors.aliyun.com
  18. * extras: mirrors.aliyun.com
  19. * updates: mirrors.aliyun.com
  20. base | 3.6 kB 00:00:00
  21. epel | 4.7 kB 00:00:00
  22. extras | 3.4 kB 00:00:00
  23. updates | 3.4 kB 00:00:00
  24. (1/18): base/7/x86_64/group_gz | 166 kB 00:00:00
  25. (2/18): base/7/x86_64/filelists_db | 7.1 MB 00:00:01
  26. (3/18): epel/x86_64/group_gz | 88 kB 00:00:00
  27. (4/18): base/7/x86_64/other_db | 2.6 MB 00:00:00
  28. (5/18): epel/x86_64/updateinfo | 959 kB 00:00:00
  29. (6/18): epel/x86_64/prestodelta | 4.6 kB 00:00:00
  30. (7/18): base/7/x86_64/primary_db | 6.0 MB 00:00:01
  31. (8/18): epel/x86_64/primary_db | 6.6 MB 00:00:01
  32. (9/18): epel/x86_64/filelists_db | 11 MB 00:00:02
  33. (10/18): extras/7/x86_64/prestodelta | 47 kB 00:00:00
  34. (11/18): extras/7/x86_64/filelists_db | 230 kB 00:00:00
  35. (12/18): extras/7/x86_64/primary_db | 179 kB 00:00:00
  36. (13/18): extras/7/x86_64/other_db | 117 kB 00:00:00
  37. (14/18): updates/7/x86_64/prestodelta | 333 kB 00:00:00
  38. (15/18): epel/x86_64/other_db | 3.2 MB 00:00:00
  39. (16/18): updates/7/x86_64/filelists_db | 1.9 MB 00:00:00
  40. (17/18): updates/7/x86_64/other_db | 331 kB 00:00:00
  41. (18/18): updates/7/x86_64/primary_db | 2.4 MB 00:00:00
  42. Metadata Cache Created

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

CentOS 7系统配置国内yum源和epel源CentOS 7系统配置国内yum源和epel源
到这里,国内的yum源和epel源就配置好了,下面就可以安装软件了,很方便的哦