当前位置:   article > 正文

Linux服务器无法访问GitHub问题解决

Linux服务器无法访问GitHub问题解决

项目场景:

在使用阿里云服务器部署docker-compose时,需要从GitHub部署下载文件;


问题描述

使用以下命令下载docker-compose安装包,会出现连接失败的情况,直接ping也是无法ping通的

curl -L https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

 


原因分析:

国内的运营厂商由于某些特殊原因,连接GitHub会超时,即使连接上也会很慢掉线等,网上查找有些大佬给了解释:


解决方案:

通过修改hosts文件的方法,直接访问 GitHub 的 CDN 节点,从而达到加速的目的。

1.GitHub520

GitHub520是一个开源的GitHub项目,帮助大家访问GitHub,还提供了无需访问GitHub就能获取最新的hosts内容:

  • 文件:https://raw.hellogithub.com/hosts
  • JSON:https://raw.hellogithub.com/hosts.json

2.操作

(1)Linux的hosts文件存储地址是 /etc/hosts

vim /etc/hosts

(2)复制以下内容到hosts文件中(备注,如果失效需要从1中的GitHub获取新的hosts内容)

  1. # GitHub520 Host Start
  2. 140.82.114.26 alive.github.com
  3. 140.82.112.5 api.github.com
  4. 185.199.111.153 assets-cdn.github.com
  5. 185.199.110.133 avatars.githubusercontent.com
  6. 185.199.110.133 avatars0.githubusercontent.com
  7. 185.199.110.133 avatars1.githubusercontent.com
  8. 185.199.110.133 avatars2.githubusercontent.com
  9. 185.199.110.133 avatars3.githubusercontent.com
  10. 185.199.110.133 avatars4.githubusercontent.com
  11. 185.199.110.133 avatars5.githubusercontent.com
  12. 185.199.110.133 camo.githubusercontent.com
  13. 140.82.112.21 central.github.com
  14. 185.199.108.133 cloud.githubusercontent.com
  15. 140.82.114.9 codeload.github.com
  16. 140.82.113.21 collector.github.com
  17. 185.199.110.133 desktop.githubusercontent.com
  18. 185.199.110.133 favicons.githubusercontent.com
  19. 140.82.114.3 gist.github.com
  20. 54.231.132.201 github-cloud.s3.amazonaws.com
  21. 52.217.159.33 github-com.s3.amazonaws.com
  22. 16.182.70.201 github-production-release-asset-2e65be.s3.amazonaws.com
  23. 52.217.71.156 github-production-repository-file-5c1aeb.s3.amazonaws.com
  24. 52.216.77.12 github-production-user-asset-6210df.s3.amazonaws.com
  25. 192.0.66.2 github.blog
  26. 140.82.114.3 github.com
  27. 140.82.112.17 github.community
  28. 185.199.110.154 github.githubassets.com
  29. 151.101.1.194 github.global.ssl.fastly.net
  30. 185.199.110.153 github.io
  31. 185.199.108.133 github.map.fastly.net
  32. 185.199.110.153 githubstatus.com
  33. 140.82.114.26 live.github.com
  34. 185.199.108.133 media.githubusercontent.com
  35. 185.199.110.133 objects.githubusercontent.com
  36. 13.107.42.16 pipelines.actions.githubusercontent.com
  37. 185.199.108.133 raw.githubusercontent.com
  38. 185.199.108.133 user-images.githubusercontent.com
  39. 13.107.213.40 vscode.dev
  40. 140.82.112.21 education.github.com
  41. # Update time: 2023-12-09T12:05:19+08:00
  42. # Update url: https://raw.hellogithub.com/hosts
  43. # Star me: https://github.com/521xueweihan/GitHub520
  44. # GitHub520 Host End

(3)激活生效

一般情况是立即生效,未生效可尝试使用以下命令

sudo nscd restart

如报错则须安装:sudo apt install nscd 或 sudo /etc/init.d/nscd restart

均无效尝试重启机器

3.备注

GitHub520 还提供了SwitchHosts管理工具自动更新的方式,包括windows系统,安卓系统,ios系统等系统的更改方法

参考:

GitHub520: 让你“爱”上 GitHub,解决访问时图裂、加载慢的问题。(无需安装) github地址:https://github.com/521xueweihan/GitHub520

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/433613
推荐阅读
相关标签
  

闽ICP备14008679号