第1章 gitlab安裝部署
1.官方網(wǎng)站
https://about.gitlab.com/install/#centos-7
2.安裝依賴
yum -y install policycoreutils-python.x86_64 openssh-server curl
3.安裝gitlab
方法1:添加清華源侦另,然后安裝
cat > /etc/yum.repos.d/gitlab-ce.repo <<EOF
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
EOF
方法2:直接下載指定版本的清華源rpm包
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
安裝命令
yum -y install gitlab-ce
4.修改配置文件
修改external_url為本機(jī)IP
vim /etc/gitlab/gitlab.rb
external_url 'http://10.0.0.200'
5.重新加載配置并啟動(dòng)
這一步耗時(shí)比較長(zhǎng)骂倘,耐心等待
gitlab-ctl reconfigure
6.gitlab常用命令
查看當(dāng)前狀態(tài)
gitlab-cli status
啟動(dòng)服務(wù)
gitlab-cli start
停止服務(wù)
gitlab-cli stop
停止單個(gè)服務(wù)
gitlab-ctl stop nginx
啟動(dòng)單個(gè)服務(wù)
gitlab-ctl start nginx
查看服務(wù)日志
gitlab-ctl tail
7.web頁(yè)面訪問(wèn)
初次登陸gitlab需要我們?cè)O(shè)置密碼娶耍,密碼長(zhǎng)度不低于8位
設(shè)置完密碼之后我們就可以登陸了闭树,用戶名為root,密碼為剛才設(shè)置的密碼:
登錄后的界面:
第2章 gitlab權(quán)限說(shuō)明
1.用戶-項(xiàng)目組-項(xiàng)目說(shuō)明
1.項(xiàng)目由項(xiàng)目組來(lái)創(chuàng)建抗斤,而不是由用戶創(chuàng)建
2.用戶通過(guò)加入到不同的組肾筐,來(lái)實(shí)現(xiàn)對(duì)項(xiàng)目的訪問(wèn)或者提交
3.項(xiàng)目可以設(shè)置為只有項(xiàng)目組可以查看枫疆,所有登陸用戶可以查看和誰(shuí)都可以看三種
2.建議的操作流程
1.創(chuàng)建組
2.基于組創(chuàng)建項(xiàng)目
3.創(chuàng)建用戶忘分,分配組棋枕,分配權(quán)限
3.說(shuō)明圖
第3章 gitlab權(quán)限實(shí)驗(yàn)
1.需求分析
文字版
1.創(chuàng)建2個(gè)組
dev
ops
2.創(chuàng)建2個(gè)項(xiàng)目
ansible
game
3.創(chuàng)建3個(gè)用戶
cto
olya_ops
oldya_dev
4.分配權(quán)限
cto 對(duì)所有組都有權(quán)限,擁有合并分支的權(quán)限
oldya_dev 對(duì)dev組有所有權(quán)限,可以推拉代碼
oldya_ops 對(duì)ops組有所有權(quán)限妒峦,可以推拉代碼重斑,對(duì)dev組有拉取代碼的權(quán)限
圖表版
2.創(chuàng)建組
2.1 創(chuàng)建dev組
2.2 創(chuàng)建ops組
2.3 檢查
3.創(chuàng)建項(xiàng)目
3.1 創(chuàng)建game項(xiàng)目
<img src="https://upload-images.jianshu.io/upload_images/14248468-5378c5da17467800.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" />
3.2 創(chuàng)建ansible項(xiàng)目
4.創(chuàng)建用戶
4.1 創(chuàng)建cto用戶
創(chuàng)建密碼
4.2 創(chuàng)建oldya_dev用戶
修改密碼
4.3 創(chuàng)建oldya_ops用戶
修改密碼
4.4 檢查
5.授權(quán)
5.1 dev組添加用戶
添加cto賬戶
添加oldya_dev用戶
添加oldya_ops用戶
檢查
5.2 ops組添加用戶
添加cto用戶
添加ops用戶
檢查
6.取消用戶注冊(cè)
7.dev用戶拉取上傳測(cè)試
7.1 dev用戶登陸并修改密碼
<img src="/Users/zhangya/Library/Application Support/typora-user-images/image-20200805204446773.png" alt="image-20200805204446773" style="zoom: 67%;" />
<img src="https://upload-images.jianshu.io/upload_images/14248468-db679982ac46eba6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" style="zoom:50%;" />
7.2 添加SSH公匙
要想dev用戶能免密克隆上傳項(xiàng)目,需要將開(kāi)發(fā)者電腦的ssh公鑰上傳到項(xiàng)目的倉(cāng)庫(kù)中
生成SSH密鑰對(duì)
ssh-keygen -f /root/.ssh/id_rsa -N ''
復(fù)制公鑰
[root@web-7 ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZS9kTGlim0k8zhCSPWp/gsg7ll5ymn91bS7ADuTp4B+5fkt3Tyo+TdgUKD786mkyNH9bJK3W3rwN5SviQJCOKemPVCJCzmewbdubweeZ/ZfXQFZ/iOvB6uiWD1THbfEG8OUxT7OVQiVffwhyXdtGnifcpu/hNWmDWDArFXlR7fvT84QpIOvWC8TKpHM//6EsQgPv4lfM1oLOXNEcoW7DGmQhuWkhiYBzjiYxfRfZo6H5G0WNMwx1piC9MnLbbIBxRp201gtPJZjykSe8le2wJiUU0i6DAObjSo2Nfshwjdc020qaCKFG/1sH9GsUzLBJ3l44Tuj6HdPH/0poejCxP root@web-7
將公鑰信息添加到項(xiàng)目里
7.3 克隆項(xiàng)目
git克隆命令
[root@web-7 ~]# git clone git@10.0.0.200:dev/game.git
正克隆到 'game'...
The authenticity of host '10.0.0.200 (10.0.0.200)' can't be established.
ECDSA key fingerprint is SHA256:FD6YcWj3q66GnZZX7Qa36YpguJn7g70H3sJQu9Y7OcM.
ECDSA key fingerprint is MD5:e8:e1:ab:63:d4:91:1a:c4:f6:3e:fb:cf:27:93:40:f0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.200' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
接收對(duì)象中: 100% (3/3), done.
[root@web-7 ~]# ll
總用量 0
drwxr-xr-x 3 root root 35 8月 5 20:54 game
[root@web-7 ~]# ll game/
總用量 4
-rw-r--r-- 1 root root 8 8月 5 20:54 README.md
7.4 創(chuàng)建新分支并修改代碼提交
[root@web-7 ~]# cd game/
#創(chuàng)建新分支
[root@web-7 ~/game]# git checkout -b game_v1
切換到一個(gè)新分支 'game_v1'
#創(chuàng)建首頁(yè)文件
[root@web-7 ~/game]# echo "v1" > index.html
#提交修改的文件到暫存區(qū)
[root@web-7 ~/game]# git add .
#提交暫存區(qū)記錄到本地倉(cāng)庫(kù)
[root@web-7 ~/game]# git commit -m "create index"
[game_v1 0febf4c] create index
1 file changed, 1 insertion(+)
create mode 100644 index.html
#推送到遠(yuǎn)程倉(cāng)庫(kù)的分支
[root@web-7 ~/game]# git push origin game_v1
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 271 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for game_v1, visit:
remote: http://10.0.0.200/dev/game/merge_requests/new?merge_request%5Bsource_branch%5D=game_v1
remote:
To git@10.0.0.200:dev/game.git
* [new branch] game_v1 -> game_v1
7.5 gitlab創(chuàng)建合并請(qǐng)求
7.6 cto用戶合并分支
使用cto用戶登陸肯骇,然后將分支合并到master主干
7.7 檢查
8.ops用戶拉取上傳測(cè)試
8.1 oldya_ops用戶創(chuàng)建SSH密鑰對(duì)
[root@web-8 ~]# ssh-keygen -f /root/.ssh/id_rsa -N ''
Generating public/private rsa key pair.
Created directory '/root/.ssh'.
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:eUe4jLkE0Hyp0yU3tCkqtGZRf5/i0rDnT415V60Neag root@web-8
The key's randomart image is:
+---[RSA 2048]----+
| .o. o. |
| oo.+ ++ |
| o .+o+=.. |
| . ooo.B + . o.|
| = ..S = + + +|
| o . . B o = =.|
| + + E + o|
| + . . . |
| ... |
+----[SHA256]-----+
[root@web-8 ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDJrUsBKg8bKRhwOBuEMmctufi0c4R7OEMcOR6WvYzR8O20EB8NR4mb/TJg45vOFoKuGT+NIwknvhMGrKAdl6UA1m5C9e1EZVZI13ZbuOsKTiiEyN/kXTzmpgkhyBC2jS8zHkGVJ4w4+QThax9yl5hAbUZBkuccwZJKYktWnRMcbp2Fe/qBBJauenvcvpeWonneOCyeH57FUrQNmYoJpJeW6WwMEs27IhULfjVKC7u78wXRXTGZFlx6lwKymgOevLp0rdZA12E8pnvFBfwzCW1nk+uVwfSSYXYrVBoSAk2D2Qy+YSCxxx9GrjS2tRMFO5iT0Bp7dbgKSl2Hb3sfJoqR root@web-8
8.2 gitlab項(xiàng)目添加公鑰信息
8.3 克隆項(xiàng)目
[圖片上傳失敗...(image-886b3f-1598313773268)]
克隆代碼
[root@web-8 ~]# git clone git@10.0.0.200:ops/ansible.git
正克隆到 'ansible'...
The authenticity of host '10.0.0.200 (10.0.0.200)' can't be established.
ECDSA key fingerprint is SHA256:FD6YcWj3q66GnZZX7Qa36YpguJn7g70H3sJQu9Y7OcM.
ECDSA key fingerprint is MD5:e8:e1:ab:63:d4:91:1a:c4:f6:3e:fb:cf:27:93:40:f0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.200' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
接收對(duì)象中: 100% (3/3), done.
8.4 創(chuàng)建新分支并修改代碼提交
[root@web-8 ~/ansible]# ls
README.md
#切換分支
[root@web-8 ~/ansible]# git checkout -b add_nginx
切換到一個(gè)新分支 'add_nginx'
#創(chuàng)建新文件
[root@web-8 ~/ansible]# echo "nginx" >> nginx.yaml
#查看跟蹤狀態(tài)
[root@web-8 ~/ansible]# git status
# 位于分支 add_nginx
# 未跟蹤的文件:
# (使用 "git add <file>..." 以包含要提交的內(nèi)容)
#
# nginx.yaml
提交為空窥浪,但是存在尚未跟蹤的文件(使用 "git add" 建立跟蹤)
#提交更新文件到暫存區(qū)
[root@web-8 ~/ansible]# git add .
#提交暫存區(qū)文件到本地倉(cāng)庫(kù)
[root@web-8 ~/ansible]# git commit -m "add nginx.yaml"
[add_nginx c368e6a] add nginx.yaml
1 file changed, 1 insertion(+)
create mode 100644 nginx.yaml
#查看狀態(tài)
[root@web-8 ~/ansible]# git status
# 位于分支 add_nginx
無(wú)文件要提交,干凈的工作區(qū)
#提交本地倉(cāng)庫(kù)文件到遠(yuǎn)程分支
[root@web-8 ~/ansible]# git push origin add_nginx
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 280 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for add_nginx, visit:
remote: http://10.0.0.200/ops/ansible/merge_requests/new?merge_request%5Bsource_branch%5D=add_nginx
remote:
To git@10.0.0.200:ops/ansible.git
* [new branch] add_nginx -> add_nginx
8.5 登陸gitlab創(chuàng)建合并請(qǐng)求
8.6 cto用戶合并分支
8.7 檢查
8.8 oldya_ops測(cè)試能否修改上傳game代碼
#ops用戶可以正车驯克隆代碼
[root@web-8 ~]# git clone git@10.0.0.200:dev/game.git
正克隆到 'game'...
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 7 (delta 0), reused 0 (delta 0)
接收對(duì)象中: 100% (7/7), done.
#進(jìn)入項(xiàng)目目錄
[root@web-8 ~]# cd game/
[root@web-8 ~/game]# ls
index.html README.md
#切換新分支
[root@web-8 ~/game]# git checkout -b ops
切換到一個(gè)新分支 'ops'
#創(chuàng)建新文件
[root@web-8 ~/game]# touch ops.txt
#檢查
[root@web-8 ~/game]# git status
# 位于分支 ops
# 未跟蹤的文件:
# (使用 "git add <file>..." 以包含要提交的內(nèi)容)
#
# ops.txt
提交為空漾脂,但是存在尚未跟蹤的文件(使用 "git add" 建立跟蹤)
#提交新文件到暫存區(qū)
[root@web-8 ~/game]# git add .
#提交暫存區(qū)文件到本地倉(cāng)庫(kù)
[root@web-8 ~/game]# git commit -m "add ops.txt"
[ops 9017ede] add ops.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 ops.txt
#檢查
[root@web-8 ~/game]# git status
# 位于分支 ops
無(wú)文件要提交,干凈的工作區(qū)
#提交到遠(yuǎn)程分支提示報(bào)錯(cuò)胚鸯,沒(méi)有提交權(quán)限
[root@web-8 ~/game]# git push origin ops
> GitLab: You are not allowed to push code to this project.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
[root@web-8 ~/game]#
第4章 gitlab備份
1.備份
編輯配置文件骨稿,添加備份路徑:
vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
重新生效配置:
gitlab-ctl reconfigure
創(chuàng)建備份目錄:
mkdir /backup
備份命令:
[root@gitlab-200 ~]# gitlab-rake gitlab:backup:create
2020-08-05 07:27:09 +0800 -- Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2020-08-05 07:27:11 +0800 -- done
2020-08-05 07:27:11 +0800 -- Dumping repositories ...
2020-08-05 07:27:11 +0800 -- done
2020-08-05 07:27:11 +0800 -- Dumping uploads ...
2020-08-05 07:27:11 +0800 -- done
2020-08-05 07:27:11 +0800 -- Dumping builds ...
2020-08-05 07:27:11 +0800 -- done
2020-08-05 07:27:11 +0800 -- Dumping artifacts ...
2020-08-05 07:27:11 +0800 -- done
2020-08-05 07:27:11 +0800 -- Dumping pages ...
2020-08-05 07:27:11 +0800 -- done
2020-08-05 07:27:11 +0800 -- Dumping lfs objects ...
2020-08-05 07:27:12 +0800 -- done
2020-08-05 07:27:12 +0800 -- Dumping container registry images ...
2020-08-05 07:27:12 +0800 -- [DISABLED]
Creating backup archive: 1596583632_2020_08_05_13.2.2_gitlab_backup.tar ... done
Uploading backup archive to remote storage ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... skipping
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
Backup task is done.
剛才備份的時(shí)候我們發(fā)現(xiàn)有一條警告,意思是有g(shù)itlab-secrets.json文件里包含了敏感信息姜钳,需要我們手動(dòng)備份坦冠,所以恢復(fù)的時(shí)候需要將備份文件和這個(gè)json文件一起恢復(fù)才行。
備份gitlab-secrets.json配置文件
cp /etc/gitlab/gitlab-secrets.json /backup/
查看備份結(jié)果:
[root@gitlab-200 ~]# ll /backup/
總用量 220
-rw------- 1 git git 204800 8月 5 07:27 1596583632_2020_08_05_13.2.2_gitlab_backup.tar
-rw------- 1 root root 18771 8月 5 07:30 gitlab-secrets.json
2.恢復(fù)
恢復(fù)時(shí)最好不要有數(shù)據(jù)寫(xiě)入,所以我們可以先停止服務(wù)
gitlab-ctl stop
將json文件復(fù)制到指定位置:
cp /backup/gitlab-secrets.json /etc/gitlab/
恢復(fù)操作:
gitlab-rake gitlab:backup:restore BACKUP=1596583632_2020_08_05_13.2.2
重新載入配置
gitlab-ctl reconfigure
第5章 gitlab漢化
官方自帶中文哥桥,只不過(guò)翻譯的不完整辙浑。