美文网首页
ssh forward 解决Github下载过慢的问题

ssh forward 解决Github下载过慢的问题

作者: 山哥Samuel | 来源:发表于2020-12-20 21:37 被阅读0次

    今天试玩Gatsby,安装sharp的时候由于是Github的,连不上。下载失败。

    info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.0/libvips-8.10.0-darwin-x64.tar.br
    ERR! sharp socket hang up
    info sharp Attempting to build from source via node-gyp but this may fail due to the above error
    

    然后报这个错:

    fatal error: 'vips/vips8' file not found

    果然遇到Github都是一个慢字…

    山哥有一个外网服务器 (my-jumper.com),速度挺快的,因为奉公守法不想做长期代理(免禁IP免罚款)。于是想用它做跳板机,让我能比较快地下载这个包。事不宜迟,走一个!

    sam $ sudo ssh -f -N -g -L 443:github.com:443 my-jumper.com
    

    修改 DNS使得所有的github.com走本地

    • Run command sudo vi /etc/hosts, 加上以下并保存。在Mac下保存即时生效
      127.0.0.1 github.com
      我们来验证一下:ping github.com
    sam$ ping github.com
    PING github.com (127.0.0.1): 56 data bytes
    64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.046 ms
    

    果然通的!
    咱们来看看现在装会不会很快!

    npm i -g sharp
    info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.0/libvips-8.10.0-darwin-x64.tar.br
    

    等了一下,发现没什么进展,于是看看是什么情况:

    sam$ curl https://github.com/lovell/sharp-libvips/releases/download/v8.10.0/libvips-8.10.0-darwin-x64.tar.br
    <html><body>You are being <a href="https://github-production-release-asset-2e65be.s3.amazonaws.com/104502835/a530c980-e54a-11ea-884a-79331ea787e8?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20201220%2Fus-east-1%2Fs3%2Faws4_request&amp;X-Amz-Date=20201220T130545Z&amp;X-Amz-Expires=300&amp;X-Amz-Signature=7e2a057712c5903f8703b176ad697315c9880a1a5b49d9f1ceacb9f103ee4751&amp;X-Amz-SignedHeaders=host&amp;actor_id=0&amp;key_id=0&amp;repo_id=104502835&amp;response-content-disposition=attachment%3B%20filename%3Dlibvips-8.10.0-darwin-x64.tar.br&amp;response-content-type=application%2Foctet-stream">redirected</a>.</body></html>
    

    居然被转发了,背后原来是去了AWS的S3。

    好吧,重新转发!

    $ ps aux|grep ssh
    sam               2814   0.0  0.0  4285680    248   ??  S     8Dec20   0:00.04 /usr/bin/ssh-agent -l
    sam              27713   0.0  0.0  4278688    744 s002  S+    9:12PM   0:00.00 grep ssh
    root             26978   0.0  0.0  4408788    656   ??  Ss    9:02PM   0:00.00 ssh -f -N -g -L 443:github.com:443 ubuntu@my-jumper.com
    
    $ sudo kill -9 26978
    

    重新来设置

    sam $ sudo ssh -f -N -g -L 443:github-production-release-asset-2e65be.s3.amazonaws.com:443 ubuntu@my-jumper.com
    
    # change the "127.0.0.1 github.com" to be as following
    sam $ sudo vi /etc/hosts
    127.0.0.1 github-production-release-asset-2e65be.s3.amazonaws.com
    
    # 验证一下,发现生效了,哦也~
    sam$ ping github-production-release-asset-2e65be.s3.amazonaws.com
    PING github-production-release-asset-2e65be.s3.amazonaws.com (127.0.0.1): 56 data bytes
    64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.046 ms
    

    按捺下激动的心情,控制住颤抖的手,再来安装

    sam$ npm i -g sharp
    
    > sharp@0.26.3 install /usr/local/lib/node_modules/sharp
    > (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
    
    info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.0/libvips-8.10.0-darwin-x64.tar.br
    + sharp@0.26.3
    updated 1 package in 9.607s
    

    完事了,9秒多装好!果然是Work的!

    事后把/etc/hosts还原,把这个SSH进程杀掉!

    相关文章

      网友评论

          本文标题:ssh forward 解决Github下载过慢的问题

          本文链接:https://www.haomeiwen.com/subject/okxlnktx.html