Git 之八 - Gitlab 详细使用教程

上篇 - Git 之七 - Centos7 搭建 Gitlab 服务器

Gitlab 常规配置

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
# 编辑Gitlab的配置文件
# vim /etc/gitlab/gitlab.rb

# 配置unicorn的端口(默认8080),注意不要用8082、9090端口,因为自带工具会占用
unicorn['port'] = 9999

# 配置Gitlab的默认备份路径
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"

# 配置邮件发送
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "huangdc@domain.com"
gitlab_rails['smtp_password'] = "smtp password"
gitlab_rails['smtp_authentication']= "plain"
gitlab_rails['smtp_enable_starttls_auto']= true
gitlab_rails['gitlab_email_from']= "huangdc@domain.com"
gitlab_rails['gitlab_email_reply_to']= "noreply@domain.com"

# 配置SSH的端口(默认22),修改之后Gitlab中项目的SSH地址会在前面加上协议头和端口号,例如“ssh://git@192.168.1.198:55725/lisi/test.git”
gitlab_rails['gitlab_shell_ssh_port'] = 55725

# 重新编译Gitlab的配置
# gitlab-ctl reconfigure

# 重启GitLab
# gitlab-ctl restart

Gitlab 定时备份

1
2
3
4
5
6
# 添加定时备份任务,crontab表达式根据自己的需要进行修改,最后wq存盘退出crontab的编辑状态
# crontab -e
0 2 * * * /usr/bin/gitlab-rake gitlab:backup:create CRON=1

# 查看计划任务是否添加成功
# crontab -l

Gitlab 恢复备份

1
2
3
4
5
6
7
8
9
10
11
12
13
# 停止unicorn和sidekiq,保证数据库没有新的连接,不会有新的数据写入
# gitlab-ctl stop unicorn
# gitlab-ctl stop sidekiq

# 进入gitlab的备份目录
# cd /var/opt/gitlab/backups

# 恢复指定的备份文件,1547096290_2019_01_10_11.6.3是备份文件的编号
# gitlab-rake gitlab:backup:restore BACKUP=1547096290_2019_01_10_11.6.3

# 启动unicorn和sidekiq
# gitlab-ctl start unicorn
# gitlab-ctl start sidekiq