[Centos系统] CentOS 7.9 快速更换 阿里云源教程

981 0
Honkers 2025-3-6 04:20:11 | 显示全部楼层 |阅读模式

CentOS 7.9 更换源教程

总结

  1. # 下载 wget
  2. yum -y install wget
  3. # 备份 yum 源
  4. mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
  5. # 下载阿里云的yum源到 /etc/yum.repos.d/
  6. # 此处以 CentOS 7 为例,如果是其它版本或者系统的话,请看:http://mirrors.aliyun.com/repo/
  7. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  8. # 清除缓存
  9. yum clean all
  10. # 更新本地 yum 缓存
  11. yum makecache
  12. # 更新 yum 中的所有软件包
  13. yum -y update
复制代码

以下是步骤!!

查看版本

  1. cat /etc/redhat-release
复制代码

https://blog.csdn.net/XiaoXinYAYAYA/article/details/139620079

CentOS 7是一个使用比较广泛,也比较流行的Linux发行版,但是默认的yum源常常无法满足我们的需求。以下是以阿里源为例的详细换源教程。

1、备份原有源文件

备份原有的源文件,以备不时之需。命令如下:

  1. sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
复制代码

2、安装依赖工具

  1. sudo yum install -y wget
复制代码

3、更换源

下载新的源文件,指令如下:

  1. sudo wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
复制代码

出现问题 需要增加dns解析!

输入

  1. vim /etc/resolv.conf
复制代码

添加DNS地址:

  1. nameserver 8.8.8.8
  2. nameserver 8.8.4.4
  3. nameserver 223.5.5.5
  4. nameserver 223.6.6.6
复制代码

当然不想下载,也可以采取如下方法:

  1. sudo vi /etc/yum.repos.d/CentOS-Base.repo
复制代码

然后直接复制下内容:

  1. # CentOS-Base.repo
  2. #
  3. # The mirror system uses the connecting IP address of the client and the
  4. # update status of each mirror to pick mirrors that are updated to and
  5. # geographically close to the client. You should use this for CentOS updates
  6. # unless you are manually picking other mirrors.
  7. #
  8. # If the mirrorlist= does not work for you, as a fall back you can try the
  9. # remarked out baseurl= line instead.
  10. #
  11. #
  12. [base]
  13. name=CentOS-$releasever - Base - mirrors.aliyun.com
  14. failovermethod=priority
  15. baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
  16. http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
  17. http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
  18. gpgcheck=1
  19. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  20. #released updates
  21. [updates]
  22. name=CentOS-$releasever - Updates - mirrors.aliyun.com
  23. failovermethod=priority
  24. baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
  25. http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
  26. http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
  27. gpgcheck=1
  28. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  29. #additional packages that may be useful
  30. [extras]
  31. name=CentOS-$releasever - Extras - mirrors.aliyun.com
  32. failovermethod=priority
  33. baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
  34. http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
  35. http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
  36. gpgcheck=1
  37. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  38. #additional packages that extend functionality of existing packages
  39. [centosplus]
  40. name=CentOS-$releasever - Plus - mirrors.aliyun.com
  41. failovermethod=priority
  42. baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
  43. http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
  44. http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
  45. gpgcheck=1
  46. enabled=0
  47. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  48. #contrib - packages by Centos Users
  49. [contrib]
  50. name=CentOS-$releasever - Contrib - mirrors.aliyun.com
  51. failovermethod=priority
  52. baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
  53. http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
  54. http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
  55. gpgcheck=1
  56. enabled=0
  57. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
复制代码

保存退出,操作如下:

  1. 1、按Esc
  2. 2、输入:wq!
  3. 3、按Enter
复制代码

4、生成缓存

配置新的源后,需要清理yum的旧缓存并生成新缓存,指令如下:

  1. sudo yum clean all
  2. sudo yum makecache
复制代码

5、检查新源

输入以下指令:

  1. yum repolist
复制代码

如图:

如果输出中包含了阿里源,则证明已换源成功。

6、测试新源

我们随便搜索一个软件包,比如nginx:

  1. yum search nginx
复制代码

7、其他源

如果想使用其他的源,替换对应的链接或内容即可。

网易源:

http://mirrors.163.com/.help/CentOS7-Base-163.repo

对应内容:

  1. # CentOS-Base.repo
  2. #
  3. # The mirror system uses the connecting IP address of the client and the
  4. # update status of each mirror to pick mirrors that are updated to and
  5. # geographically close to the client. You should use this for CentOS updates
  6. # unless you are manually picking other mirrors.
  7. #
  8. # If the mirrorlist= does not work for you, as a fall back you can try the
  9. # remarked out baseurl= line instead.
  10. #
  11. #
  12. [base]
  13. name=CentOS-$releasever - Base - 163.com
  14. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
  15. baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
  16. gpgcheck=1
  17. gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
  18. #released updates
  19. [updates]
  20. name=CentOS-$releasever - Updates - 163.com
  21. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
  22. baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
  23. gpgcheck=1
  24. gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
  25. #additional packages that may be useful
  26. [extras]
  27. name=CentOS-$releasever - Extras - 163.com
  28. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
  29. baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
  30. gpgcheck=1
  31. gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
  32. #additional packages that extend functionality of existing packages
  33. [centosplus]
  34. name=CentOS-$releasever - Plus - 163.com
  35. baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
  36. gpgcheck=1
  37. enabled=0
  38. gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
复制代码

若还需其他源,请自行搜集。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2026 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行