[TOC]
1、简介
GitLab 是一个综合性的 DevOps 平台,主要用于代码存储和项目管理。它集成了 Git 仓库管理、持续集成和持续交付(CI/CD)、项目管理、安全性等多种功能。
2、功能
1 | [root@gitlab ~]# ls |

1 | # 创建ssl证书存放路径 |

1 | [root@localhost ~]# cat /etc/gitlab/initial_root_password #密码存放地 |



任何人都可以注册帐户。
只允许任何人在GitLab实例上注册您打算供任何人使用的帐户。允许任何人注册会使GitLab实例更容易受到攻击。
更改Root密码



创建新项目




拉取项目代码仓库

上传SSH公钥


1 | # 查看本地公钥 |

拉取代码
1 | # 拉取代码 |

Tag版本推送
GitLab 的 tag(标签)在版本控制中主要用于标记某个特定的提交(commit)点。这些标签通常用于表示软件的发布版本,使得开发者能够轻松地引用和查找这些重要的提交点。
- 版本标记:
- 标签可以标记代码库中的特定版本,如 v1.0.0、v2.1.3 等。这有助于开发者和其他利益相关者(如产品经理、测试人员、用户等)清楚地了解代码的当前状态和历史版本。
- 发布管理:
- 当软件达到某个稳定状态并准备发布时,可以为该状态创建一个标签。这有助于在后续开发过程中追踪和比较不同版本之间的差异。
- 通过标签,可以轻松地回滚到以前的版本,如果新版本出现严重问题或不符合预期。
- 构建和部署:
- 在持续集成/持续部署(CI/CD)流程中,标签经常用于触发构建和部署操作。例如,当一个新的标签被推送到代码库时,CI/CD 系统可以自动构建和部署该版本的软件。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56lenovo@LAPTOP-P0AL7U72 MINGW64 ~/Desktop/study-test-cloud (main)
$ vim tag.txt
lenovo@LAPTOP-P0AL7U72 MINGW64 ~/Desktop/study-test-cloud (main)
$ git add .
warning: in the working copy of 'tag.txt', LF will be replaced by CRLF the next time Git touches it
lenovo@LAPTOP-P0AL7U72 MINGW64 ~/Desktop/study-test-cloud (main)
$ git commit -m "net tag.txt"
[main 3461e18] net tag.txt
1 file changed, 1 insertion(+)
create mode 100644 tag.txt
lenovo@LAPTOP-P0AL7U72 MINGW64 ~/Desktop/study-test-cloud (main)
$ git tag -a "v1.1" -m "new e.txt"
lenovo@LAPTOP-P0AL7U72 MINGW64 ~/Desktop/study-test-cloud (main)
$ git push origin main
lenovo@LAPTOP-P0AL7U72 MINGW64 ~/Desktop/study-test-cloud (main)
$ git push origin v1.1
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 32 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 424 bytes | 424.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To gitlab.tanke.love:gitlab-instance-d5d699e8/study-test-cloud.git
* [new tag] v1.1 -> v1.1
lenovo@LAPTOP-P0AL7U72 MINGW64 ~/Desktop/study-test-cloud (main)
$ git log
commit 3461e180cc300dddd9ea289c619b74f771e57dd9 (HEAD -> main, tag: v1.1)
Author: jiaming <hjm131641@163.com>
Date: Tue Jun 4 23:30:26 2024 +0800
net tag.txt
commit c3aba0f8f1d3fa73789ce7562ed97526433628b0 (origin/main, origin/HEAD)
Author: jiaming <hjm131641@163.com>
Date: Tue Jun 4 23:22:26 2024 +0800
first commit
commit 1416f75324c274ae5b813ee7ce8d80a09d61212b
Author: jiaming <hjm131641@163.com>
Date: Tue Jun 4 23:02:44 2024 +0800
first commit
commit 7f887e5c316766a6cab4b81ba73cfd00e1230fc2
Author: Administrator <admin@example.com>
Date: Tue Jun 4 22:55:52 2024 +0800
Initial commitGitlab备份
设置备份保留时长,防止每天执行备份,肯定有目录被爆满的风险,打开/etc/gitlab/gitlab.rb配置文件,找到如下配置1
2
3
4
5
6
7
8
9# 查看Gitlab的版本
[root@localhost ~]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
15.1.2
# 打开配置文件数据备份
[root@localhost ~]# vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups" #备份的路径
gitlab_rails['backup_archive_permissions'] = 0644 #备份文件的默认权限
gitlab_rails['backup_keep_time'] = 604800 #保留时长,秒为单位
该项定义了默认备份出文件的路径,可以通过修改该配置,并执行 gitlab-ctl reconfigure 或者 gitlab-ctl restart 重启服务生效。1
2
3
4
5
6
7
8
9[root@localhost ~]# gitlab-ctl reconfigure
或者
[root@localhost ~]# gitlab-ctl restart
[root@localhost ~]# echo $?
0
# 执行备份命令进行备份
[root@localhost ~]# gitlab-rake gitlab:backup:create
也可以添加到 crontab 中定时执行:可以到/var/opt/gitlab/backups找到备份包,解压查看,会发现备份的还是比较全面的,数据库、repositories、build、upload等分类还是比较清晰的。备份完成,会在备份目录中生成一个当天日期的tar包。1
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
1
[root@localhost ~]# ll /var/opt/gitlab/backups/
- 在持续集成/持续部署(CI/CD)流程中,标签经常用于触发构建和部署操作。例如,当一个新的标签被推送到代码库时,CI/CD 系统可以自动构建和部署该版本的软件。
Gitlab数据恢复
特别注意:
- 备份目录和gitlab.rb中定义的备份目录必须一致
- GitLab的版本和备份文件中的版本必须一致,否则还原时会报错。
模拟删除数据

1 | [root@localhost ~]# cd /var/opt/gitlab/backups |



恢复完成后,启动刚刚的两个服务,或者重启所有服务,再打开浏览器进行访问,发现数据和之前的一致:
注意:通过备份文件恢复gitlab必须保证两台主机的gitlab版本一致,否则会提示版本不匹配
再次查看Gitlab







