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
    
  • 10
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

卡尔特斯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值