logo
1
1
WeChat Login

Mirrors

智能镜像源路由服务 —— 根据客户端 IP 的地理位置和 ISP 信息,自动 307 重定向到最优的镜像站。

支持 APT 软件源和 Docker Registry 镜像,覆盖国内主流云厂商内网源与高校/公网源。

一键换源

bash <(curl -sSL mirrors.bring.host/install.sh)

支持 Debian、Ubuntu、Alpine、Arch Linux 等发行版,自动检测系统并配置。也可指定协议:

PROTOCOL=https bash <(curl -sSL mirrors.bring.host/install.sh)

工作原理

客户端请求 → 解析客户端 IP → 查询 IP 归属(ISP/地域)→ 匹配路由规则 → 307 重定向到最优镜像
  • 规则优先:按顺序匹配 ISP/CIDR/地域规则,命中即返回对应镜像
  • 加权随机兜底:无规则命中时,从健康的公网镜像中按优先级加权随机选择
  • 云厂商内网加速:阿里云、腾讯云、华为云、火山引擎等请求自动路由到对应内网源

支持的镜像类型

类型路径说明
APT/debian/, /ubuntu/ ...Debian、Ubuntu、CentOS、Alpine 等 20+ 发行版
Docker/v2/Docker Hub、ghcr.io、gcr.io、registry.k8s.io、quay.io、mcr、nvcr
Go Modules/go/goproxy.cn、阿里云、腾讯云、华为云
PyPI/pypi/simple/阿里云、腾讯云、华为云、清华、USTC、北外、南大、上交、浙大
npm/npm/npmmirror(淘宝)、腾讯云、华为云、清华、USTC

快速开始

Docker 部署

docker run -d \
  --name mirrors \
  -p 8080:8080 \
  -v ./config.json:/config.json \
  docker.cnb.cool/bring/tools/mirrors:latest

生成配置文件

内置的 generate 工具会探测所有镜像源的可用性,自动生成配置:

go run ./cmd/generate -configs configs -output config.json

该工具会:

  1. 读取 configs/ 目录下的所有 YAML 探测配置
  2. 对每个镜像站发起健康检查(HEAD 请求)
  3. 按延迟排序并分配优先级
  4. 输出合并后的 config.json 供服务加载

APT 源

将 APT sources 中的域名替换为本服务地址,或使用一键脚本自动配置:

deb http://mirrors.bring.host/debian bookworm main contrib non-free non-free-firmware
deb http://mirrors.bring.host/debian-security bookworm-security main contrib non-free non-free-firmware
deb http://mirrors.bring.host/ubuntu noble main restricted universe multiverse

Docker Registry

配置为 Docker registry mirror,支持 Docker Hub 及 ghcr.io、gcr.io、registry.k8s.io、quay.io 等:

{
  "registry-mirrors": ["http://mirrors.bring.host"]
}

拉取其他 registry 的镜像时,在 image 路径前加上 registry 域名:

docker pull mirrors.bring.host/library/nginx:latest
docker pull mirrors.bring.host/ghcr.io/owner/image:tag
docker pull mirrors.bring.host/gcr.io/project/image:tag

Go Modules

export GOPROXY=http://mirrors.bring.host/go/,direct

或写入 ~/.bashrc / ~/.zshrc 永久生效。自动路由到 goproxy.cn、阿里云、腾讯云等 Go proxy 镜像。

npm

npm config set registry http://mirrors.bring.host/npm/

PyPI

pip install -i http://mirrors.bring.host/pypi/simple/ --trusted-host mirrors.bring.host <package>

或写入 ~/.pip/pip.conf

[global]
index-url = http://mirrors.bring.host/pypi/simple/
trusted-host = mirrors.bring.host

环境变量

变量默认值说明
LISTEN_ADDR:8080监听地址
CONFIG_FILEconfig.json本地配置文件路径
CONFIG_API_URL-远程配置 API 地址(优先于本地文件)
CONFIG_API_AUTH-远程配置 API 的 Authorization 头
CONFIG_RELOAD_INTERVAL5m配置热重载间隔
IP_API_URLhttps://api.bring.cool/ip/IP 归属查询 API
IP_API_AUTH-IP API 的 Authorization 头

路由规则

configs/settings.yml 中定义路由规则,支持按 ISP、CIDR、地域匹配:

rules:
  - name: aliyun-internal
    match:
      isp: [阿里云]
    targets:
      apt: aliyun

  - name: tencent-internal
    match:
      isp: [腾讯云]
    targets:
      apt: tencent
      docker.hub: tencent-internal

defaults:
  apt: tencent
  docker: 1ms

规则按顺序求值,首个匹配的规则生效。所有 match 条件为 AND 逻辑。

API

路径说明
GET /health健康检查
ANY /v2/*Docker Registry v2 API 代理
GET /<distro>/*APT 镜像重定向

构建

# 本地构建
go build -o mirrors .

# Docker 构建
docker build -t mirrors .

License

MIT

About

No description, topics, or website provided.
Mirrorsrepo-named
Language
Go61.9%
Shell25.5%
HTML12%
Dockerfile0.6%