github访问加速,亲测有效

电玩女神 2022-10-07 13:55 401阅读 0赞

文章目录

    • 概括
    • 使用镜像网站
    • cdn加速
      • 获取GitHub官方CDN地址
      • 修改系统Hosts文件
      • 刷新系统DNS缓存
    • 转入gitee加速

概括

如果是下载比较大的项目,比如耗时 5min 往上,大小 30mb 往上,十分推荐使用镜像网站,或者转入gitee的方式下载.

如果仅仅是下载比较小的项目,类似代码性质,文档性质的项目,使用cdn加速,提升到100多KB/s也就够用了

使用镜像网站

使用github的镜像网站

原地址:

  1. https://github.com/xxx.git

替换为:

  1. https://github.com.cnpmjs.org/xxx.git

示例:

  1. git clone https://github.com.cnpmjs.org/xxx.git

说白了,就在 http://github.com 后面加个 .cnpmjs.org 即可

缺点: 每次访问页面都需要手动添加一次 .cnpmjs.org

对于 github release 中下载的大文件

使用 https://toolwa.com/github/来下载,速度起飞,无需注册,亲测有效。

cdn加速

通过修改系统 hosts 文件的办法,绕过国内dns解析,直接访问GitHub的CDN节点,从而达到github访问加速的目的。不需要海外的服务器辅助。

GitHub在国内访问速度慢的问题原因有很多,但最直接和最主要的原因是GitHub的分发加速网络的域名遭到dns污染,下载网站上任何东西的时候会下半天,有时还会失败需要从头再来,多失败了几次又因访问次数过多被做了ip限制,让人恼火

做到以上需要三步

  1. 获取GitHub官方CDN地址
  2. 修改系统Hosts文件
  3. 刷新系统DNS缓存

获取GitHub官方CDN地址

首先,打开https://www.ipaddress.com/

查询以下三个链接的DNS解析地址

  1. github.com
  2. assets-cdn.github.com
  3. github.global.ssl.fastly.net
    在这里插入图片描述

修改系统Hosts文件

接着,打开系统hosts文件(需管理员权限)。
路径:C:\Windows\System32\drivers\etc

mac或者其他linux系统的话,是/etc下的hosts文件,需要切入到root用户修改

  1. # Copyright (c) 1993-2009 Microsoft Corp.
  2. #
  3. # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
  4. #
  5. # This file contains the mappings of IP addresses to host names. Each
  6. # entry should be kept on an individual line. The IP address should
  7. # be placed in the first column followed by the corresponding host name.
  8. # The IP address and the host name should be separated by at least one
  9. # space.
  10. #
  11. # Additionally, comments (such as these) may be inserted on individual
  12. # lines or following the machine name denoted by a '#' symbol.
  13. #
  14. # For example:
  15. #
  16. # 102.54.94.97 rhino.acme.com # source server
  17. # 38.25.63.10 x.acme.com # x client host
  18. # localhost name resolution is handled within DNS itself.
  19. # 127.0.0.1 localhost
  20. # ::1 localhost
  21. 140.82.112.3 github.com
  22. 185.199.108.153 assets-cdn.github.com
  23. 199.232.69.194 github.global.ssl.fastly.net

并在末尾添加三行记录并保存。(需管理员权限,注意IP地址与域名间需留有空格)

刷新系统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的速度
在这里插入图片描述
例:我们要下载

  1. https:://github.com/DoubleLabyrinth/navicat-keygen

先访问要下载的仓库的地址(在chrome中打开)

点击fork (fork会把这个仓库复制一份到你的github账号的名下,所以你需要有个githu账号,没有的注册一下,有了的记得登陆)

点完之后
在这里插入图片描述
注意到这个仓库已经到了我们的名下

好了 github这边的事我们暂时做完了

现在登陆gitee (没有账号的注册一个账号)

然后点击
在这里插入图片描述
接着会出现一个授权
在这里插入图片描述
然后可能会出现第一输入密码的地方
在这里插入图片描述
这儿输入mac的登陆密码 并点击始终允许

然后出现
在这里插入图片描述
输入 github账号的密码 之后出现
在这里插入图片描述
选择我们刚刚的项目 navicat-keygen -> 导入

gitee正在帮我们从github下载(gitee从github下载的速度一定是很快的,毕竟大网站)
在这里插入图片描述

一般来说30s内就处理好自动刷新了
在这里插入图片描述

然后我们复制这个网址
在这里插入图片描述
然后我们下载这个地址

可以看到速度
在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,401人围观)

还没有评论,来说两句吧...

相关阅读