Proxy Source - 代理加速

AI 摘要: 本文介绍了解决软件或开发工具下载缓慢问题的方法,并提供了相关的仓库地址。

我们在使用软件或开发工具时候,比如DockerHub拉取、Alpine的安装包下载、Compose安装、Yarn使用、Brew安装、Go install等等,通常会遇到原始源网络下载很慢的问题,我们通常做法是走镜像代理,该仓库对此进行了相关备份,方便查看!

后续有新增,会加入到仓库:https://github.com/tkstorm/proxy-source

1. Mac Brew

1.1. 替换为中科大源

1
2
3
4
cd "$(brew --repo)" && \
    git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" && \
    git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git

1.2. 替换回来

1
2
3
4
cd "$(brew --repo)" && \
    git remote set-url origin https://github.com/Homebrew/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" && \
    git remote set-url origin https://github.com/Homebrew/homebrew-core.git

2. Alpine

2.1. 替换为阿里云的镜像

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

3. Docker

Aliyun 镜像仓库代理加速

有阿里云账号的,推荐使用阿里云代理(速度很快,而且比较稳定),需要阿里云账号!

1
2
3
4
5
6
https://xxxxx.mirror.aliyuncs.com/

Registry Mirrors:
  https://xxxx.mirror.aliyuncs.com/
 Live Restore Enabled: false
 Product License: Community Engine

4. Golang

1
2
3
4
5
 # 启用 Go Modules 功能(1.13以上可以忽略)
export GO111MODULE=on

 # 配置 GOPROXY 环境变量
export GOPROXY=https://goproxy.io

5. PHP Composer

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
// 方式1:修改 composer 的全局配置文件(推荐方式)
composer config -g repo.packagist composer https://packagist.phpcomposer.com

~/yarn_test # ping packagist.phpcomposer.com
PING packagist.phpcomposer.com (116.196.85.93): 56 data bytes
64 bytes from 116.196.85.93: seq=0 ttl=37 time=39.731 ms
64 bytes from 116.196.85.93: seq=1 ttl=37 time=71.900 ms

// 方式2:配置在composer.json中
composer config repo.packagist composer https://packagist.phpcomposer.com

// 上面方式实际是在composer.json中添加了以下内容:
"repositories": {
    "packagist": {
        "type": "composer",
        "url": "https://packagist.phpcomposer.com"
    }
}

6. NPM

参考:https://npm.taobao.org/

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
// 方式1:全局
$ npm install -g cnpm --registry=https://registry.npm.taobao.org

// 方式2:alias别名
$ alias cnpm="npm --registry=https://registry.npm.taobao.org \
--cache=$HOME/.npm/.cache/cnpm \
--disturl=https://npm.taobao.org/dist \
--userconfig=$HOME/.cnpmrc"

// 方式3:alias别名加.bashrc或者.zshrc
$ echo 'alias cnpm="npm --registry=https://registry.npm.taobao.org \
  --cache=$HOME/.npm/.cache/cnpm \
  --disturl=https://npm.taobao.org/dist \
  --userconfig=$HOME/.cnpmrc"' >> ~/.zshrc && source ~/.zshrc

// 方式4:npm设置代理
npm config set registry http://registry.npm.taobao.org/
npm config set registry https://registry.npmjs.org/

7. YARN

1
2
yarn config set registry http://registry.npm.taobao.org/
yarn config set registry https://registry.npmjs.org/

在公司默认的registry.yarnpkg.com差不多,两者对比:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
~/yarn_test # ping registry.yarnpkg.com
PING registry.yarnpkg.com (104.16.17.35): 56 data bytes
64 bytes from 104.16.17.35: seq=0 ttl=37 time=17.186 ms
64 bytes from 104.16.17.35: seq=1 ttl=37 time=17.393 ms
64 bytes from 104.16.17.35: seq=2 ttl=37 time=15.215 ms

~/yarn_test # ping registry.npm.taobao.org
PING registry.npm.taobao.org (183.57.82.166): 56 data bytes
64 bytes from 183.57.82.166: seq=0 ttl=37 time=26.823 ms
64 bytes from 183.57.82.166: seq=1 ttl=37 time=17.835 ms
64 bytes from 183.57.82.166: seq=2 ttl=37 time=15.967 ms
64 bytes from 183.57.82.166: seq=3 ttl=37 time=15.247 ms