CentOS 服务器 git clone下载加速(下载过慢或超时)

  • CentOS 服务器 上通过 git clone 下载项目,速度很慢或直接超时

    [root@VM-0-11-centos home]# git clone https://github.com/dengzemiao/DZMLuckyDraw.git
    正克隆到 'DZMLuckyDraw'...
    error: RPC failed; result=35, HTTP code = 0
    fatal: The remote end hung up unexpectedly
    复制代码
  • git clone 特别慢,是因为 github.global.ssl.fastly.net 域名被限制了,只要找到这个域名对应的 IP 地址,然后在 hosts 文件中加上 ip–>域名 的映射,刷新 DNS 缓存便可。

  • nslookup 命令获取 github IP 地址

    1、如果没有安装,则需要安装一下

    $ yum -y install bind-utils
    复制代码

    2、获取 IP 地址

    $ nslookup github.global.ssl.fastly.net
    $ nslookup github.com
    复制代码

    image.png

  • 修改 hosts 文件

    1、编辑 hosts

    $ sudo vim /etc/hosts
    复制代码

    2、填入内容,保存

    格式:
    x.x.x.x http://global-ssl.fastly.net 
    x.x.x.x http://github.com
    
    例如拿上面得到的IP地址:
    69.171.229.73 http://global-ssl.fastly.net 
    13.250.177.223 http://github.com
    复制代码

    image.png

  • nscd 命令更新 DNS 缓存

    1、如果没有安装,则需要安装一下

    $ yum install -y nscd
    复制代码

    2、更新 DNS 缓存

    $ nscd -i hosts
    复制代码
  • 然后再次执行 git clone,则会进入下载。

    [root@VM-0-11-centos home]# git clone https://github.com/dengzemiao/DZMLuckyDraw.git
    正克隆到 'DZMLuckyDraw'...
    remote: Enumerating objects: 2644, done.
    remote: Counting objects: 100% (2644/2644), done.
    remote: Compressing objects: 100% (1562/1562), done.
    接收对象中:   1% (41/2644), 897.00 KiB | 897.00 KiB/s
    复制代码
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享