概述
如果是下载比较大的项目,比如耗时5min往上,大小30mb往上,十分推荐使用代理网站下载,或者转入gitee的方式下载.
如果仅仅是下载比较小的项目,类似代码性质,文档性质的项目,使用cdn加速,提升到100多KB/s也就够用了
一.使用镜像网站
例如:使用github的镜像网站:http://cnpmjs.org
原地址:
1https://github.com/xxx.git
替换为:
1https://github.com.cnpmjs.org/xxx.git
示例:
1git clone https://github.com.cnpmjs.org/xxx.git
说白了,就在http://github.com后面加个.cnpmjs.org
即可
常用镜像网站
推荐:https://hub.fastgit.xyz/
是否推荐 | 网址 | 操作 |
---|---|---|
https://hub.fastgit.xyz/ 或https://hub.fastgit.org/ | git clone https://hub.fastgit.xyz/…… | |
https://hub.おうか.tw/ | git clone https://hub.xn--p8jhe.tw/…… | |
https://hub.連接.台灣/ | git clone https://hub.xn--gzu630h.xn--kpry57d/…… | |
https://cdn.githubjs.cf/ | 只能看,不能git | |
https://gitclone.com/ | git clone https://gitclone.com/github.com/…… | |
https://www.github.do/ | git clone https://github.do/https://github.com/…… | |
https://ghproxy.com/ | git clone https://ghproxy.com/https://github.com/…… |
二. 使用代理网站下载
对于github release中下载的大文件,推荐代理网站,速度起飞,无需注册,亲测有效。
推荐:
https://ghproxy.com/
https://toolwa.com/github/
三. cdn加速(修改hosts文件)-- 推荐
通过修改系统hosts文件的办法,绕过国内dns解析,直接访问GitHub的CDN节点,从而达到github访问加速的目的。不需要海外的服务器辅助。
GitHub在国内访问速度慢的问题原因有很多,但最直接和最主要的原因是GitHub的分发加速网络的域名遭到dns污染,下载网站上任何东西的时候会下半天,有时还会失败需要从头再来,多失败了几次又因访问次数过多被做了ip限制,让人恼火
做到以上需要三步
获取GitHub官方CDN地址
修改系统Hosts文件
刷新系统DNS缓存
1. 获取GitHub官方CDN地址
首先,打开 https://www.ipaddress.com/
查询以下4个链接的DNS解析地址
1github.com
2assets-cdn.github.com
3github.global.ssl.fastly.net
4raw.githubusercontent.com



2. 修改系统Hosts文件
接着,打开系统hosts文件(需管理员权限)。
路径:C:\Windows\System32\drivers\etc
mac或者其他linux系统的话,是/etc下的hosts文件,需要切入到root用户修改
1140.82.114.3 github.com
2185.199.108.153 assets-cdn.github.com
3199.232.69.194 github.global.ssl.fastly.net
4185.199.108.133 raw.githubusercontent.com
5
6
7
8echo "
9140.82.114.3 github.com
10185.199.108.153 assets-cdn.github.com
11199.232.69.194 github.global.ssl.fastly.net
12185.199.108.133 raw.githubusercontent.com
13185.199.108.154 github.githubassets.com
14" >> /etc/hosts
并在末尾添加三行记录并保存。(需管理员权限,注意IP地址与域名间需留有空格)
3. 刷新系统DNS缓存
最后,Windows+X 打开系统命令行(管理员身份)或powershell
运行 ipconfig flushdns
手动刷新系统DNS缓存。
mac系统修改完hosts文件,保存并退出就可以了.不要要多一步刷新操作.
centos系统执行/etc/init.d/network restart命令 使得hosts生效

四. 转入gitee加速
最终下载速度对比
github 42KB/s (加了github访问cdn)

gitee 1034KB/s 大约25倍与github的速度

例:我们要下载https://github.com/DoubleLabyrinth/navicat-keygen
先访问要下载的仓库的地址(在chrome中打
点击fork (fork会把这个仓库复制一份到你的github账号的名下,所以你需要有个githu账号,没有的注册一下,有了的记得登陆)
点完之后

注意到这个仓库已经到了我们的名下
好了 github这边的事我们暂时做完了
现在登陆gitee (没有账号的注册一个账号)
然后点击

接着会出现一个授权

然后可能会出现第一输入密码的地方

这儿输入mac的登陆密码 并点击始终允许
然后出现

输入 github账号的密码 之后出现

选择我们刚刚的项目 navicat-keygen -> 导入
gitee正在帮我们从github下载(gitee从github下载的速度一定是很快的,毕竟大网站)

一般来说30s内就处理好自动刷新了

然后我们复制这个网址

然后我们下载这个地址
可以看到速度

五.安装浏览器插件
地址:https://github.com/fhefh2015/Fast-GitHub

使用方式:
从设置->更多工具->扩展程序 打开扩展程序页面,或者地址栏输入 chrome://extensions/ 按下回车打开扩展程序页面
安装插件:开发者模式 -> 刷新页面 -> 下载好的 .crx 文件拖入扩展程序
如果在添加谷歌插件的时候,却发现谷歌浏览器显示 程序包无效:"CRX_HEADER_INVALID"
谷歌浏览器显示 程序包无效:"CRX_HEADER_INVALID" 解决方式
在扩展安装页面打开右上角的【开发者模式】按钮,然后刷新页面,将下载好的.crx文件拖入扩展安装页面内。
六.使用fastgithub软件(推荐)
github:https://github.com/dotnetcore/fastgithub/releases
官网:https://fastgithub.cn/
安装部署方式
2.1 windows-x64桌面
双击运行FastGithub.UI.exe
2.2 windows-x64服务
fastgithub.exe start
以windows服务安装并启动fastgithub.exe stop
以windows服务卸载并删除
2.3 linux-x64终端
sudo ./fastgithub
设置系统自动代理为
http://127.0.0.1:38457
,或手动代理http/https为127.0.0.1:38457
2.4 linux-x64服务
1wget https://github.com/dotnetcore/FastGithub/releases/download/2.1.4/fastgithub_linux-x64.zip
2unzip fastgithub_linux-x64.zip -d /usr/local/
3cd /usr/local/fastgithub_linux-x64/
4./fastgithub start
5systemctl status fastgithub.service
sudo ./fastgithub start
以systemd服务安装并启动sudo ./fastgithub stop
以systemd服务卸载并删除设置系统自动代理为
http://127.0.0.1:38457
,或手动代理http/https为127.0.0.1:38457

2.5 macOS-x64
双击运行fastgithub
安装cacert/fastgithub.cer并设置信任
设置系统自动代理为
http://127.0.0.1:38457
,或手动代理http/https为127.0.0.1:38457
具体配置详情
2.6 docker-compose一键部署
准备好docker 18.09, docker-compose.
在源码目录下,有一个docker-compose.yaml 文件,专用于在实际项目中,临时使用github.com源码,而做的demo配置。
根据自己的需要更新docker-compose.yaml中的sample和build镜像即可完成拉github.com源码加速,并基于源码做后续的操作。
1https://github.com/docker/compose
2curl --insecure -L https://download.fastgit.org/docker/compose/releases/download/v2.6.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
3chmod +x /usr/local/bin/docker-compose
4docker-compose -v
5
6
7cat > docker-compose.yml <<"EOF"
8version: "3.7"
9services:
10 fastgithub:
11 image: slcnx/fastgithub
12 network_mode: host
13 restart: always
14 volumes:
15 - cacert:/fastgithub/cacert/
16 sample:
17 depends_on:
18 - fastgithub
19 image: slcnx/ubuntu:18.04
20 volumes:
21 - cacert:/tmp/cacert
22 - build_data:/build_data
23 working_dir: /build_data
24 restart: on-failure
25 tty: true
26 entrypoint: sh -c 'cp /tmp/cacert/fastgithub.cer /usr/local/share/ca-certificates/fastgithub.crt && update-ca-certificates && git clone https://github.com/kubernetes/kubernetes.git'
27 command: ""
28 environment:
29 https_proxy: http://0.0.0.0:38457
30 http_proxy: http://0.0.0.0:38457
31 network_mode: host
32 build:
33 working_dir: /build_data
34 depends_on:
35 - sample
36 image: nginx
37 volumes:
38 - build_data:/build_data
39volumes:
40 cacert: {}
41 build_data: {}
42
43EOF
44
问题解决
Firefox建立安全连接失败
连接到 github.com 时发生错误。对等端的证书有一个无效的签名。
错误代码:SEC_ERROR_BAD_SIGNATURE
解决办法
1、地址栏输入:about:config
2、 输入首选项名称:security.enterprise_roots.enabled
3、修改值为:true
firefox提示“连接有潜在的安全问题”
设置->隐私与安全->证书->查看证书->证书颁发机构,导入cacert/fastgithub.cer,勾选“信任由此证书颁发机构来标识网站”



git.exe clone、pull或push等证书异常
fatal: unable to access 'https://github.com/xxx.git/'
SSL certificate problem: unable to get local issuer certificate
解决办法
管理员身份运行:cmd
在cmd输入:git config --global http.sslverify false
缺点
1、开启该代理后,picgo不能上传图片,报错“RequestError: Error: unable to verify the first certificate”,目前无解
2、目前只能代理本机的github加速,不能作为其它机器的代理。
七.使用dev-sidecar软件(推荐)
https://github.com/docmirror/dev-sidecar
https://github.com/docmirror/dev-sidecar/releases/tag/v1.7.3
windows下载安装即可。
Ubuntu:
1wget https://github.com/docmirror/dev-sidecar/releases/download/v1.7.3/DevSidecar-1.7.3.AppImage
2chmod +x ./DevSidecar-1.7.3.AppImage
3./DevSidecar-1.7.3.AppImage --no-sandbox
优点
可以作为其它机器的代理,可以在Ubuntu或windows上使用。

缺点
稳定性不如fastgithub好,即加速效果不如fastgithub好。
但是,不影响picgo上传图片,对我来说比较合适。
报错
建立安全连接失败
连接到 github.com 时发生错误。对等端的证书有一个无效的签名。
错误代码:SEC_ERROR_BAD_SIGNATURE

解决:
方法一:将服务端的crt文件拷贝过来,并导入证书。
方法二:取消“启用拦截”的选项。

总结
1、代理网站:https://ghproxy.com/
2、安装软件:fastgithub 或 dev-sidecar
参考
参考:https://blog.csdn.net/Ejzq1/article/details/123560340