首页 > 系统相关 >Linux下安装git工具及访问github问题的解决

Linux下安装git工具及访问github问题的解决

时间:2022-10-18 15:02:00浏览次数:77  
标签:git com el9.2 github Linux root phpMyFAQ

什么是git

参考下这里:​​https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-Git-%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F​

站长写的很详细。

如何安装

安装

[root@OpenKM ~]# yum -y install git
CentOS Stream 9 - BaseOS 718 B/s | 4.0 kB 00:05
CentOS Stream 9 - AppStream 790 B/s | 4.1 kB 00:05
CentOS Stream 9 - Extras packages 823 B/s | 4.3 kB 00:05
Dependencies resolved.
=======================================================================================================================================
Package Architecture Version Repository Size
=======================================================================================================================================
Installing:
git x86_64 2.31.1-2.el9.2 appstream 124 k
Installing dependencies:
git-core x86_64 2.31.1-2.el9.2 appstream 3.6 M
git-core-doc noarch 2.31.1-2.el9.2 appstream 2.5 M
perl-Error noarch 1:0.17029-7.el9 appstream 42 k
perl-Git noarch 2.31.1-2.el9.2 appstream 43 k
perl-TermReadKey x86_64 2.38-11.el9 appstream 37 k
perl-lib x86_64 0.65-479.el9 appstream 24 k

Transaction Summary
=======================================================================================================================================
Install 7 Packages

Total download size: 6.4 M
Installed size: 32 M
Downloading Packages:
(1/7): git-2.31.1-2.el9.2.x86_64.rpm 24 kB/s | 124 kB 00:05
(2/7): perl-Error-0.17029-7.el9.noarch.rpm 387 kB/s | 42 kB 00:00
(3/7): git-core-doc-2.31.1-2.el9.2.noarch.rpm 455 kB/s | 2.5 MB 00:05
(4/7): perl-TermReadKey-2.38-11.el9.x86_64.rpm 755 kB/s | 37 kB 00:00
(5/7): perl-lib-0.65-479.el9.x86_64.rpm 527 kB/s | 24 kB 00:00
(6/7): perl-Git-2.31.1-2.el9.2.noarch.rpm 85 kB/s | 43 kB 00:00
(7/7): git-core-2.31.1-2.el9.2.x86_64.rpm 608 kB/s | 3.6 MB 00:06
---------------------------------------------------------------------------------------------------------------------------------------
Total 553 kB/s | 6.4 MB 00:11
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : git-core-2.31.1-2.el9.2.x86_64 1/7
Installing : git-core-doc-2.31.1-2.el9.2.noarch 2/7
Installing : perl-lib-0.65-479.el9.x86_64 3/7
Installing : perl-TermReadKey-2.38-11.el9.x86_64 4/7
Installing : perl-Error-1:0.17029-7.el9.noarch 5/7
Installing : perl-Git-2.31.1-2.el9.2.noarch 6/7
Installing : git-2.31.1-2.el9.2.x86_64 7/7
Running scriptlet: git-2.31.1-2.el9.2.x86_64 7/7
Verifying : git-2.31.1-2.el9.2.x86_64 1/7
Verifying : git-core-2.31.1-2.el9.2.x86_64 2/7
Verifying : git-core-doc-2.31.1-2.el9.2.noarch 3/7
Verifying : perl-Error-1:0.17029-7.el9.noarch 4/7
Verifying : perl-Git-2.31.1-2.el9.2.noarch 5/7
Verifying : perl-TermReadKey-2.38-11.el9.x86_64 6/7
Verifying : perl-lib-0.65-479.el9.x86_64 7/7

Installed:
git-2.31.1-2.el9.2.x86_64 git-core-2.31.1-2.el9.2.x86_64 git-core-doc-2.31.1-2.el9.2.noarch
perl-Error-1:0.17029-7.el9.noarch perl-Git-2.31.1-2.el9.2.noarch perl-TermReadKey-2.38-11.el9.x86_64
perl-lib-0.65-479.el9.x86_64

Complete!
[root@OpenKM ~]#

基本语法与逻辑:

Git 常用的是以下 6 个命令:git clonegit pushgit addgit commitgit checkoutgit pull

Linux下安装git工具及访问github问题的解决_github

说明:

  • workspace:工作区
  • staging area:暂存区/缓存区
  • local repository:版本库或本地仓库
  • remote repository:远程仓库

Git 的工作流程:

Linux下安装git工具及访问github问题的解决_Linux_02

大家也可以参考这里写的很详细了:

​https://www.runoob.com/git/git-commit-history.html​

如何解决访问github等网站仓库连接失败的问题

问题现象:

默认情况下尝试下载github资源(我们以一个开源项目phpMyFAQ为例)

[root@OpenKM phpMyFAQ]# git clone https://github.com/phpMyFAQ/docker-hub.git
Cloning into 'docker-hub'...
fatal: unable to access 'https://github.com/phpMyFAQ/docker-hub.git/': OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while reading, errno 0
[root@OpenKM phpMyFAQ]#

你将得到​​unable to access​​的问题。

这是由于github被gw屏蔽的原因导致的,因此,要解决问题需要首选找到可访问的github服务器的地址。

解决方法(更新于2022-10-18)

如何获取Github可访问的ip地址

我们访问链接:​​https://ping.chinaz.com/github.com​​​(站长之家)。利用它的​​ping​​检测目标网站的IP地址。

Linux下安装git工具及访问github问题的解决_access error_03

往下看测试结果:

Linux下安装git工具及访问github问题的解决_Linux_04

不出意外,国内因该都是失败的

不要着急,继续往下翻:

Linux下安装git工具及访问github问题的解决_git_05

Linux下安装git工具及访问github问题的解决_Linux_06

可以看到国外的节点所访问的某些地址是正常的。

在这些正常的地址中,我们随便选择一个;比如:140.82.121.3

然后,在需要使用git工具的计算机中尝试ping 140.82.121.3

[root@xml-srv phpMyFAQ]# ping 140.82.121.3
PING 140.82.121.3 (140.82.121.3) 56(84) bytes of data.
64 bytes from 140.82.121.3: icmp_seq=1 ttl=47 time=246 ms
64 bytes from 140.82.121.3: icmp_seq=2 ttl=47 time=245 ms
64 bytes from 140.82.121.3: icmp_seq=3 ttl=47 time=245 ms
64 bytes from 140.82.121.3: icmp_seq=4 ttl=47 time=246 ms
64 bytes from 140.82.121.3: icmp_seq=5 ttl=47 time=246 ms
64 bytes from 140.82.121.3: icmp_seq=6 ttl=47 time=246 ms
^C
--- 140.82.121.3 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5007ms
rtt min/avg/max/mdev = 245.269/245.661/245.944/0.259 ms
[root@xml-srv phpMyFAQ]#

可以很直观看到地址是可以访问的,那么我们就可以用该​​ip​​来设置​​github hosts​​地址。

注意:若上面这个地址无法ping通或者质量不好,可以多测试几个,然后选择最优的地址作为hosts对应的github网站地址。

//我的环境是Linux设置hosts的方法如下;如果你是其他OS,参照本文设定原理即可
[root@xml-srv phpMyFAQ]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@xml-srv phpMyFAQ]# vi /etc/hosts
[root@xml-srv phpMyFAQ]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
140.82.121.3 github.com www.github.com
[root@xml-srv phpMyFAQ]#


//设置完成后进行域名的ping测试
[root@xml-srv phpMyFAQ]# ping github.com
PING github.com (140.82.121.3) 56(84) bytes of data.
64 bytes from github.com (140.82.121.3): icmp_seq=1 ttl=47 time=246 ms
64 bytes from github.com (140.82.121.3): icmp_seq=2 ttl=47 time=246 ms
^C
--- github.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 245.715/246.004/246.293/0.289 ms
[root@xml-srv phpMyFAQ]# ping www.github.com
PING github.com (140.82.121.3) 56(84) bytes of data.
64 bytes from github.com (140.82.121.3): icmp_seq=1 ttl=47 time=246 ms
^C
--- github.com ping statistics ---
2 packets transmitted, 1 received, 50% packet loss, time 1002ms
rtt min/avg/max/mdev = 245.850/245.850/245.850/0.000 ms
[root@xml-srv phpMyFAQ]#

再次尝试git访问GitHub

[root@xml-srv phpMyFAQ]# git clone https://github.com/phpMyFAQ/docker-hub.git
Cloning into 'docker-hub'...
remote: Enumerating objects: 90, done.
remote: Total 90 (delta 0), reused 0 (delta 0), pack-reused 90
Receiving objects: 100% (90/90), 13.18 KiB | 116.00 KiB/s, done.
Resolving deltas: 100% (47/47), done.
[root@xml-srv phpMyFAQ]# ll
total 0
drwxr-xr-x. 3 root root 146 Oct 18 12:14 docker-hub
[root@xml-srv phpMyFAQ]#

到此,就成功事先了国内对github的访问。

若出现fatal: unable to access 'https://github.com/.../.git': Could not resolve host: github.com错误则:

问题现象:

[root@xml-srv docker-hub]# docker build -t phpmyfaq:xml3.0 .
Sending build context to Docker daemon 89.09kB
Step 1/25 : FROM composer:latest as composer
---> 93cce8060354
Step 2/25 : WORKDIR /app
---> Using cache
---> 342315ade676
Step 3/25 : ARG PMF_BRANCH="3.0"
---> Using cache
---> f2f6fbf883dc
Step 4/25 : RUN set -x && git clone --depth 1 -b $PMF_BRANCH https://github.com/thorsten/phpMyFAQ.git /app
---> Running in d9dd1d71a18b
+ git clone --depth 1 -b 3.0 https://github.com/thorsten/phpMyFAQ.git /app
Cloning into '/app'...
fatal: unable to access 'https://github.com/thorsten/phpMyFAQ.git/': Could not resolve host: github.com
The command '/bin/sh -c set -x && git clone --depth 1 -b $PMF_BRANCH https://github.com/thorsten/phpMyFAQ.git /app' returned a non-zero code: 128
[root@xml-srv docker-hub]#
[root@xml-srv docker-hub]#

解决办法:

[root@xml-srv phpMyFAQ]git config --global --unset http.proxy 
[root@xml-srv phpMyFAQ]git config --global --unset https.proxy

然后,必须要清空dns缓存护着重启服务器后再试。

清空缓存的方法大家自行百度一下,方法有很多。


标签:git,com,el9.2,github,Linux,root,phpMyFAQ
From: https://blog.51cto.com/mlxia/5766695

相关文章

  • Git学习(八)命令总结
    1、分支、pullrequest等日常写作命令2、常用的更新命令这是一个人在GitHub玩儿的时候用的最多的,就是不断push,最多在GitHub上改了的话先pull一下再push。//【快速命令】......
  • linux windows双系统 磁盘扩充 系统备份
    前言由于工作需要,从windows迁移到linux,但是怕linux下有工作不能胜任,所以先装了双系统过度。用了一段时间,对windows的依赖越来越低,所以准备卸载windows上的一些软件,清理一......
  • Linux split package into more parts
    Sometimestheirsinglepackagespaceislimited,justlikenobiggerthan10Mforeachdocument,intheseconditions,weneedsplitthebigoneintomorepiece......
  • Linux安装mysql之路
    1、登录机器(1)链接机器ssh+ip,回车ssh192.168.1.1(2)输入密码,回车2、上传文件由于作者这边是内网,安全原因不能暴露具体内容,大致是利用工具将文件传到的指定目录中(非内网情况可......
  • Linux (Debain11) 安装 docker-desktop 时出现依赖问题
    安装Docker-Desktop出现依赖问题添加docker-ce-cli的安装源$echo\"deb[arch=$(dpkg--print-architecture)signed-by=/usr/share/keyrings/docker-archive-keyr......
  • Git 常用命令清单
    每天使用Git,但是很多命令记不住。一般来说,日常使用只要记住下图6个命令,就可以了。但是熟练使用,恐怕要记住60~100个命令。下面是整理的常用Git命令清单。几个专用名词......
  • Linux 必掌握的 SQL 命令
    数据库和SQL在本系列教程中,目前我们使用平面文本文件来存储数据。平面文本文件可能适合相对较少的数据,但它们对存储大量数据或查询该数据没有多大帮助。多年来,为该目的开发......
  • 【Linux 管理】如何将 PCI Bus 地址和物理 PCI 插槽对应
    前言事情是这样的:实验室做机器学习的服务器挂了一张显卡。这台服务器总共有8张RTX2080Ti显卡,现在使用nvidia-smi查看显卡信息,只能检测到七张显卡。查看连接到服务......
  • linux limit文件最大打开数
    目录linuxlimit文件最大打开数修改文件句柄数查看当前大小openfiles临时修改永久修改修改maxuserprocesses进程数临时修改永久修改调整vm.max_map_count的大小查看当前......
  • 配置Git私服
    配置Git私服参考的文章在这:一文手把手教你搭建Git私服|代码随想录(programmercarl.com)第一次连入新建的服务器执行suroot时提示su:Authenticationfailure,说是......