11月28日 Git
1、Git基础介绍
Git是一个开源的分布式版本控制系统,可以有效、高速的处理从很小到非常大的项目版本管理。
-
安装包:yum install git
-
Git分为以下区:
工作区:Working Directory
暂存区:Staging Area,也叫index,保存版本库一次变化的元数据,包括作者、邮箱、提交日期、日志等
版本库:Repository,或者对象库 -
Git的对象类型: .git/objects
块(blob)对象:文件的每个版本表现为一个块(blob);
树(tree)对象:一个目录代表一层目录信息;
提交的(commit)对象:用于保存版本库一次变化的元数据,包括作者、邮箱、提交日期、日志;每个提交对象都指定一个目录树对象;
标签(tag)对象:用于给一个特定对象一个易读的名称;
6854348-9f9f399b31b1e5dc.png -
git reset:撤消此前的操作;
git reset --soft:相当于撤销了commit操作,此时index和工作目录内容不变,还是最新的版本,只有对象库中的内容回到原来的版本;
git reset --mixed:相当于撤销commit和add操作,此时index中的内容也被撤销了,只有工作目录中的内容不变,还是最新的版本;
git reset --hard:撤销所有的操作,工作目录中的内容也回到原来的版本 -
Git分支
git branch:列出、创建及删除分支;
git branch BRANCH_NAME [START_COMMIT]
git branch -d BRANCH_NAME 删除分支
git show-branch:查看分支及其相关的提交;
git checkout:创建和切换分支
git merge BRANCH_NAME:合并分支
git log:查看提交历史
git tag:管理标签 -
引用远程版本库
git remote命令:管理远程仓库;
git fetch:取回远程服务器的更新;
git pull:取回远程服务器更新,而后与本地的指定分支合并;
git pull <远程主机名> <远程分支名>:<本地分支名>
git push:将本地的更新推送到远程主机;
git push <远程主机名> <本地分支名>:<远程分支名>
示例:把某个目录中的内容纳入到git来管理
[root@node1 app]#mkdir /app/app1
[root@node1 app]#cd /app/app1
[root@node1 app1]#vim README
test app project
[root@node1 app1]#git init #在当前目录下执行此命令进行git初始化,就会把当前目录app1纳入git来管理了
Initialized empty Git repository in /app/app1/.git/
[root@node1 app1]#ls -a #被git管理的目录会有一个.git的目录
. .. .git README
[root@node1 app1]#tree .git
.git
├── branches
├── config
├── description
├── HEAD
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── info
│ └── exclude
├── objects #所有被git追踪的内容将来都要放在此目录下做为一个对象存在,保存的时候会对内容进行哈希运算,将哈希运算的结果当成文件名,保存在对象目录下,根缓存系统很相似
│ ├── info
│ └── pack
└── refs #记录某一个时刻目录内容发生改变,这些有记录的符号链接存放在此目录下
├── heads
└── tags
[root@node1 app1]#git add README #将此文件保存到暂存区
[root@node1 app1]#tree .git/
.git/
├── branches
├── config
├── description
├── HEAD
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── index
├── info
│ └── exclude
├── objects
│ ├── f7
│ │ └── 238e084ceba3700ee4a38d41534e1b4b3b1382 #发现在对象目录中增加了一个文件就是READM文件
│ ├── info
│ └── pack
└── refs
├── heads
└── tags
[root@node1 app1]#mkdir examples src
[root@node1 app1]#ls
examples README src
[root@node1 app1]#vim examples/test
test example
[root@node1 app1]#git add . #将当前目录app1中的内容全部保存至index
[root@node1 app1]#tree .git
.git
├── branches
├── config
├── description
├── HEAD
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── index
├── info
│ └── exclude
├── objects
│ ├── 6c
│ │ └── 1792a38f86402e3560a3255beb63ac452b200e #又新增加了一个文件,也就是examples目录下的test文件
│ ├── f7
│ │ └── 238e084ceba3700ee4a38d41534e1b4b3b1382 #发现此时还没有记录目录的层级结构,只记录了目录中的文件
│ ├── info
│ └── pack
└── refs
├── heads
└── tags
[root@node1 app1]#git config --global user.name magedu #在提交之前需要设置个人的信息,用户名和邮箱等,不然每次提交之前都会提示输入个人信息
[root@node1 app1]#git config --global user.email mage@magedu.com
[root@node1 app1]#git config --global --list
user.name=magedu
user.email=mage@magedu.com
[root@node1 app1]#git commit -m "initial version" #提交的时候需要指明一些描述信息,比如提交的是个初始版本
[root@node1 app1]#tree .git/ #发现多了三个对象文件,除了上面两个外,一个是app1根目录,一个是example目录,另外一个是提交本身,src因为里面没有文件,所以目录结构并没有被保存
.git/
├── branches
├── COMMIT_EDITMSG
├── config
├── description
├── HEAD
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── index
├── info
│ └── exclude
├── logs
│ ├── HEAD
│ └── refs
│ └── heads
│ └── master
├── objects
│ ├── 6c
│ │ └── 1792a38f86402e3560a3255beb63ac452b200e
│ ├── 7f
│ │ └── b9eb1f385cb2b5fb5904e8b231436eae8ba78c
│ ├── 9c
│ │ └── 73b081ff7b864633f6f2177cee890425efd7bd
│ ├── a6
│ │ └── 057071df2675a95751ea08bbbf72f6f91214ff
│ ├── f7
│ │ └── 238e084ceba3700ee4a38d41534e1b4b3b1382
│ ├── info
│ └── pack
└── refs
├── heads
│ └── master
└── tags
[root@node1 app1]#git log #查看提交历史
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c #在这里我们可以看到提交本身也是一个对象文件,会保存到对象库中
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
[root@node1 app1]#rm -rf * #删除该目录下的所有内容
[root@node1 app1]#ls -a
. .. .git
[root@node1 app1]#git checkout #从对象库中检出
D README
D examples/test
[root@node1 app1]#ls -a #发现检出后并没有真正的原因
. .. .git
[root@node1 app1]#git clone /app/app1 /tmp/app2 #需要克隆之后才能
真正的还原,所以我们在创建仓库时可以自己从头开始创建,就像上面
的创建过程一样,也可以克隆别人的仓库中的内容
Cloning into '/tmp/app2'...
done.
[root@node1 app1]#cd /tmp/app2/
[root@node1 app2]#ls -a #发现还原了
. .. examples .git README
[root@node1 app2]#tree .git
.git
├── branches
├── config
├── description
├── HEAD
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── index
├── info
│ └── exclude
├── logs
│ ├── HEAD
│ └── refs
│ ├── heads
│ │ └── master
│ └── remotes
│ └── origin
│ └── HEAD
├── objects
│ ├── 6c
│ │ └── 1792a38f86402e3560a3255beb63ac452b200e
│ ├── 7f
│ │ └── b9eb1f385cb2b5fb5904e8b231436eae8ba78c
│ ├── 9c
│ │ └── 73b081ff7b864633f6f2177cee890425efd7bd
│ ├── a6
│ │ └── 057071df2675a95751ea08bbbf72f6f91214ff
│ ├── f7
│ │ └── 238e084ceba3700ee4a38d41534e1b4b3b1382
│ ├── info
│ └── pack
├── packed-refs
└── refs
├── heads
│ └── master #当前目录下已有文件的主分支
├── remotes #记录下来当前仓库是从远程哪个仓库克隆过来的
│ └── origin #表示起始仓库
│ └── HEAD #指向它的最新一次提交
└── tags
[root@node1 app2]#git status
# On branch master #表示当前在master分支上
nothing to commit, working directory clean #三个区域的内容是一样的
[root@node1 app2]#vim README
test app project
one line
[root@node1 app2]#git status #再次查看状态
# On branch master
# Changes not staged for commit: #表示有一个改变没有被提交
# (use "git add <file>..." to update what will be committed) #可以使用git add去更新索引并等待提交
# (use "git checkout -- <file>..." to discard changes in working directory) #可以使用git checkout去丢弃改变在工作目录中
#
# modified: README #更改的文件时README
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@node1 app2]#git add README #表示添加至暂存区并没有提交
[root@node1 app2]#git status
# On branch master
# Changes to be committed: #表示现在可以进行提交了
# (use "git reset HEAD <file>..." to unstage)#表示可以用git reset命令撤销刚才的操作,也就是从暂存区中撤销
#
# modified: README
#
[root@node1 app2]#git commit -m 'v0.2' #提交
[master 1d6adef] v0.2
1 file changed, 1 insertion(+)
[root@node1 app2]#git log #查看提交历史,发现是上面是最新一次的提交
commit 1d6adef3db3ae979cc93970547562621e0940f05
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:28:57 2017 +0800
v0.2
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
[root@node1 app2]#git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
# (use "git push" to publish your local commits)
#
nothing to commit, working directory clean #告诉我们没有什么需要提交的了,三个区域工作目录、index、对象库中又同步了
[root@node1 app2]#vim newfile #在工作目录下创建一个新的文件
hello world
[root@node1 app2]#git add newfile
[root@node1 app2]#git commit -m 'v0.3'
[master 4ba897e] v0.3
1 file changed, 1 insertion(+)
create mode 100644 newfile
[root@node1 app2]#git log #可以看到最近三次提交
commit 4ba897eaf80b2b195da0b4a27fe2228c24779723
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:33:45 2017 +0800
v0.3
commit 1d6adef3db3ae979cc93970547562621e0940f05
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:28:57 2017 +0800
v0.2
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
[root@node1 app2]#git reset --soft 1d6adef3 #撤销commit操作至第二
次提交,1d6adef3是第二次提交的对象文件的前几个字符,只要和其他
的提交能区别唯一就可以
[root@node1 app2]#git status #发现返回到最后一次提交之前的状态了
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
# (use "git push" to publish your local commits)
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: newfile
#
[root@node1 app2]#git commit -m "v0.3.1" #再一次提交
[root@node1 app2]#git status
[root@node1 app2]#git log
commit fd87dc12f2aa5ac0ba46706158341ca2873270b3
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:41:33 2017 +0800
v0.3.1
commit 1d6adef3db3ae979cc93970547562621e0940f05
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:28:57 2017 +0800
v0.2
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
[root@node1 app2]#git reset --mixed 1d6adef3 #再次撤销到第二次提交
[root@node1 app2]#git status #发现commit和add操作都被撤销了
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
# (use "git push" to publish your local commits)
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# newfile
nothing added to commit but untracked files present (use "git add" to track)
[root@node1 app2]#git add newfile
[root@node1 app2]#git commit -m "v3.0.2" #再次提交
[master 99797e0] v3.0.2
1 file changed, 1 insertion(+)
create mode 100644 newfile
[root@node1 app2]#git log
commit 99797e0fea11a9ea899b5adb6a73d03fa05d3de1
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:45:24 2017 +0800
v3.0.2
commit 1d6adef3db3ae979cc93970547562621e0940f05
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:28:57 2017 +0800
v0.2
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
[root@node1 app2]#git reset --hard 1d6adef3 #再次撤销至第二次提交
HEAD is now at 1d6adef v0.2
[root@node1 app2]#ls -a #发现连工作目录中的文件也被撤销了
. .. examples .git README
示例:如何添加分支
[root@node1 app2]#git branch --list #查看分支
* master
[root@node1 app2]#git branch stroy2 #添加分支
[root@node1 app2]#git branch stroy3
[root@node1 app2]#git branch --list #发现添加了两个分支
* master #带*表示当前分支
stroy2
stroy3
[root@node1 app2]#ls .git/refs/heads/ #在此目录下生成了三个文件,每个文件就是一个分支
master stroy2 stroy3
[root@node1 app2]#git checkout stroy2 #切换分支
Switched to branch 'stroy2'
[root@node1 app2]#git branch --list
master
* stroy2
stroy3
[root@node1 app2]#vim newfile
stroy 2
[root@node1 app2]#git add newfile
[root@node1 app2]#git commit -m "stroy2.v0.1"
[stroy2 b39a485] stroy2.v0.1
1 file changed, 1 insertion(+)
create mode 100644 newfile
[root@node1 app2]#git log
commit b39a48512bfd6ec7aea8cf6835dfee8d6fc1d644
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:58:06 2017 +0800
stroy2.v0.1
commit 1d6adef3db3ae979cc93970547562621e0940f05
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:28:57 2017 +0800
v0.2
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
[root@node1 app2]#git checkout master #切换回master分支
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
[root@node1 app2]#git branch --list
* master
stroy2
stroy3
[root@node1 app2]#git log #发现不同的分支上所看到的提交历史是不一样的
commit 1d6adef3db3ae979cc93970547562621e0940f05
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:28:57 2017 +0800
v0.2
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
[root@node1 app2]#ls -a
. .. examples .git README
[root@node1 app2]#git branch --list
* master
stroy2
stroy3
[root@node1 app2]#git checkout stroy2
Switched to branch 'stroy2'
[root@node1 app2]#ls -a #我们发现不同的分支,它们的工作目录是不同的
. .. examples .git newfile README
[root@node1 app2]#git checkout master #切换到master分支
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
[root@node1 app2]#git branch --list
* master
stroy2
stroy3
[root@node1 app2]#vim newfile #也创建一个和stroy2一样名字的文件,但内容不同
master newfile
[root@node1 app2]#git add newfile
[root@node1 app2]#git commit -m "v0.3"
[master 304af42] v0.3
1 file changed, 1 insertion(+)
create mode 100644 newfile
[root@node1 app2]#git log #发现在不同分支上名字相同的文件也可以
提交,说明git内部对所有对象的追踪是根据内容的哈希值识别的,而不
是根据文件名
commit 304af4289bc0cb3358d209edf68cd3ed1ddfbfa5
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 22:07:15 2017 +0800
v0.3
commit 1d6adef3db3ae979cc93970547562621e0940f05
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 21:28:57 2017 +0800
v0.2
commit 7fb9eb1f385cb2b5fb5904e8b231436eae8ba78c
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 20:52:11 2017 +0800
initial version
2、在github上如何使用git命令从远程克隆一个仓库
https://github.com 官方网站
[root@node1 network-scripts]#cd /app
[root@node1 app]#git clone https://github.com/happyfish100/fastdfs.git #在github上克隆一个仓库
[root@node1 app]#cd fastdfs/ #发现在此工作目录下也有.git目录
[root@node1 fastdfs]#ls -a
. client conf fastdfs.spec HISTORY INSTALL php_client restart.sh storage tracker
.. common COPYING-3_0.txt .git init.d make.sh README.md stop.sh test
[root@node1 fastdfs]#git config --list
user.name=magedu
user.email=mage@magedu.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://github.com/happyfish100/fastdfs.git #远程工作目录的url
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* #表示本地的工作目录是从远程的origin分支取过来的,远程refs/remotes/origin/*分支下的所有内容对应的是本地分支的refs/heads/master分支下的所有内容
branch.master.remote=origin #远程的master分支在本地表现为origin分支
branch.master.merge=refs/heads/master #本地的master分支的工作目录是来自远程的origin分支的工作目录
[root@node1 fastdfs]#ls .git/refs/remotes/origin/
HEAD
[root@node1 fastdfs]#ls .git/refs/heads/
master
3、在github上创建一个仓库然后克隆到本地修改后再推到github上
在github上注册一个账号,登录后创建一个仓库如下图
image.png
克隆仓库到本地进行编辑
[root@node1 app]#git clone https://github.com/qilinzhicai/testrepos.git
Cloning into 'testrepos'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
[root@node1 app]#cd testrepos/ #进入此工作目录
[root@node1 testrepos]#ls -a
. .. .git README.md
[root@node1 testrepos]#vim myfile
hello this is my first github
[root@node1 testrepos]#git add myfile
[root@node1 testrepos]#git commit -m "githubv0.1"
[master bbd856a] githubv0.1
1 file changed, 1 insertion(+)
create mode 100644 myfile
[root@node1 testrepos]#git log
commit bbd856a7b732ff8ffe60fa24d40d87ec791aeb9a
Author: magedu <mage@magedu.com>
Date: Tue Nov 28 22:41:34 2017 +0800
githubv0.1
commit 9336769479c41cf730fcb3788c5b799beedc609b
Author: qilinzhicai <34060909+qilinzhicai@users.noreply.github.com>
Date: Tue Nov 28 19:24:16 2017 +0800
Initial commit
[root@node1 testrepos]#git tag -a testapp-v0.1 bbd856 #给本次提交添加一个标签为testapp-v0.1
testapp-v0.1
#
# Write a tag message
# Lines starting with '#' will be ignored.
[root@node1 testrepos]#git tag --list
testapp-v0.1
[root@node1 testrepos]#git help tag
[root@node1 testrepos]#git help push
[root@node1 testrepos]#ls .git/refs/tags/ #标签存放在此目录下
testapp-v0.1
[root@node1 testrepos]#git branch --list #当前的分支是在master
* master
[root@node1 testrepos]#ls -a #在master分支下工作目录中有如下内容
. .. .git myfile README.md
[root@node1 testrepos]#git push --tags origin master #表示把本地的
maste分支上的工作目录推到远程的origin分支上的工作目录中,并加标
签,因为远程的master分支在本地表现为origin分支,所以要写成origin
Username for 'https://github.com': qilinzhicai #要输入guthub的账号和密码
Password for 'https://qilinzhicai@github.com':
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 413 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To https://github.com/qilinzhicai/testrepos.git
9336769..bbd856a master -> master
* [new tag] testapp-v0.1 -> testapp-v0.1
可以看到推送成功,其他人就可以用pull把远程的仓库取过来和本地的合并,也可以用fetch把远程仓库的取过来和本地不合并
image.png
总结:在这里我们所说的仓库其实就是在一个分支上的一个工作目录
4、搭建gitlib
gitlib是一个软件,安装此软件后,可以提供一个web界面,相当于github一样的web网站,可以在此网站上创建仓库,进行和github一样的操作
lftp 172.18.0.1:/pub/Sources/7.x86_64/gitlab> ls
-rw-r--r-- 1 0 0 345224324 Aug 21 09:10 gitlab-ce-7.14.3-ce.1.el7.x86_64.rpm
-rw-r--r-- 1 0 0 280689456 Aug 21 09:09 gitlab-ce-8.8.3-ce.0.el7.x86_64.rpm
lftp 172.18.0.1:/pub/Sources/7.x86_64/gitlab> get gitlab-ce-8.8.3-ce.0.el7.x86_64.rpm
280689456 bytes transferred in 4 seconds (70.11M/s)
[root@node1 app]#rpm -ivh ./gitlab-ce-8.8.3-ce.0.el7.x86_64.rpm
[root@node1 app]#rpm -ivh ./gitlab-ce-8.8.3-ce.0.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:gitlab-ce-8.8.3-ce.0.el7 ################################# [100%]
gitlab: Thank you for installing GitLab!
gitlab: To configure and start GitLab, RUN THE FOLLOWING COMMAND:
sudo gitlab-ctl reconfigure #下一步执行此命令
gitlab: GitLab should be reachable at http://node1.magedu.com
gitlab: Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
gitlab: And running reconfigure again.
gitlab:
gitlab: For a comprehensive list of configuration options please see the Omnibus GitLab readme
gitlab: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
gitlab:
It looks like GitLab has not been configured yet; skipping the upgrade script.
[root@node1 app]#gitlab-ctl reconfigure
[root@node1 app]#gitlab-ctl help
[root@node1 app]#gitlab-ctl start #启动
ok: run: gitlab-workhorse: (pid 17791) 84s
ok: run: logrotate: (pid 17168) 120s
ok: run: nginx: (pid 17093) 126s
ok: run: postgresql: (pid 16942) 152s
ok: run: redis: (pid 16858) 158s
ok: run: sidekiq: (pid 17066) 134s
ok: run: unicorn: (pid 18149) 59s
[root@node1 app]#ss -nlt #发现打开了很多端口
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:8080 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
可以看到类似于github的界面了
image.png
5、在github上使用ssh连接克隆或者push到远程仓库的设置
使用ssh连接后不用每次都输入账号和密码
[root@node1 app]#ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)?
[root@node1 app]#cd
[root@node1 ~]#cd .ssh/
[root@node1 .ssh]#ls
authorized_keys id_rsa id_rsa.pub known_hosts
[root@node1 .ssh]#cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQClFgU7bGSRFMmvFXLkb3hhMSCXkRIkaRLjNzk3lPw+AP1nWPGc343p6RprBTqsFLmOqCOjNtwH742PcTmy9WRYCzBlAAw5oTaHoU3EgmqDa43HuWJCl0f0rlaSNo2Vrj6db7e54g/nsz4+ur+icITot47JjgkT5DVpnEw88N33fYNvJJw6DVrfZn/96N0FmaECQXjXsCt5EuOnVH2/J2sOI7EecA+3/00QOdCvTrsuY4bkNAxd3jh+5EC+Xo3ONLtfx3D8ggMpf36nWG/WXWwzR1sPy7tVsLdRICd1k2SH/ul0fXFWACw84aB54XnHaBukxrAhf4nu3v9MJlvBBQWn root@node1.magedu.com
将以上公钥的内容复制到下图的位置即可,注意要事先用自己的账号登录后才能进行如下操作
image.png
image.png
最后添加的时候可能会跳转至一个界面让输入登录账号的密码
添加完后如下图,就可以基于ssh进行github上的远程仓库了
image.png