Linux的阿里云等外网服务器配置gitLab公司git仓库

由于一部分业务存在保密行为,放在gitHub上或许不太好, Gitee的团队仓库又要钱,不想使用svn,所以就有了在自己公司搭建一个git的代码管理仓库,就看上了gitLab。

1、首先下载gitLab安装包:

centos 6系统的下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6

centos 7系统的下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7

(下载过慢可以开vpn去国外官网上下载,清华镜像下载这个容易下到半途就中断链接)

点击进去选择你想需要下载的gitLab安装包,这里建议下载近邻你的日期的版本,这里我安装的日期是2021年7月,所以版本选择的是gitlab-ce-13.8.2-ce.0.el7.x86_64.rpm

然后使用下面的代码下载

1
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.8.2-ce.0.el7.x86_64.rpm

点击并拖拽以移动

这里推荐下载在/usr/local/。

2、使用rpm -i gitlab-ce-8.0.0-ce.0.el7.x86_64.rpm安装

注:在这一步可能会提示policycoreutils-python的问题,这是因为找不到这个依赖包,运行以下代码即可。

1
yum install -y curl policycoreutils-python openssh-server

点击并拖拽以移动

3、修改配置文件,注意不要跟已有端口冲突,没有vim的使用vi命令。

1
vim  /etc/gitlab/gitlab.rb

点击并拖拽以移动

找到下图的地方修改对应的url以及端口,如果搭配的服务器是外网服务器,直接写外网的url:端口,记得开放端口,阿里云就在安全组规则开放端口。

img点击并拖拽以移动

4、启动gitLab

1
2
gitlab-ctl reconfigure
gitlab-ctl restart

点击并拖拽以移动

分别运行这两条命令,在第一步一步可能会等待很久,不要暂停,静等即可。运行第二条的时候弹出一堆ok即证明运行成功。

5、启动完成之后直接在浏览器输入ip地址加端口即可进入,初始页面会更改初始密码,8位以上,初始用户为root。

6、搭配完成之后,由于担心服务器攻击,所以会设置备份,普通的手备份可以使用

1
gitlab-rake gitlab:backup:create

点击并拖拽以移动

默认的备份地址在/var/opt/gitlab/backups

同时可以设置自动备份(推荐):

首先使用以下命令,打开定时器文档编辑器

1
crontab -e

点击并拖拽以移动

然后在里面写定时的日期,这里我选择的是每周1、3、5、7的晚上2点定时保存

1
2
3
4
0 2 * * 5 /opt/gitlab/bin/gitlab-rake gitlab:backup:create
0 2 * * 1 /opt/gitlab/bin/gitlab-rake gitlab:backup:create
0 2 * * 3 /opt/gitlab/bin/gitlab-rake gitlab:backup:create
0 2 * * 7 /opt/gitlab/bin/gitlab-rake gitlab:backup:create

点击并拖拽以移动

如果有不懂crontab的规则的可以去crontab在线工具查看

配置完成之后重制crontab

1
systemctl restart crond

点击并拖拽以移动

然后设置自动清理,不然很快硬盘就满了,直接编辑gitlab.rb文件

1
vim /etc/gitlab/gitlab.rb

点击并拖拽以移动

然后填写以下内容,我这里是设置备份保留7天(7360024=604800)

1
gitlab_rails['backup_keep_time'] = 604800

点击并拖拽以移动

最后重新加载配置文件,会等一小会儿

1
gitlab-ctl reconfigure

点击并拖拽以移动

7、还原备份:由于我也没还原过,这里引用大佬还原的过程:GitLab - GitLab的备份与还原 - Anliven - 博客园

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
[root@test102 ~]# cat /etc/gitlab/gitlab.rb |grep "backup_path" |grep -Ev "^$"  # 确认备份目录
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
[root@test102 ~]#
[root@test102 ~]# ll /var/opt/gitlab/backups/ # 确认备份文件
total 172
-rw-r--r-- 1 git git 174080 Nov 27 16:12 1574842330_2019_11_27_12.5.0_gitlab_backup.tar
[root@test102 ~]#
[root@test102 ~]# gitlab-rake gitlab:backup:restore BACKUP=1574842330_2019_11_27_12.5.0 # 还原
Unpacking backup ... done
Before restoring the database, we will remove all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.

Do you want to continue (yes/no)? yes
Removing all tables. Press `Ctrl-C` within 5 seconds to abort
2019-11-27 16:40:03 +0800 -- Cleaning the database ...
2019-11-27 16:40:05 +0800 -- done
2019-11-27 16:40:05 +0800 -- Restoring database ...
......
......
......
[DONE]
2019-11-27 16:40:19 +0800 -- done
2019-11-27 16:40:19 +0800 -- Restoring repositories ...
2019-11-27 16:40:19 +0800 -- done
2019-11-27 16:40:19 +0800 -- Restoring uploads ...
2019-11-27 16:40:19 +0800 -- done
2019-11-27 16:40:19 +0800 -- Restoring builds ...
2019-11-27 16:40:19 +0800 -- done
2019-11-27 16:40:19 +0800 -- Restoring artifacts ...
2019-11-27 16:40:19 +0800 -- done
2019-11-27 16:40:19 +0800 -- Restoring pages ...
2019-11-27 16:40:19 +0800 -- done
2019-11-27 16:40:19 +0800 -- Restoring lfs objects ...
2019-11-27 16:40:19 +0800 -- done
This task will now rebuild the authorized_keys file.
You will lose any data stored in the authorized_keys file.
Do you want to continue (yes/no)? yes

Deleting tmp directories ... done
done
done
done
done
done
done
done
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need to restore these files manually.
Restore task is done.
[root@test102 ~]#
[root@test102 ~]# gitlab-ctl restart # 重启服务
ok: run: alertmanager: (pid 26150) 1s
ok: run: gitaly: (pid 26163) 0s
ok: run: gitlab-exporter: (pid 26182) 1s
ok: run: gitlab-workhorse: (pid 26184) 0s
ok: run: grafana: (pid 26204) 1s
ok: run: logrotate: (pid 26216) 0s
ok: run: nginx: (pid 26223) 1s
ok: run: node-exporter: (pid 26229) 0s
ok: run: postgres-exporter: (pid 26235) 0s
ok: run: postgresql: (pid 26321) 1s
ok: run: prometheus: (pid 26330) 0s
ok: run: redis: (pid 26341) 1s
ok: run: redis-exporter: (pid 26345) 0s
ok: run: sidekiq: (pid 26353) 0s
ok: run: unicorn: (pid 26364) 0s
[root@test102 ~]#
[root@test102 ~]# gitlab-rake gitlab:check SANITZE=true # 检查GitLab所有组件是否运行正常
Checking GitLab subtasks ...

Checking GitLab Shell ...

GitLab Shell: ... GitLab Shell version >= 10.2.0 ? ... OK (10.2.0)
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Internal API available: OK
Redis available via internal API: OK
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Gitaly ...

Gitaly: ... default ... OK

Checking Gitaly ... Finished

Checking Sidekiq ...

Sidekiq: ... Running? ... yes
Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking Incoming Email ...

Incoming Email: ... Reply by email is disabled in config/gitlab.yml

Checking Incoming Email ... Finished

Checking LDAP ...

LDAP: ... LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab App ...

Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... yes
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
Projects have namespace: ... can't check, you have no projects
Redis version >= 2.8.0? ... yes
Ruby version >= 2.5.3 ? ... yes (2.6.3)
Git version >= 2.22.0 ? ... yes (2.22.0)
Git user has default SSH configuration? ... yes
Active users: ... 3
Is authorized keys file accessible? ... yes

Checking GitLab App ... Finished


Checking GitLab subtasks ... Finished

[root@test102 ~]#

点击并拖拽以移动

8、升级gitLab:Gitlab 跨版本升级 - _fn - 博客园

1
2
3
4
5
6
7
8
9
10
11
12
# 创建备份
gitlab-rake gitlab:backup:create
# 停止 gitlab 各项服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-ctl stop nginx
# 安装指定版本 gitlab
rpm -Uvh gitlab-ce-12.0.12-ce.0.el7.x86_64.rpm
# 刷新配置
gitlab-ctl reconfigure
# 重启 gitlab
gitlab-ctl restart

点击并拖拽以移动

9、开启gitLab大文件存储空间(大型文件单独加密存储到指定位置)

需要找到gitLab本地配置路径的gitlab.rb文件

img点击并拖拽以移动

编辑Git LFC的代码,将框框中的6行代码取消注释

img点击并拖拽以移动

退出并保存之后需要刷新配置、重启gitlab

1
2
3
4
# 刷新配置
gitlab-ctl reconfigure
# 重启 gitlab
gitlab-ctl restart

点击并拖拽以移动

重启之后即可,之后传输的大文件就默认加密保存在 /var/opt/gitlab/gitlab-rails/shared/lfs-objects 中


Linux的阿里云等外网服务器配置gitLab公司git仓库
https://tdsgpo.top/2022/04/02/Linux的阿里云等外网服务器配置gitLab公司git仓库/
作者
DDS
发布于
2022年4月2日
许可协议