与各种龟速对抗

与各种龟速对抗

以下内容从网络收集整理,方便自己查用

GitHub访问龟速

原因:

GitHub链接被指向了Amazon的服务器,从国内访问Amazon非常慢

解决方法:

www.ipaddress.com 中查找github.com以及github.global.ssl.fastly.net两个域名的最近服务器IP,然后加下列ip加入C:\Windows\System32\drivers\etchost文件中(需要管理员权限)

1
2
140.82.114.4 github.com
199.232.5.194 github.global.ssl.fastly.net

git clone龟速

方法:设置代理,git命令并不会直接走全局代理,需要通过git config配置:

1
2
3
4
5
6
# socks5协议,1080端口修改成自己的本地代理端口
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080
# http协议,1081端口修改成自己的本地代理端口
git config --global http.proxy http://127.0.0.1:1081
git config --global https.proxy https://127.0.0.1:1081

以上的配置会导致所有git命令都走代理,但是如果你混合使用了国内的git仓库,甚至是局域网内部的git仓库,这就会把原来速度快的改成更慢的了;

下面是仅仅针对github进行配置,让github走本地代理,其他的保持不变;

1
2
3
4
5
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080
# http协议,1081端口修改成自己的本地代理端口
git config --global http.https://github.com.proxy https://127.0.0.1:1081
git config --global https.https://github.com.proxy https://127.0.0.1:1081

但是不知道为什么,今天推送代码到GitHub上时候,Git Push 提示不支持具有 Socks5 方案的代理

所以又取消了代理:

1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

pip install龟速

大多数速度慢的问题都因为镜像源在国外比较慢,可通过换镜像源(如淘宝/清华的)来加速

临时方法

1
2
# pip install换清华的镜像源
$pip install XXX -i https://pypi.tuna.tsinghua.edu.cn/simple

永久方法

linux下修改 ~/.pip/pip.conf (没有就创建一个), 修改 index-url至tuna,内容如下:

1
2
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

npm龟速

临时方法

1
$npm install XXX -g --registry=http://registry.npm.taobao.org  

永久方法

法1

打开nodejs安装文件夹下面的子目录E:\nodejs\node_modules\npm,找到里面的npmrc文件,添加配置

registry=http://registry.npm.taobao.org

或者直接用命令配置

1
2
# 配置registry
npm config set registry=http://registry.npm.taobao.org

法2

cnpm 是 npm 中国镜像的 npm 客户端,可以代替 npm。

先用 npm 安装 cnpm:

1
npm install -g cnpm --registry=https://registry.npm.taobao.org 

而后,安装软件就能直接用 cnpm 代替 npm 了:

1
cnpm install [name]

references

一招 git clone 加速

加速 npm

若有误或待改进之处,望前辈们指正!

转载请注明出处!