代码仓库

  • 目录
  • 1.代码管理平台介绍
  • 2.安装svn
  • 3.客户端上使用svn(linux)
  • 4.单机上使用git
  • 5.建立远程仓库
  • 6.克隆远程仓库
  • 7.分支管理
  • 8.远程分支管理
  • 9.搭建git服务器
  • 10.gitlab的使用

 

 

1.代码管理平台介绍

功能:版本控制,记录若干文件内容变化,以便将来查阅特定版本修订情况

版本管理工具发展简史,cvs→ svn →git  参考http://luckypoem14.github.io/test/2012/04/24/scm-history/

svn全称subversion,是一个开源版本控制系统,始于2000年

git是linux创始人linus发起的,2005年发布,最初目的是更好管理linux内核代码

git和svn不同在于git不需要依赖服务端就可以工作,即git是分布式的

关于git和svn的比较大家参考http://blog.lishiming.net/?p=305

github是基于git的在线web页面代码托管平台,可以选择付费服务

gitlab可以认为是一个开源的github,两者没有直接关系

 

2.安装svn

安装svn,直接使用yum安装

[root@localhost ~]# yum install -y subversion

创建版本库

[root@localhost ~]# mkdir -p  /data/svnroot/myproject   创建目录
[root@localhost ~]# svnadmin create !$                  初始化目录
svnadmin create /data/svnroot/myproject
[root@localhost ~]# ls !$
ls /data/svnroot/myproject
conf  db  format  hooks  locks  README.txt
主要配置文件
[root@localhost ~]# cd !$/conf
cd /data/svnroot/myproject/conf
[root@localhost conf]# ls
authz  passwd  svnserve.conf

修改组和用户权限

[root@localhost conf]# vi authz 


[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
xiaoqis = xiaoqi,user1

[/]
@xiaoqi=rw
*=r

定义密码

[root@localhost conf]# vi passwd 

### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.

[users]
# harry = harryssecret
# sally = sallyssecret
xiaoqi = 123456
user1 = 123456

 

编辑配置文件


[root@localhost conf]# vi svnserve.conf 


[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
realm = /data/svnroot/myproject

启动svn

[root@localhost conf]# svnserve -d -r /data/svnroot/

查看svn监听端口

[root@localhost conf]# netstat -lntp|grep svn
tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN      13775/svnserve      

 

3.客户端上使用svn(linux

检出文件

[root@localhost conf]# svn checkout svn://192.168.7.111/myproject --username=xiaoqi
取出版本 0。
[root@localhost svntest]# ls
myproject

在客户端上增加文件并传送到服务端上去

[root@localhost myproject]# svn commit -m "add 2.txt"
认证领域: <svn://192.168.7.111:3690> /data/svnroot/myproject
“root”的密码: 
认证领域: <svn://192.168.7.111:3690> /data/svnroot/myproject
用户名: xiaoqi
“xiaoqi”的密码: 

-----------------------------------------------------------------------
注意!  你的密码,对于认证域:

   <svn://192.168.7.111:3690> /data/svnroot/myproject

只能明文保存在磁盘上!  如果可能的话,请考虑配置你的系统,让 Subversion
可以保存加密后的密码。请参阅文档以获得详细信息。

你可以通过在“/root/.subversion/servers”中设置选项“store-plaintext-passwords”为“yes”或“no”,
来避免再次出现此警告。
-----------------------------------------------------------------------
保存未加密的密码(yes/no)?yes
正在增加       2.txt
传输文件数据.
提交后的版本为 1。

svn up命令来同步服务端文件

 

4.单机上使用git

可以不依赖网络

安装git

[root@chenshi ~]# yum install -y git

创建git目录

[root@chenshi ~]# mkdir /data/gitroot

初始化仓库

[root@chenshi gitroot]# git init
初始化空的 Git 版本库于 /data/gitroot/.git/
您在 /var/spool/mail/root 中有新邮件
[root@chenshi gitroot]# 
[root@chenshi gitroot]# ls -la
总用量 0
drwxr-xr-x  3 root root  18 8月  31 09:50 .
drwxrwxrwx 11 root root 241 8月  31 09:49 ..
drwxr-xr-x  7 root root 119 8月  31 09:50 .git

在库里创建一个新的文件;把文件添加到库里面去

[root@chenshi gitroot]# vim 1.txt
您在 /var/spool/mail/root 中有新邮件
[root@chenshi gitroot]# git add 1.txt
[root@chenshi gitroot]# git commit -m "add  1.txt"

使用git status查看状态

[root@xiaoqi gitroot]# git status
# 位于分支 master
无文件要提交,干净的工作区

修改文件后查看git status

[master(根提交) 17ea121] add 1.txt
 1 file changed, 4 insertions(+)
 create mode 100644 1.txt
[root@xiaoqi gitroot]# git status
# 位于分支 master
无文件要提交,干净的工作区
[root@xiaoqi gitroot]# vim 1.txt 
[root@xiaoqi gitroot]# git status
# 位于分支 master
# 尚未暂存以备提交的变更:
#   (使用 "git add <file>..." 更新要提交的内容)
#   (使用 "git checkout -- <file>..." 丢弃工作区的改动)
#
#	修改:      1.txt
#
修改尚未加入提交(使用 "git add" 和/或 "git commit -a")

git diff查看变更

[root@chenshi gitroot]# git diff 1.txt
diff --git a/1.txt b/1.txt
index 8636e8e..a72e529 100644
--- a/1.txt
+++ b/1.txt
@@ -1,4 +1,4 @@
 12312312
 213123
 132123123
-12312
+dsadad12312

[root@xiaoqi gitroot]# git add 1.txt 
[root@xiaoqi gitroot]# git commit -m "add 1.txt"
[master de7d174] add 1.txt
 1 file changed, 1 insertion(+), 1 deletion(-)

查看所有变更记录

[root@xiaoqi gitroot]# git log
commit de7d174316d37f9ae30678b34f6e1175407462e2
Author: xiaoqi <c13761785991@gmail.com>
Date:   Fri Aug 31 10:07:08 2018 +0800

    add 1.txt

commit 17ea12133b1571ffdee87fdf61017c39b96fe707
Author: xiaoqi <c13761785991@gmail.com>
Date:   Fri Aug 31 10:05:43 2018 +0800

    add 1.txt

[root@xiaoqi gitroot]# git log --pretty=oneline
de7d174316d37f9ae30678b34f6e1175407462e2 add 1.txt
17ea12133b1571ffdee87fdf61017c39b96fe707 add 1.txt

回到最早的版本

[root@xiaoqi gitroot]# git reset --hard de7d174316d37f9
HEAD 现在位于 de7d174 add 1.txt

查看所有历史版本

[root@xiaoqi gitroot]# git reflog
de7d174 HEAD@{0}: commit: add 1.txt
17ea121 HEAD@{1}: commit (initial): add 1.txt

当删除文件时可以用git恢复

[root@xiaoqi gitroot]# rm -rf 1.txt 
[root@xiaoqi gitroot]# ls
[root@xiaoqi gitroot]# git checkout -- 1.txt
[root@xiaoqi gitroot]# ls
1.txt

单行显示git log

[root@localhost gitroot]# git log --pretty=oneline
037fc86d6645c818bf2917cb8550e1c904d697f4 add 1.txt
513fdb95aa4b590d17ffc9041ca005a166b687da add 1.txt

如果文件以已经修改,add后没有使用commit,再想回到上次提交的状态可以使用

[root@localhost gitroot]# vi 1.txt 
[root@localhost gitroot]# git add 1.txt 
[root@localhost gitroot]# git status
# 位于分支 master
# 要提交的变更:
#   (使用 "git reset HEAD <file>..." 撤出暂存区)
#
#	修改:      1.txt
#
[root@localhost gitroot]# git reset HEAD 1.txt 
重置后撤出暂存区的变更:
M	1.txt
[root@localhost gitroot]# git checkout -- 1.txt

删除文件

[root@localhost gitroot]# git rm 1.txt 
rm '1.txt'
[root@localhost gitroot]# git commit -m "delete 1.txt"
[master 12c67fd] delete 1.txt
 Committer: root <root@localhost.localdomain>
您的姓名和邮件地址基于登录名和主机名进行了自动设置。请检查它们正确
与否。您可以通过下面的命令对其进行明确地设置以免再出现本提示信息:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

设置完毕后,您可以用下面的命令来修正本次提交所使用的用户身份:

    git commit --amend --reset-author

 1 file changed, 7 deletions(-)
 delete mode 100644 1.txt
[root@localhost gitroot]# ls
[root@localhost gitroot]# git chekout
git:'chekout' 不是一个 git 命令。参见 'git --help'。

您指的是这个么?
	checkout
[root@localhost gitroot]# git checkout
[root@localhost gitroot]# ls

找回文件

[root@localhost gitroot]# git reset --hard 513fdb95aa4b5
HEAD 现在位于 513fdb9 add 1.txt
[root@localhost gitroot]# ls
1.txt

 

 

5.建立远程仓库

到github上面注册一个账号

新建仓库

a10651ad46c66ed15eeec1b39536628f2ca.jpg

a57b3a97912c753c4b7ce72cc9016674cc2.jpg

 

创建完成

63f81444ffe3ba7ff7a727a7b16ab3077ae.jpg

 

添加秘钥

86ee1b416d159bf675e7da8dc47e46054d5.jpg

af05ae149b66a6dda293699ca2e8d2bb06b.jpg

 

 

生成公钥并粘贴进去

[root@localhost gitroot]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:5dRBQSIdwtStGoL+lgMwbCsgp0CjgrVWIz/aq65PfV8 root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|       o+oo==.   |
| oo o   .ooo..   |
|+o.= o    o..    |
|B O + . .+.      |
|== B . .So.      |
|o o.+   .        |
| .. .+..  E      |
| .  ..=. .       |
|.++. . ..        |
+----[SHA256]-----+
[root@localhost gitroot]# cd
[root@localhost ~]# cat .ssh/id_rsa.pub 

40c7a0ad660c39fa8b6a254ded70ac7e3e4.jpg

生成成功

4ad4c880598417be9b7aaba478a3817e26d.jpg

操作流程

[root@localhost tmp]# mkdir test
[root@localhost tmp]# cd test/
[root@localhost test]# echo "# test" >> README.md
[root@localhost test]# git init
初始化空的 Git 版本库于 /tmp/test/.git/
[root@localhost test]# ll -a
总用量 8
drwxr-xr-x   3 root root   35 9月  10 10:29 .
drwxrwxrwt. 11 root root 4096 9月  10 10:29 ..
drwxr-xr-x   7 root root  119 9月  10 10:29 .git
-rw-r--r--   1 root root    7 9月  10 10:29 README.md
[root@localhost test]# git add README.md
[root@localhost test]# git commit -m "123"
[master(根提交) ca15663] 123
 Committer: root <root@localhost.localdomain>
您的姓名和邮件地址基于登录名和主机名进行了自动设置。请检查它们正确
与否。您可以通过下面的命令对其进行明确地设置以免再出现本提示信息:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

设置完毕后,您可以用下面的命令来修正本次提交所使用的用户身份:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)
 create mode 100644 README.md
[root@localhost test]# 
[root@localhost test]# git remote add origin git@github.com:Chenshi77/test.git

推送更改到远程

[root@localhost test]# git push -u origin master
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
Counting objects: 3, done.
Writing objects: 100% (3/3), 212 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:Chenshi77/test.git
 * [new branch]      master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。

a3d11a85e11a949924dc4ca082cb1aadb74.jpg

新增测试

5000621bf25b23cd38b6940810b6c2010a4.jpg

 

6.克隆远程仓库

查看克隆地址

60a6873ffb664dd48fbc0661b713633911a.jpg

就算没有传送公钥也可以克隆下来,但是没有写的权限

[root@localhost home]# git clone git@github.com:Chenshi77/test.git
正克隆到 'test'...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 6 (delta 0), pack-reused 0
接收对象中: 100% (6/6), done.

修改

root@localhost test]# vi README.md 
[root@localhost test]# git add README.md 
[root@localhost test]# git commit -m "change readme.md"
[master 1c82ae2] change readme.md
 Committer: root <root@localhost.localdomain>
您的姓名和邮件地址基于登录名和主机名进行了自动设置。请检查它们正确
与否。您可以通过下面的命令对其进行明确地设置以免再出现本提示信息:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

设置完毕后,您可以用下面的命令来修正本次提交所使用的用户身份:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)
[root@localhost test]# git push
warning: push.default 未设置,它的默认值将会在 Git 2.0 由 'matching'
修改为 'simple'。若要不再显示本信息并在其默认值改变后维持当前使用习惯,
进行如下设置:

  git config --global push.default matching

若要不再显示本信息并从现在开始采用新的使用习惯,设置:

  git config --global push.default simple

参见 'git help config' 并查找 'push.default' 以获取更多信息。
('simple' 模式由 Git 1.7.11 版本引入。如果您有时要使用老版本的 Git,
为保持兼容,请用 'current' 代替 'simple' 模式)

Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
Counting objects: 5, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 282 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:Chenshi77/test.git
   4b133ef..1c82ae2  master -> master

0faa7a26714242cc66f3080e8e94a37d485.jpg

可以在网页上直接编辑

 

7de23c6fcb5301ce533990aeefa974a824d.jpg

在客户端上更新

[root@localhost test]# git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
Unpacking objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
来自 github.com:Chenshi77/test
   1c82ae2..0b1d280  master     -> origin/master
更新 1c82ae2..0b1d280
Fast-forward
 README.md | 3 +++
 1 file changed, 3 insertions(+)
[root@localhost test]# cat README.md 
# test
1
sadas
asdasd
adsad

 

7.分支管理

查看分支

[root@localhost test]# git branch
* master

创建分支

[root@localhost gitroot]# git branch xiaoqi
[root@localhost gitroot]# git branch
* master
  xiaoqi
  *表示现在在哪个分支
[root@localhost gitroot]# git checkout xiaoqi
切换到分支 'xiaoqi'
[root@localhost gitroot]# git branch
  master
* xiaoqi

切换分支

[root@localhost gitroot]# git checkout xiaoqi
切换到分支 'xiaoqi'
[root@localhost gitroot]# git branch
  master
* xiaoqi

在其他分支下创建的文件切换到master下发现没有新的文件,发现分支是相互隔离的

[root@localhost gitroot]# ls
1.txt  2.txt
[root@localhost gitroot]# 
[root@localhost gitroot]# git checkout master
切换到分支 'master'
[root@localhost gitroot]# ls
1.txt

合并分支,先要切换到目标分支

[root@localhost gitroot]# git branch
* master
  xiaoqi
[root@localhost gitroot]# git merge xiaoqi
更新 513fdb9..c7165ce
Fast-forward
 2.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 2.txt
[root@localhost gitroot]# ls
1.txt  2.txt

如果合并分支出现冲突需要把两个文件内容改成一样。

但是这样有一个问题,万一master分支更改的内容是我们想要的呢? 可以编辑2.txt内容,改为想要的,然后提交。切换到aming分支,然后合并master分支到aming分支即可(倒着合并)。合并分支有一个原则,那就是要把最新的分支合并到旧的分支。也就是说merge后面跟的分支名字一定是最新的分支。

删除分支;-D会强制删除分支

[root@localhost gitroot]# git branch -d xiaoqi
已删除分支 xiaoqi(曾为 c7165ce)。
[root@localhost gitroot]# git branch
* master

 

8.远程分支管理

使用分支原则

对于分支的应用,建议大家以这样的原则来:

master分支是非常重要的,线上发布代码用这个分支,平时我们开发代码不要在这个分支上。

创建一个dev分支,专门用作开发,只有当发布到线上之前,才会把dev分支合并到master

开发人员应该在dev的基础上再分支成个人分支,个人分支(在自己pc上)里面开发代码,然后合并到dev分支

a9d35b7d1d67e8536ec831c56f40837a3c3.jpg

dev分支合并bob分支的命令是:

git checkout dev   //先切换到dev分支,然后

git merge bob

创建新的分支

d6da89a46f8b32126828f04e638067b7a70.jpg

 

克隆只能克隆master分支;查看远程所有分支

[root@localhost test]# git ls-remote origin
89c6a00224751321a769365a58be693093e5569a	HEAD
89c6a00224751321a769365a58be693093e5569a	refs/heads/dev
89c6a00224751321a769365a58be693093e5569a	refs/heads/master
本地新建的分支如果不推送到远程,对其他人就是不可见的
 查看远程分支  git ls-remote origin,可以看到所有分支
 对于git push分支分两种情况
 当本地分支和远程分支一致时
 git push会把所有本地分支的变更一同推送到远程,如果想只推送一个分支,使用git push origin branch-name
 当本地分支比远程分支多,默认git push 只推送本地和远程一致的分支,想要把多出来的本地分支推送到远程时,使用git push origin branch-name  如果推送失败,先用git pull抓取远程的新提交
 git clone的时候默认只把master分支克隆下来,如果想把所有分支都克隆下来,需要手动创建,在本地创建和远程分支对应的分支,使用git checkout -b branch-name origin/branch-name,本地和远程分支的名称要一致


[root@localhost test]# git checkout -b dev origine/dev
fatal: 不能同时更新路径并切换到分支'dev'。
您是想要检出 'origine/dev' 但其未能解析为提交么?
[root@localhost test]# git checkout -b dev 
切换到一个新分支 'dev'
[root@localhost test]# git branch
* dev
  master

 

9.搭建git服务器

安装git

[root@chenshi ~]# yum install -y git

添加用户

[root@chenshi ~]# useradd -s /usr/bin/git-shell git
[root@chenshi ~]# cd /home/git/
[root@chenshi git]# mkdir .ssj
[root@chenshi git]# mv .ssj .ssh
[root@chenshi git]# cd !$
cd .ssh
您在 /var/spool/mail/root 中有邮件
[root@chenshi .ssh]# touch .ssh/authorized_keys
touch: 无法创建".ssh/authorized_keys": 没有那个文件或目录
[root@chenshi .ssh]# touch authorized_keys
[root@chenshi .ssh]# chmod 600 !$
chmod 600 authorized_keys
[root@chenshi .ssh]# chown -R git:git .ssh
chown: 无法访问".ssh": 没有那个文件或目录
[root@chenshi .ssh]# cd ..
[root@chenshi git]# chown -R git:git .ssh
[root@chenshi git]# vi .ssh/authorized_keys 

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5ojg4Guv6DLn8Ysw0tWhrnJ7s8okPtTWRFKNt8eINRtinMq3x5CEzYyHfQ+NAJscGDURMbLyRixWvZyQSLCYbxAbVyK6Q3f6OBMclf8Lc6c0ONmNLTw/J6syj8NWP3z+IpNDjlO/PgNdnXQfw2OPRJDmmNWmBmrIYVHeAmyaaQKm2qACAiCkCYHF91a4gRhVGJgvWrvtNjXFFCV7lzKM2NABWDLobVvxnwb7OIEjeOQQgLLHoFqb8teLDmK60zXckVnA0Rx+7/1HcAtptYSGO2vM7FEUUSlBe9lGIJoM327+8ANRkXRMZ8wGeDb9kmqLKtwBIorH0w6kQOHwmKZgr root@localhost.localdomain

查看验证是否成功

root@localhost ~]# ssh git@192.168.1.197
The authenticity of host '192.168.1.197 (192.168.1.197)' can't be established.
ECDSA key fingerprint is SHA256:S/jF/jNzwC/e1l2AVb0pXYLxjxzy7v3qvRh8+WkjKuw.
ECDSA key fingerprint is MD5:47:5e:33:c6:25:5d:87:55:cc:e8:7b:49:a2:e0:99:5a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.197' (ECDSA) to the list of known hosts.
fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to 192.168.1.197 closed.

初始化空仓库

[root@chenshi gitroot]# git init --bare sample.git 
初始化空的 Git 版本库于 /data/gitroot/sample.git/

修改属主

[root@chenshi gitroot]# chown -R git.git sample.git

在客户端上克隆仓库

[root@localhost ~]# git clone git@192.168.1.197:/data/gitroot/sample.git
正克隆到 'sample'...
warning: 您似乎克隆了一个空版本库。
[root@localhost ~]# cd sample/
[root@localhost sample]# ls -la
总用量 0
drwxr-xr-x  3 root root  18 9月  10 13:47 .
dr-xr-x---. 4 root root 183 9月  10 13:47 ..
drwxr-xr-x  7 root root 119 9月  10 13:47 .git

git push需要加上分支才可以同步(由于之前的仓库是空的);其他客户端可以使用git pull来拉取变更

[root@localhost sample]# git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 209 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.1.197:/data/gitroot/sample.git
 * [new branch]      master -> master

 

10.安装gitlab

gitlab官网 https://about.gitlab.com/gitlab-com/

官方安装文档 https://about.gitlab.com/installation/?version=ce#centos-7 (ce/ee)

要求服务器内存不少于2g

编辑gitlab的repo

[root@chenshi ~]# vim /etc/yum.repos.d/gitlab.repo

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1

开始安装

[root@chenshi ~]# yum install -y gitlab-ce
It looks like GitLab has not been configured yet; skipping the upgrade script.

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.
  


     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/
  

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
  sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

  验证中      : gitlab-ce-11.2.3-ce.0.el7.x86_64                                                         1/1 

已安装:
  gitlab-ce.x86_64 0:11.2.3-ce.0.el7                                                                         

完毕!

配置gitlab

[root@chenshi ~]# gitlab-ctl reconfigure
Running handlers:
Running handlers complete
Chef Client finished, 428/614 resources updated in 02 minutes 40 seconds
gitlab Reconfigured!

[root@chenshi ~]# ps aux|grep git
root     12345  0.0  0.0   4380   488 ?        Ss   13:08   0:00 runsvdir -P /opt/gitlab/service log: ...........................................................................................................................................................................................................................................................................................................................................................................................................
gitlab-+ 12371  0.2  0.1  41528 11824 ?        Ssl  13:08   0:00 /opt/gitlab/embedded/bin/redis-server 127.0.0.1:0
gitlab-+ 12437  0.0  0.8 2633016 82356 ?       Ss   13:08   0:00 /opt/gitlab/embedded/bin/postgres -D /var/opt/gitlab/postgresql/data
gitlab-+ 12439  0.0  0.2 2633152 22460 ?       Ss   13:08   0:00 postgres: checkpointer process   
gitlab-+ 12440  0.0  0.2 2633016 21976 ?       Ss   13:08   0:00 postgres: writer process   
gitlab-+ 12441  0.0  0.1 2633016 18772 ?       Ss   13:08   0:00 postgres: wal writer process   
gitlab-+ 12442  0.0  0.0 2633560 3404 ?        Ss   13:08   0:00 postgres: autovacuum launcher process   
gitlab-+ 12443  0.0  0.0  32912  2632 ?        Ss   13:08   0:00 postgres: stats collector process   
git      12703  0.0  0.0  11688  1604 ?        Ss   13:09   0:00 /bin/bash /opt/gitlab/embedded/bin/gitlab-unicorn-wrapper
git      12721 13.0  4.4 704204 441500 ?       Sl   13:09   0:24 unicorn master -D -E production -c /var/optgitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru
git      12745 13.2  5.3 839008 532512 ?       Ssl  13:09   0:23 sidekiq 5.1.3 gitlab-rails [0 of 25 busy]
root     12770  0.0  0.0   4228   348 ?        Ss   13:09   0:00 runsv gitlab-workhorse
root     12811  0.0  0.0  11680  1420 ?        Ss   13:09   0:00 /bin/sh /opt/gitlab/embedded/bin/gitlab-logrotate-wrapper
git      12849  0.1  4.3 704208 435676 ?       Sl   13:09   0:00 unicorn worker[0] -D -E production -c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru
git      12852  0.1  4.3 704208 435672 ?       Sl   13:09   0:00 unicorn worker[1] -D -E production -c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru
git      12855  0.1  4.3 704208 435548 ?       Sl   13:09   0:00 unicorn worker[2] -D -E production -c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru
root     12859  0.0  0.0   4228   344 ?        Ss   13:09   0:00 runsv gitaly
gitlab-+ 13049  0.1  0.1  18532 10876 ?        Ssl  13:10   0:00 /opt/gitlab/embedded/bin/node_exporter --web.listen-address=localhost:9100 --collector.textfile.directory=/var/opt/gitlab/node-exporter/textfile_collector
root     13066  0.0  0.0   4228   344 ?        Ss   13:10   0:00 runsv gitlab-monitor
gitlab-+ 13095  0.0  0.1 162408 12644 ?        Ssl  13:10   0:00 /opt/gitlab/embedded/bin/redis_exporter -web.listen-address=localhost:9121 -redis.addr=unix:///var/opt/gitlab/redis/redis.socket
gitlab-+ 13159  0.0  0.0 2738440 8748 ?        Ss   13:10   0:00 postgres: gitlab gitlabhq_production [local] idle
gitlab-+ 13273  0.0  0.0 2738444 9972 ?        Ss   13:10   0:00 postgres: gitlab gitlabhq_production [local] idle
git      13291  0.0  0.1 158544 13556 ?        Ssl  13:10   0:00 /opt/gitlab/embedded/bin/gitlab-workhorse -listenNetwork unix -listenUmask 0 -listenAddr /var/opt/gitlab/gitlab-workhorse/socket -authBackend http://localhost:8080 -authSocket /var/opt/gitlab/gitlab-rails/sockets/gitlab.socket -documentRoot /opt/gitlab/embedded/service/gitlab-rails/public -pprofListenAddr  -prometheusListenAddr localhost:9229 -secretPath /opt/gitlab/embedded/service/gitlab-rails/.gitlab_workhorse_secret -config config.toml
git      13309  0.2  0.1 411668 19604 ?        Ssl  13:10   0:00 /opt/gitlab/embedded/bin/gitaly /var/opt/gilab/gitaly/config.toml
root     13324  0.0  0.0   4372   568 ?        S    13:10   0:00 svlogd -tt /var/log/gitlab/gitaly
git      13329  0.9  0.2 327900 27272 ?        Ssl  13:10   0:01 /opt/gitlab/embedded/bin/ruby /opt/gitlab/embedded/bin/gitlab-mon web -c /var/opt/gitlab/gitlab-monitor/gitlab-monitor.yml
git      13333  1.4  0.5 1313132 59532 ?       Sl   13:10   0:01 ruby /opt/gitlab/embedded/service/gitaly-ruby/bin/gitaly-ruby 13309 /tmp/gitaly-ruby834790710/socket.0
git      13336  1.4  0.5 1314580 58864 ?       Sl   13:10   0:01 ruby /opt/gitlab/embedded/service/gitaly-ruby/bin/gitaly-ruby 13309 /tmp/gitaly-ruby834790710/socket.1
root     13337  0.0  0.0   4372   344 ?        S    13:10   0:00 svlogd -tt /var/log/gitlab/redis
root     13338  0.0  0.0   4372   348 ?        S    13:10   0:00 svlogd -tt /var/log/gitlab/postgresql
root     13340  0.0  0.0   4372   348 ?        S    13:10   0:00 svlogd -tt /var/log/gitlab/unicorn
root     13341  0.0  0.0   4372   348 ?        S    13:10   0:00 svlogd -tt /var/log/gitlab/sidekiq
root     13350  0.0  0.0   4372   564 ?        S    13:10   0:00 svlogd -tt /var/log/gitlab/gitlab-monitor
root     13354  0.0  0.0   4372   348 ?        S    13:10   0:00 svlogd -tt /var/log/gitlab/gitlab-workhorse
root     13355  0.0  0.0   4372   564 ?        S    13:10   0:00 svlogd -tt /var/log/gitlab/nginx
root     13356  0.0  0.0   4372   348 ?        S    13:10   0:00 svlogd -tt /var/log/gitlab/logrotate
gitlab-+ 13360  0.7  0.7 600204 70976 ?        Ssl  13:10   0:00 /opt/gitlab/embedded/bin/prometheus -web.listen-address=localhost:9090 -storage.local.path=/var/opt/gitlab/prometheus/data -storage.local.chunk-encoding-version=2 -storage.local.target-heap-size=231688929 -config.file=/var/opt/gitlab/prometheus/prometheus.yml
root     13373  0.0  0.0   4372   564 ?        S    13:10   0:00 svlogd -tt /var/log/gitlab/prometheus
gitlab-+ 13378  0.0  0.1 310896 13232 ?        Ssl  13:10   0:00 /opt/gitlab/embedded/bin/alertmanager --web.listen-address=localhost:9093 --storage.path=/var/opt/gitlab/alertmanager/data --config.file=/var/opt/gitlab/alertmanager/alertmanager.yml
root     13379  0.0  0.0   4372   344 ?        S    13:10   0:00 svlogd -tt /var/log/gitlab/node-exporter
root     13394  0.0  0.0   4372   568 ?        S    13:10   0:00 svlogd -tt /var/log/gitlab/alertmanager
gitlab-+ 13398  0.0  0.1 142072 10248 ?        Ssl  13:10   0:00 /opt/gitlab/embedded/bin/postgres_exporter --web.listen-address=localhost:9187 --extend.query-path=/var/opt/gitlab/postgres-exporter/queries.yaml
gitlab-+ 13404  0.1  0.1 2739076 10944 ?       Ss   13:10   0:00 postgres: gitlab-psql postgres [local] idle
root     13405  0.0  0.0   4372   344 ?        S    13:10   0:00 svlogd -tt /var/log/gitlab/redis-exporter
root     13407  0.0  0.0   4372   344 ?        S    13:10   0:00 svlogd -tt /var/log/gitlab/postgres-exporter
gitlab-+ 13506  0.1  0.1 2739172 11740 ?       Ss   13:10   0:00 postgres: gitlab gitlabhq_production [local] idle
gitlab-+ 13507  0.0  0.0 2738168 9016 ?        Ss   13:10   0:00 postgres: gitlab gitlabhq_production [local] idle
gitlab-+ 13508  0.0  0.1 2738452 10076 ?       Ss   13:10   0:00 postgres: gitlab gitlabhq_production [local] idle
gitlab-+ 13541  0.0  0.0 2738444 9968 ?        Ss   13:10   0:00 postgres: gitlab gitlabhq_production [local] idle
root     13880  0.5  0.0  37936  3096 ?        Ss   13:12   0:00 /opt/gitlab/embedded/sbin/nginx -p /var/optgitlab/nginx
git      13883  0.0  0.0   4360   352 ?        S    13:12   0:00 sleep 1
root     13888  0.0  0.0 112724   972 pts/0    R+   13:12   0:00 grep --color=auto git

浏览器访问gitlab,输入ip即可

4db3bbfb0f0163c16126418969c7def2281.jpg

默认管理员root,无密码,它会让我们去定义一个密码

e52e7328ebe96324a8be5e362cb5fc340ef.jpg

gitlab常用命令  https://www.cnyunwei.cc/archives/1204

使用代理需要编辑文件

[root@chenshi ~]# cd /var/opt/gitlab/nginx/conf/
[root@chenshi conf]# ls
gitlab-http.conf  nginx.conf  nginx-status.conf
[root@chenshi conf]# vi gitlab-http.conf 

f323ad39f6b062f867f29815d0adb2a183f.jpg

 

创建新用户

8e8d861aa9b46a4acc9c6f6b79ff4fa71f2.jpg

 

Google翻译,你值得拥有……哈哈哈哈哈哈

 

11.gitlab备份和恢复

 gitlab备份  gitlab-rake gitlab:backup:create
 备份目录在/var/opt/gitlab/backups
 gitlab 恢复  先停服务 gitlab-ctl stop unicorn ; gitlab-ctl stop sidekiq
 gitlab-rake gitlab:backup:restore BACKUP=xxxxx (这里是一个编号,即备份文件的前缀)
 再启动服务 gitlab-ctl start 

 

 

 

 

 

 

 

 

 

转载于:https://my.oschina.net/u/3850968/blog/2046047

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值