Press "Enter" to skip to content

如何修改软件源为国内加速镜像

目的

由于众所周知的网络原因 6,我们在进行各类技术活动时经常遇到各类问题,本文仅解决各类Linux系统的的软件源的配置问题,将软件源配置为国内的镜像。

修改原理

软件源的修改比较简单,各类系统只需要修改对应的包管理工具 12的源配置文件即可。

国内镜像

国内的软件源镜像比较多,个人推荐 aliyun 的软件源,毕竟aliyun是作为基础的服务支撑,当前云基础服务的提供商应该值得信赖,好雨的公有云容器平台 9也使用了阿里云的计算资源。

通用

教育网

除了上面列出比较常用的之前,还有更多的镜像加速 28,请根据自己的网络情况选择合适的镜像源。

各系统软件源修改方法

下面各类系统以修改为阿里云的镜像源为示例进行说明。

CentOS

# 备份原文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

# 下载新的CentOS-Base.repo 到/etc/yum.repos.d/

#CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

#CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

#CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# 生成缓存
yum makecache

Debina

系统代号版本
squeeze6.x
wheezy7.x
jessie8.x

下面的修改以 jessie(8.x)为例:

# 备份原文件
mv /etc/apt/sources.list /etc/apt/sources.list.bak

# 修改为阿里云的镜像源
cat > /etc/apt/sources.list << END
deb http://mirrors.aliyun.com/debian/ jessie main non-free contrib
deb http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ jessie main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib
END

# 更新源列表信息
apt-get update 

Ubuntu

系统代号版本LTS
precise12.04true
trusty14.04true
vivid15.04
xenial16.04true
zesty17.04

下面的修改以 trusty(14.04)为例:

# 备份原文件
mv /etc/apt/sources.list /etc/apt/sources.list.bak

# 修改为阿里云的镜像源
cat > /etc/apt/sources.list << END
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
END

# 更新源列表信息
apt-get update 

Alpine

目前Docker镜像越来越倾向于使用Alpine系统作为基础的系统镜像,Docker Hub 官方制作的镜像都在逐步支持Alpine系统。

下面的修改以 Alpine 3.4 为例:


# 备份原始文件
cp /etc/apk/repositories /etc/apk/repositories.bak

# 修改为国内镜像源
echo "http://mirrors.aliyun.com/alpine/v3.4/main/" > /etc/apk/repositories

引自:https://t.goodrain.com/t/topic/236

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注