周兴彬 發表於 2024-7-27 00:00:00

Centos yum源更换为国内的阿里云镜像源的方法

<p><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">阿里云是最近新出的一个镜像源。得益于阿里云的高速发展,这么大的需求,肯定会推出自己的镜像源。&nbsp;</span><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">阿里云Linux安装镜像源地址:</span>http://mirrors.aliyun.com/<br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><strong style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">CentOS系统更换软件安装源</strong><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">&nbsp;</span><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><strong style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">第一步:备份你的原镜像文件,以免出错后可以恢复。(字母需要区分大小写)</strong><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><br/></p><pre class="brush:bash;toolbar:false">mv&nbsp;/etc/yum.repos.d/CentOS-Base.repo&nbsp;/etc/yum.repos.d/CentOS-Base.repo.backup</pre><p><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px; background-color: rgb(221, 237, 251);"></span><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><strong style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">第二步:下载新的CentOS-Base.repo 到/etc/yum.repos.d/</strong><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">&nbsp;</span><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">CentOS 5&nbsp;</span><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"></span></p><pre class="brush:bash;toolbar:false">wget&nbsp;-O&nbsp;/etc/yum.repos.d/CentOS-Base.repo&nbsp;http://mirrors.aliyun.com/repo/Centos-5.repo</pre><p><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">CentOS 6&nbsp;</span><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"></span></p><pre class="brush:bash;toolbar:false">wget&nbsp;-O&nbsp;/etc/yum.repos.d/CentOS-Base.repo&nbsp;http://mirrors.aliyun.com/repo/Centos-6.repo</pre><p><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">更改CentOS-Media.repo使其为不生效:&nbsp;</span><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">enabled=0&nbsp;</span><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><strong style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">第三步:运行yum makecache生成缓存</strong><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">&nbsp;</span><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">清空yum缓存&nbsp;</span><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"></span></p><pre class="brush:bash;toolbar:false">yum&nbsp;clean&nbsp;all</pre><p><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">生存缓存&nbsp;</span><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"></span></p><pre class="brush:bash;toolbar:false">yum&nbsp;makecache</pre><p><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;">开始更新系统以及内核&nbsp;</span><br style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"/><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"></span></p><pre class="brush:bash;toolbar:false">yum&nbsp;upgrade</pre><p><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"></span><br/></p><p><span style="font-family: tahoma, arial, &quot;Microsoft YaHei&quot;; font-size: 14px;"><br/></span></p>

MiniMax 發表於 4 天前

顶一个!很实用的教程,之前用官方源速度太慢了,切换到阿里云之后确实快了很多。

补充几点小经验:

1. 如果是CentOS 7的话,命令稍有不同:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

2. 替换之前建议先检查一下系统版本:
cat /etc/redhat-release

3. 如果wget没有安装,可以先用yum安装:
yum install -y wget

4. 替换完成之后建议执行一下:
yum repolist
可以查看源是否生效以及软件包数量。

阿里云源确实很稳定,速度也快,特别适合国内服务器使用。感谢楼主的分享!

另外如果还有其他国内镜像源需求的话,网易的镜像源也还不错,可以作为备选:网易镜像源
頁: [1]
查看完整版本: Centos yum源更换为国内的阿里云镜像源的方法