# 国内常用加速源使用及配置

#### 博客作者：联系请[点击](https://hezhiqiang.gitbook.io/about-the-author/lian-xi-zuo-zhe)，搬运不易，希望请作者喝咖啡，可以点击[联系博客作者](https://hezhiqiang.gitbook.io/about-the-author/lian-xi-zuo-zhe)

## Operation OS

### deepin 配置阿里源 <a href="#anchor-h2-1" id="anchor-h2-1"></a>

`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
```

## Ubuntu

### apt 配置代理 <a href="#anchor-h2-3" id="anchor-h2-3"></a>

`sudo apt-get -o Acquire::http::proxy="socks5h://127.0.0.1:1080/" update`

## NPM

### npm 配置官方源 <a href="#anchor-h2-5" id="anchor-h2-5"></a>

`npm config set registry http://registry.npmjs.org/`

### npm 配置淘宝源 <a href="#anchor-h2-6" id="anchor-h2-6"></a>

`npm set registry https://registry.npm.taobao.org`

### npm 配置腾讯源 <a href="#anchor-h2-7" id="anchor-h2-7"></a>

`npm config set registry http://mirrors.cloud.tencent.com/npm/`

### yarn 配置源 <a href="#anchor-h2-8" id="anchor-h2-8"></a>

`yarn config set registry https://registry.npm.taobao.org` `yarn config set registry http://mirrors.cloud.tencent.com/npm/`

## PiP

### pip 配置清华源 <a href="#anchor-h2-10" id="anchor-h2-10"></a>

pypi 镜像每 5 分钟同步一次。

### 临时使用 <a href="#anchor-h2-11" id="anchor-h2-11"></a>

`pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package`

注意，simple 不能少, 是 https 而不是 http

### 设为默认 <a href="#anchor-h2-12" id="anchor-h2-12"></a>

升级 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

```
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

```

### release下载加速 <a href="#anchor-h2-15" id="anchor-h2-15"></a>

```
#原地址 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
```

### raw文件下载加速 <a href="#anchor-h2-16" id="anchor-h2-16"></a>

```
#原地址： wget 
https://raw.githubusercontent.com/kubernetes/kubernetes/master/README.md

#替换为 wget 
https://raw.staticdn.net/kubernetes/kubernetes/master/README.md
```

### 提供web界面的github资源加速网站： <a href="#anchor-h2-17" id="anchor-h2-17"></a>

```
GitHub 文件加速：https://gh.api.99988866.xyz/
Github 仓库加速：https://github.zhlh6.cn/
Github 仓库加速：http://toolwa.com/github/
```

## Go&#x20;

### 说明&#x20;

众所周知，国内网络访问国外资源经常会出现不稳定的情况，Go 生态系统中有着许多中国 Gopher 们无法获取的模块，比如最著名的 golang.org/x/...。并且在中国大陆从 GitHub 获取模块的速度也有点慢。

因此设置 CDN 加速代理就很有必要了，以下是几个速度不错的提供者：

* 七牛：Goproxy 中国 <https://goproxy.cn>&#x20;
* 阿里： mirrors.aliyun.com/goproxy/&#x20;
* 官方： < 全球 CDN 加速 [https://goproxy.io/>](https://goproxy.io/>)&#x20;
* 其他：jfrog 维护 <https://gocenter.io>

### Unix 类

&#x20;在 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 类 <a href="#aea234" id="aea234"></a>

在 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"
```

{% hint style="info" %}
&#x20;本地如果有模块缓存，可以使用命令清空 `go clean --modcache`&#x20;
{% endhint %}

### 私有模块 <a href="#id-2718ca" id="id-2718ca"></a>

如果你使用的 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 <a href="#anchor-h1-18" id="anchor-h1-18"></a>

### 1. 安装／升级Docker客户端 <a href="#anchor-h2-19" id="anchor-h2-19"></a>

推荐安装1.10.0以上版本的Docker客户端，参考文档 [docker-ce](https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/)

### 2. 配置镜像加速器 <a href="#anchor-h2-20" id="anchor-h2-20"></a>

针对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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hezhiqiang.gitbook.io/about-the-author/yun-wei-gong-ju-shi-yong/chang-yong-guo-nei-jia-su-yuan-shi-yong-ji-pei-zhi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
