现象
今天在使用 git clone nextjs demo project 源代码的时, git clone https://github.com/XXXX/next-blog.git
下载速度很慢,然后下载一段时间后,总是提示下面的错误信息
Cloning into 'gsy_github_app_flutter'...
remote: Enumerating objects: 359, done.
remote: Counting objects: 100% (359/359), done.
remote: Compressing objects: 100% (314/314), done.
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
原因
由于Http协议错误,当 pull 或者 clone 的时候,或者是 github 某个CDN被伟大的墙屏蔽所致。
解决办法
协议错误
-
先执行下列命令
git config --global http.postBuffer 524288000
再执行git pull 或者 git clone命令
墙屏蔽
访问 http://github.global.ssl.fast...
获取cdn域名以及IP地址访问 http://github.com.ipaddress.c... 获取cdn域名以及IP地址
-
将上述获取的IP地址添加到
/etc/hosts
中sudo vim /etc/hosts
image.png
- 刷新dns缓存
在Linux一般是使用nscd来缓存DNS解析,如果是sysv管理服务,可以找到 /etc/init.d/nscd这个控制脚本,重启以下就可以了。
/etc/init.d/nscd restart
如果是systemd管理服务:
systemctl restart nscd
linux方法二:
sudo killall -HUP mDNSResponder sudo dscacheutil -flushcache
如果windows Vista之前直接在cmd-终端-输入命令,在Vista之后就需要有管理员权限,可以直接到C:\Windows\System32\cmd.exe,右键这个程序,以管理员身份运行,然后在输入命令。
ipconfig /flushdns
image.png
释放IP配置信息
ipconfig /release
MAC下访问github速度慢的解决办法
打开终端,编辑hosts文件
sudo vim /etc/hosts
添加以下内容
# Github
151.101.185.194 github.global.ssl.fastly.net
192.30.253.112 github.com
151.101.112.133 assets-cdn.github.com
151.101.184.133 assets-cdn.github.com
185.199.108.153 documentcloud.github.com
192.30.253.118 gist.github.com
185.199.108.153 help.github.com
192.30.253.120 nodeload.github.com
151.101.112.133 raw.github.com
23.21.63.56 status.github.com
192.30.253.1668 training.github.com
192.30.253.112 www.github.com
151.101.13.194 github.global.ssl.fastly.net
151.101.12.133 avatars0.githubusercontent.com
151.101.112.133 avatars1.githubusercontent.com
刷新dns
较新的苹果Mac OS X系统应该使用下面的命令:
dscacheutil -flushcache
type dscacheutil -flushcache
较老的苹果系统尝试下面的命令
lookupd -flushcache
最新的 OS X Mountain Lion or Lion 上刷新DNS应该是 :
sudo killall -HUP mDNSResponder
命令执行完毕,DNS缓存就得到了更新。速度从10几K还老失败变成了800K左右。