Comment on page
国内常用加速源使用及配置
sudo vim /etc/apt/sources.list
#阿里稳定源:
deb [by-hash=force] http://mirrors.aliyun.com/deepin lion main contrib non-free
#阿里不稳定源:
deb [by-hash=force] http://mirrors.aliyun.com/deepin panda main contrib non-free
sudo apt-get -o Acquire::http::proxy="socks5h://127.0.0.1:1080/" update
npm config set registry http://registry.npmjs.org/
npm set registry https://registry.npm.taobao.org
npm config set registry http://mirrors.cloud.tencent.com/npm/
yarn config set registry https://registry.npm.taobao.org
yarn config set registry http://mirrors.cloud.tencent.com/npm/
pypi 镜像每 5 分钟同步一次。
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
注意,simple 不能少, 是 https 而不是 http
升级 pip 到最新的版本 (>=10.0.0) 后进行配置:
pip3 install pip -U
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
Github国内加速克隆及下载 fastgit.org
https://doc.fastgit.org/
gitclone.com
https://gitclone.com/
gitee
https://gitee.com/mirrors
cnpmjs.org
https://github.com.cnpmjs.org/
#原地址 git clone
https://github.com/kubernetes/kubernetes.git
#改为 git clone
https://github.com.cnpmjs.org/kubernetes/kubernetes.git
#或者 git clone
https://hub.fastgit.org/kubernetes/kubernetes.git
#或者 git clone
https://gitclone.com/github.com/kubernetes/kubernetes.git
#原地址 wget
https://github.com/goharbor/harbor/releases/download/v2.0.2/harbor-offline-installer-v2.0.2.tgz
#改为 wget
https://hub.fastgit.org/goharbor/harbor/releases/download/v2.0.2/harbor-offline-installer-v2.0.2.tgz
#免替换方法
git config --global url."https://hub.fastgit.org".insteadOf
https://github.com
#测试 git clone
https://github.com/kubernetes/kubernetes.git
查看git配置信息
git config --global --list
取消设置
git config --global --unset url.https://github.com/.insteadof
#原地址: wget
https://raw.githubusercontent.com/kubernetes/kubernetes/master/README.md
#替换为 wget
https://raw.staticdn.net/kubernetes/kubernetes/master/README.md
GitHub 文件加速:https://gh.api.99988866.xyz/
Github 仓库加速:https://github.zhlh6.cn/
Github 仓库加速:http://toolwa.com/github/
众所周知,国内网络访问国外资源经常会出现不稳定的情况,Go 生态系统中有着许多中国 Gopher 们无法获取的模块,比如最著名的 golang.org/x/...。并且在中国大陆从 GitHub 获取模块的速度也有点慢。
因此设置 CDN 加速代理就很有必要了,以下是几个速度不错的提供者:
- 阿里: mirrors.aliyun.com/goproxy/
在 Linux 或 macOS 上面,需要运行下面命令(或者,可以把以下命令写到
.bashrc
或 .bash_profile
文件中):# 启用 Go Modules 功能
go env -w GO111MODULE=on
# 配置 GOPROXY 环境变量,以下三选一
# 1. 七牛 CDN
go env -w GOPROXY=https://goproxy.cn,direct
# 2. 阿里云
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
# 3. 官方
go env -w GOPROXY=https://goproxy.io,direct
确认一下:
go env | grep GOPROXY
GOPROXY="https://goproxy.cn"
在 Windows 上,需要运行下面命令:
# 启用 Go Modules 功能
$env:GO111MODULE="on"
# 配置 GOPROXY 环境变量,以下三选一
# 1. 七牛 CDN
$env:GOPROXY="https://goproxy.cn,direct"
# 2. 阿里云
$env:GOPROXY="https://mirrors.aliyun.com/goproxy/,direct"
# 3. 官方
$env:GOPROXY="https://goproxy.io,direct"
本地 如果有模块缓存,可以使用命令清空
go clean --modcache
如果你使用的 Go 版本 >=1.13, 你可以通过设置 GOPRIVATE 环境变量来控制哪些私有仓库和依赖 (公司内部仓库) 不通过 proxy 来拉取,直接走本地,设置如下:
# Go version >= 1.13
go env -w GOPROXY=https://goproxy.cn,direct
# 设置不走 proxy 的私有仓库,多个用逗号相隔
go env -w GOPRIVATE=*.corp.example.com
针对Docker客户端版本大于 1.10.0 的用户
您可以通过修改daemon配置文件
/etc/docker/daemon.json
来使用加速器sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://u13zwy2w.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker