1. 安装准备

centos8环境安装---用的dnf安装器
下载社区版安装包---gitlab官网下载
安装参考---gitlab官方教程

2. 安装依赖环境

#安装依赖
sudo dnf install -y curl policycoreutils openssh-server

#打开HTTP, HTTPS和SSH访问
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld

#安装Postfix,用来发送通知邮件
sudo dnf install postfix
sudo systemctl enable postfix
sudo systemctl start postfix

3. 安装gitlab-ce

在官网下载好安装包后,放到自己习惯放的路径下即可

#找到路径下的文件,在当前目录执行rpm安装命令,一般中间不会出现问题,我之前安装gitlab12.3.5版本有的时候还会出现问题,具体解决办法我写到上个博客系统去了(上个博客系统被我误删了😭 ),所以你们只能去搜一下了
#一般出现gitlab的logo图案就算是安装完毕了
rpm -ivh gitlab-ce-13.9.2-ce.0.el8.x86_64.rpm

4. 配置域名/ip

#编辑gitlab配置文件
vim /etc/gitlab/gitlab.rb
#在里边某行能找到external_url =“***”
#将里边的***修改为自己想要访问的地址即可----ps:记得添加http
#如果http不用80用其他端口访问直接再后边加上其他端口号即可
external_url = "http://192.168.1.5"
external_url = "http://www.***.com"
external_url = "http://www.***.com:9999"
external_url = "http://192.168.1.5:9999"

#如果自己项配置https访问的话,需要自己先去申请ssl证书,我这个版本的gitlab用的是nginx的证书
#需要修改,并且把http修改为https,不用默认的443,用其他端口直接添加即可
#ssl证书路径可随意修改,能读取到文件就好
#有些人配置了强制跳转https,我这里木有配置

external_url = "https://www.***.com"
#external_url = "https://www.***.com:9999"
nginx['ssl_certificate'] = "/etc/gitlab/ssl/***.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/***.key"

#如果需要强制从http转为https把这个打开即可
nginx['enable'] = true
nginx['redirect_http_to_https'] = true
nginx['redirect_http_to_https_port'] = 80

#配置完毕后记得重新配置gitlab
sudo gitlab-ctl reconfigure
#重启gitlab
sudo gitlab-ctl restart 

#一定记得去开放端口号,阿里云,腾讯云等还需要去开白名单

gitlab常用命令

#启动
gitlab-ctl start
#停止
gitlab-ctl stop
#重启
gitlab-ctl restart

#实时查看日志
gitlab-ctl tail
#实时各个模块日志
gitlab-ctl tail redis/postgresql/gitlab-workhorse/logrotate/nginx/sidekiq/unicorn

#Gitlab服务构成
nginx: 静态web服务器
gitlab-shell: 用于处理Git命令和修改authorized keys列表
gitlab-workhorse: 轻量级的反向代理服务器
logrotate:日志文件管理工具
postgresql:数据库
redis:缓存数据库
sidekiq:用于在后台执行队列任务(异步执行)
unicorn:HTTP服务,GitLab Rails应用是托管在这个服务器上面的。
#主要配置文件目录
主配置文件: /etc/gitlab/gitlab.rb
文档根目录: /opt/gitlab
默认存储库位置: /var/opt/gitlab/git-data/repositories
Nginx配置文件: /var/opt/gitlab/nginx/conf/gitlab-http.conf
Postgresql数据目录: /var/opt/gitlab/postgresql/data

扩展

备份设置

vim /etc/gitlab/gitlab.rb

#指定备份后数据存放的路径、权限、时间配置
gitlab_rails['manage_backup_path'] = true                  #536行      开启备份功能
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"    #537行      指定备份的路径
gitlab_rails['backup_archive_permissions'] = 0644          #540行      备份包(tar格式压缩包)的权限
gitlab_rails['backup_keep_time'] = 604800                 #545行      备份的保留时间,单位是秒
创建备份目录并授权:
mkdir /var/opt/gitlab/backups && chown -R git.git /var/opt/gitlab/backups/

配置完毕后
gitlab-ctl reconfigure  # 重载配置,使之生效

手动备份

gitlab-rake gitlab:backup:create  # 备份数据

#不知道之前版本怎么样,我这gitlab13.9.2版本在/opt/gitlab/bin/目录下找到了gitlab-backup我就尝试运行了一下,结果正常生成备份,与上边的命令生成的一样

gitlab-backup

定时备份

使用Crontab任务进行定时备份。

[root@VM-8-13-centos ~]# crontab -l
no crontab for root
[root@VM-8-13-centos ~]# 
[root@VM-8-13-centos ~]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
[root@VM-8-13-centos ~]# 
[root@VM-8-13-centos ~]# crontab -l
# 编辑内容
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
[root@VM-8-13-centos ~]#
#重启crontab 
/bin/systemctl restart crond.service  

还原数据
特别注意:

备份目录和gitlab.rb中定义的备份目录必须一致
GitLab的版本和备份文件中的版本必须一致,否则还原时会报错。

[root@VM-8-13-centos ~]# cat /etc/gitlab/gitlab.rb |grep "backup_path" |grep -Ev "^$"  # 确认备份目录
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
[root@VM-8-13-centos ~]# 
[root@VM-8-13-centos ~]# 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@VM-8-13-centos ~]# 
[root@VM-8-13-centos ~]# 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@VM-8-13-centos ~]# 
[root@VM-8-13-centos ~]# 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@VM-8-13-centos ~]# 
[root@VM-8-13-centos ~]# 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@VM-8-13-centos ~]#