镜像仓库大全

镜像仓库大全

概述

在国内网络环境下,访问官方源和镜像仓库可能会遇到速度慢或连接不稳定的问题。本文档汇总了常用操作系统、开发语言和工具的镜像仓库配置方法,帮助快速切换至国内加速源。


操作系统镜像源

Alpine

sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
apk update

Ubuntu

sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
apt update

Debian

Debian 9-11(归档源)

cat > /etc/apt/sources.list <<EOF
# 阿里云 Debian 10 (Buster) 归档源
deb http://mirrors.aliyun.com/debian-archive/debian/ buster main non-free contrib
deb-src http://mirrors.aliyun.com/debian-archive/debian/ buster main non-free contrib

# 归档更新源
deb http://mirrors.aliyun.com/debian-archive/debian/ buster-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian-archive/debian/ buster-updates main non-free contrib

# 归档安全更新源
deb http://mirrors.aliyun.com/debian-archive/debian-security/ buster/updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian-archive/debian-security/ buster/updates main non-free contrib
EOF

apt update

Debian 12

sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources
sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources
apt update

CentOS 7

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache

Rocky Linux 9

sed -e 's|^mirrorlist=|#mirrorlist=|g' \
    -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
    -i.bak \
    /etc/yum.repos.d/[Rr]ocky*.repo

dnf makecache

编程语言镜像源

Python(pip)

临时配置

pip install [包名] -i https://mirrors.aliyun.com/pypi/simple/

永久配置

# 设置阿里云源为全局默认
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

# 验证是否配置成功
pip config get global.index-url

Golang

临时配置

# 写入 Go 环境配置(跨终端生效)
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct

# 查看所有 Go 环境变量,确认 GOPROXY 已修改
go env

永久配置

~/.bashrc~/.zshrc 中添加:

export GOPROXY=https://mirrors.aliyun.com/goproxy/,direct

npm

临时配置

npm install [包名] --registry=https://registry.npmmirror.com

永久配置

# 设置 npm 全局镜像源为淘宝源
npm config set registry https://registry.npmmirror.com

# 验证是否设置成功
npm config get registry

Docker 镜像源

# 编辑 Docker 配置文件
sudo vi /etc/docker/daemon.json

# 添加以下内容
{
  "registry-mirrors": [
    "https://docker.mirrors.ustc.edu.cn",
    "https://hub-mirror.c.163.com",
    "https://mirror.baidubce.com"
  ]
}

# 重启 Docker
sudo systemctl restart docker

网络代理配置

Linux 流量代理

# HTTP/HTTPS 代理
export http_proxy="http://10.0.0.82:7890"
export https_proxy="http://10.0.0.82:7890"

# SOCKS5 代理
export socks_proxy="socks5://10.0.0.82:7890"
export SOCKS_PROXY="socks5://10.0.0.82:7890"

永久代理配置

~/.bashrc~/.zshrc 中添加:

export http_proxy="http://10.0.0.82:7890"
export https_proxy="http://10.0.0.82:7890"
export socks_proxy="socks5://10.0.0.82:7890"

取消代理

unset http_proxy https_proxy socks_proxy SOCKS_PROXY

常见镜像源汇总

类型 官方源 阿里云 清华 中科大
Alpine dl-cdn.alpinelinux.org mirrors.aliyun.com mirrors.tuna.tsinghua.edu.cn mirrors.ustc.edu.cn
Ubuntu archive.ubuntu.com mirrors.aliyun.com mirrors.tuna.tsinghua.edu.cn mirrors.ustc.edu.cn
Debian deb.debian.org mirrors.aliyun.com mirrors.tuna.tsinghua.edu.cn mirrors.ustc.edu.cn
CentOS mirror.centos.org mirrors.aliyun.com mirrors.tuna.tsinghua.edu.cn mirrors.ustc.edu.cn
PyPI pypi.org mirrors.aliyun.com/pypi mirrors.tuna.tsinghua.edu.cn/pypi mirrors.ustc.edu.cn/pypi
npm registry.npmjs.org registry.npmmirror.com
Go proxy.golang.org mirrors.aliyun.com/goproxy mirrors.aliyun.com/goproxy

常见问题与注意事项

源配置不生效

检查配置文件是否有语法错误:

# Debian/Ubuntu
apt update 2>&1 | grep -i error

# CentOS/Rocky
yum repolist -v

# Alpine
apk update -v

HTTPS 证书问题

部分旧系统可能缺少 CA 证书,可临时使用 HTTP 源或安装证书包:

# Ubuntu/Debian
apt install -y ca-certificates

# CentOS/Rocky
yum install -y ca-certificates

# Alpine
apk add ca-certificates

pip 使用企业内网代理

pip install [包名] --proxy http://proxy.example.com:8080

Docker 拉取镜像超时

确认 Docker 镜像源配置正确后重启 Docker:

sudo systemctl daemon-reload
sudo systemctl restart docker

参考链接