centos7 配置国内yum源和epel源

深碍√TFBOYSˉ_ 2021-08-29 15:36 501阅读 0赞

组合脚本:

  1. yum install -y wget
  2. cd /etc/yum.repos.d/
  3. mkdir repo_bak
  4. mv *.repo repo_bak/
  5. wget http://mirrors.aliyun.com/repo/Centos-7.repo
  6. yum clean all
  7. yum makecache
  8. yum install -y epel-release
  9. wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
  10. yum clean all
  11. yum makecache
  12. yum repolist enabled

详细分解如下:

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

  1. [root@bogon ~]# cd /etc/yum.repos.d/
  2. [root@bogon yum.repos.d]# mkdir repo_bak
  3. [root@bogon yum.repos.d]# mv *.repo repo_bak/

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

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

  1. [root@bogon yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
  2. [root@bogon yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
  3. [root@bogon yum.repos.d]# ls
  4. 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. [root@bogon yum.repos.d]# yum clean all # 清除系统所有的yum缓存
  4. Loaded plugins: fastestmirror, langpacks
  5. Repository base is listed more than once in the configuration
  6. Repository updates is listed more than once in the configuration
  7. Repository extras is listed more than once in the configuration
  8. Repository centosplus is listed more than once in the configuration
  9. Cleaning repos: base extras updates
  10. Cleaning up everything
  11. Cleaning up list of fastest mirrors
  12. [root@bogon yum.repos.d]# yum makecache # 生成yum缓存
  13. Loaded plugins: fastestmirror, langpacks
  14. Repository base is listed more than once in the configuration
  15. Repository updates is listed more than once in the configuration
  16. Repository extras is listed more than once in the configuration
  17. Repository centosplus is listed more than once in the configuration
  18. base | 3.6 kB 00:00:00
  19. extras | 3.4 kB 00:00:00
  20. updates | 3.4 kB 00:00:00
  21. (1/12): base/7/x86_64/filelists_db | 6.7 MB 00:00:02
  22. (2/12): base/7/x86_64/group_gz | 156 kB 00:00:02
  23. (3/12): base/7/x86_64/other_db | 2.5 MB 00:00:01
  24. (4/12): base/7/x86_64/primary_db | 5.7 MB 00:00:02
  25. (5/12): extras/7/x86_64/prestodelta | 51 kB 00:00:01
  26. (6/12): extras/7/x86_64/filelists_db | 494 kB 00:00:02
  27. (7/12): extras/7/x86_64/other_db | 86 kB 00:00:00
  28. (8/12): extras/7/x86_64/primary_db | 130 kB 00:00:01
  29. (9/12): updates/7/x86_64/prestodelta | 406 kB 00:00:01
  30. (10/12): updates/7/x86_64/filelists_db | 2.1 MB 00:00:01
  31. (11/12): updates/7/x86_64/other_db | 354 kB 00:00:00
  32. (12/12): updates/7/x86_64/primary_db | 3.6 MB 00:00:01
  33. Determining fastest mirrors
  34. 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. [root@bogon yum.repos.d]# yum install -y epel-release
  8. Loaded plugins: fastestmirror, langpacks
  9. Repository base is listed more than once in the configuration
  10. Repository updates is listed more than once in the configuration
  11. Repository extras is listed more than once in the configuration
  12. Repository centosplus is listed more than once in the configuration
  13. Loading mirror speeds from cached hostfile
  14. Resolving Dependencies
  15. --> Running transaction check
  16. ---> Package epel-release.noarch 0:7-9 will be installed
  17. --> Finished Dependency Resolution
  18. Dependencies Resolved
  19. =============================================================================================================
  20. Package Arch Version Repository Size
  21. =============================================================================================================
  22. Installing:
  23. epel-release noarch 7-9 extras 14 k
  24. Transaction Summary
  25. =============================================================================================================
  26. Install 1 Package
  27. Total download size: 14 k
  28. Installed size: 24 k
  29. Downloading packages:
  30. epel-release-7-9.noarch.rpm | 14 kB 00:00:00
  31. Running transaction check
  32. Running transaction test
  33. Transaction test succeeded
  34. Running transaction
  35. Installing : epel-release-7-9.noarch 1/1
  36. Verifying : epel-release-7-9.noarch 1/1
  37. Installed:
  38. epel-release.noarch 0:7-9
  39. Complete!
  40. [root@bogon yum.repos.d]# ls # epel源安装成功,比原来多了一个epel.repo和epel-testing.repo文件
  41. 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. 100%[=================================================================================================>] 1,084 --.-K/s in 0s
  9. 2018-03-08 20:22:14 (130 MB/s) - ‘/etc/yum.repos.d/epel-7.repo saved [1084/1084]
  10. [root@bogon yum.repos.d]# ls
  11. 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. [root@bogon yum.repos.d]# yum makecache
  14. Loaded plugins: fastestmirror, langpacks
  15. Repository base is listed more than once in the configuration
  16. Repository updates is listed more than once in the configuration
  17. Repository extras is listed more than once in the configuration
  18. Repository centosplus is listed more than once in the configuration
  19. Repository epel is listed more than once in the configuration
  20. Repository epel-debuginfo is listed more than once in the configuration
  21. Repository epel-source is listed more than once in the configuration
  22. base | 3.6 kB 00:00:00
  23. epel | 4.7 kB 00:00:00
  24. extras | 3.4 kB 00:00:00
  25. updates | 3.4 kB 00:00:00
  26. (1/18): base/7/x86_64/group_gz | 156 kB 00:00:01
  27. (2/18): base/7/x86_64/filelists_db | 6.7 MB 00:00:07
  28. (3/18): base/7/x86_64/primary_db | 5.7 MB 00:00:06
  29. (4/18): epel/x86_64/group_gz | 266 kB 00:00:01
  30. (5/18): epel/x86_64/updateinfo | 899 kB 00:00:02
  31. (6/18): epel/x86_64/prestodelta | 7.1 kB 00:00:00
  32. (7/18): base/7/x86_64/other_db | 2.5 MB 00:00:05
  33. (8/18): epel/x86_64/primary_db | 6.3 MB 00:00:04
  34. (9/18): extras/7/x86_64/filelists_db | 636 kB 00:00:00
  35. (10/18): extras/7/x86_64/primary_db | 166 kB 00:00:00
  36. (11/18): extras/7/x86_64/other_db | 108 kB 00:00:00
  37. (12/18): extras/7/x86_64/prestodelta | 102 kB 00:00:01
  38. (13/18): epel/x86_64/other_db | 3.0 MB 00:00:01
  39. (14/18): epel/x86_64/filelists_db | 10 MB 00:00:09
  40. (15/18): updates/7/x86_64/filelists_db | 3.5 MB 00:00:02
  41. (16/18): updates/7/x86_64/prestodelta | 771 kB 00:00:02
  42. (17/18): updates/7/x86_64/other_db | 621 kB 00:00:00
  43. (18/18): updates/7/x86_64/primary_db | 6.0 MB 00:00:03
  44. Determining fastest mirrors
  45. * epel: mirrors.aliyun.com
  46. 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. [root@bogon yum.repos.d]# yum repolist all
  19. Loaded plugins: fastestmirror, langpacks
  20. Repository base is listed more than once in the configuration
  21. Repository updates is listed more than once in the configuration
  22. Repository extras is listed more than once in the configuration
  23. Repository centosplus is listed more than once in the configuration
  24. Repository epel is listed more than once in the configuration
  25. Repository epel-debuginfo is listed more than once in the configuration
  26. Repository epel-source is listed more than once in the configuration
  27. Loading mirror speeds from cached hostfile
  28. * epel: mirrors.aliyun.com
  29. repo id repo name status
  30. base/7/x86_64 CentOS-7 - Base - 163.com enabled: 9,591
  31. centosplus/7/x86_64 CentOS-7 - Plus - 163.com disabled
  32. contrib/7/x86_64 CentOS-7 - Contrib - mirrors.aliyun.com disabled
  33. epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 enabled: 12,382
  34. epel-debuginfo/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 - Debug disabled
  35. epel-source Extra Packages for Enterprise Linux 7 - x86_64 - Source disabled
  36. epel-testing/x86_64 Extra Packages for Enterprise Linux 7 - Testing - x86_64 disabled
  37. epel-testing-debuginfo/x86_64 Extra Packages for Enterprise Linux 7 - Testing - x86_64 - Debug disabled
  38. epel-testing-source/x86_64 Extra Packages for Enterprise Linux 7 - Testing - x86_64 - Source disabled
  39. extras/7/x86_64 CentOS-7 - Extras - 163.com enabled: 390
  40. updates/7/x86_64 CentOS-7 - Updates - 163.com enabled: 1,941
  41. repolist: 24,304

发表评论

表情:
评论列表 (有 0 条评论,501人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Centos配置国内yum

    网易(163)yum源是国内最好的yum源之一 ,无论是速度还是软件版本,都非常的不错,将yum源设置为163yum,可以提升软件包安装和更新的速度,同时避免一些常见软件版本

    相关 Centos配置国内yum

    网易(163)yum源是国内最好的yum源之一 ,无论是速度还是软件版本,都非常的不错,将yum源设置为163yum,可以提升软件包安装和更新的速度,同时避免一些常见软件版本