实践Gitlab

Gitlab

介绍

gitlab

二进制发行包

安装

官方下载适合操作系统和CPU架构的二进制包,然后安装即可,例如:

redhat
1
2
3
4
5
$ sudo yum install -y curl policycoreutils-python openssh-server cronie
# 打开http和ssh的防火墙
$ sudo lokkit -s http -s ssh
# install
$ sudo rpm -ivh gitlab-ce-10.2.4-ce.0.el6.x86_64.rpm
debian
1
2
3
$ sudo apt-get install -y curl openssh-server ca-certificates
# install
$ sudo dpkg -i gitlab-ce_11.4.4-ce.0_amd64.deb

默认安装到/opt/gitlab目录下,配置文件/etc/gitlab/gitlab.rb,日志/var/log/gitlab/

配置

配置gitlab地址:修改配置文件中的external_url为gitlab的访问地址。

git数据存储地址:默认地址是/var/opt/gitlab/git-data/,可以通过修改参数git_data_dirs来调整,会在其目录下自动新建repositories目录存放git仓库。参考官方说明

1
git_data_dirs({ "default" => { "path" => "/app" } })

启动

redhat
1
2
3
4
# 首次启动需要配置
$ sudo gitlab-ctl reconfigure
# 启动
$ sudo gitlab-ctl start

随系统自启动,可以将gitlab-ctl start追加到/etc/rc.local

debian
1
$ sudo systemctl status gitlab-runsvdir

默认账号:root,密码在首次登录时自行设置

刷新配置

修改配置后,刷新使生效。

1
$ sudo gitlab-ctl reconfigure

命令

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
$ gitlab-ctl help
omnibus-ctl: command (subcommand)
deploy-page
  Put up the deploy page
diff-config
  Compare the user configuration with package available configuration
remove-accounts
  Delete *all* users and groups used by this package
upgrade
  Run migrations after a package upgrade
General Commands:
  cleanse
    Delete *all* gitlab data, and start from scratch.
  help
    Print this help message.
  reconfigure
    Reconfigure the application.
  show-config
    Show the configuration that would be generated by reconfigure.
  uninstall
    Kill all processes and uninstall the process supervisor (data will be preserved).
Service Management Commands:
  graceful-kill
    Attempt a graceful stop, then SIGKILL the entire process group.
  hup
    Send the services a HUP.
  int
    Send the services an INT.
  kill
    Send the services a KILL.
  once
    Start the services if they are down. Do not restart them if they stop.
  restart
    Stop the services if they are running, then start them again.
  service-list
    List all the services (enabled services appear with a *.)
  start
    Start services if they are down, and restart them if they stop.
  status
    Show the status of all the services.
  stop
    Stop the services, and do not restart them.
  tail
    Watch the service logs of all enabled services.
  term
    Send the services a TERM.
  usr1
    Send the services a USR1.
  usr2
    Send the services a USR2.
Container Registry Commands:
  registry-garbage-collect
    Run Container Registry garbage collection.
Database Commands:
  pg-upgrade
    Upgrade the PostgreSQL DB to the latest supported version
  revert-pg-upgrade
    Run this to revert to the previous version of the database

smtp配置

可以参见官方

自建邮箱

1
2
3
4
5
6
7
8
9
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.corp.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "gitlab"
gitlab_rails['smtp_password'] = "***"
gitlab_rails['smtp_domain'] = "corp.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_tls'] = false

腾讯邮箱

1
2
3
4
5
6
7
8
9
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "gitlab@abc.com"
gitlab_rails['smtp_password'] = "******"
gitlab_rails['smtp_domain'] = "abc.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

email配置

1
2
3
4
gitlab_rails['gitlab_email_from'] = 'someone'
gitlab_rails['gitlab_email_display_name'] = '【Gitlab】'
gitlab_rails['gitlab_email_reply_to'] = 'noreply@abc.com'
gitlab_rails['gitlab_email_subject_suffix'] = '[gitlab]'

邮件列表中显示的发件人:gitlab_rails['gitlab_email_display_name']

邮件详情中显示的发件人:

"gitlab_rails['gitlab_email_display_name']" gitlab_rails['gitlab_email_from']

收件人回复邮件时的地址:gitlab_rails['gitlab_email_reply_to'],并不一定是发送人地址

测试验证

1
2
3
$ sudo gitlab-rails console
Loading production environment (Rails 4.2.8)
irb(main):001:0> Notify.test_email('gitlab@abc.com', 'Message Subject', 'Message Body').deliver_now

reply to email配置

参见官方,没有成功。

1
2
3
2017-11-10_03:16:25.42049 192.168.70.244 @ - - [2017-11-10 11:16:25.388247369 +0800 CST] "GET /ITS/config.git/info/refs?service=git-upload-pack HTTP/1.1" 401 26 "" "git/2.13.3" 0.032064
2017-11-10_03:16:30.01927 2017/11/10 11:16:30 error: GET "/ITS/config.git/info/refs?service=git-upload-pack": handleGetInfoRefs: GetInfoRefsHandler: rpc error: code = 14 desc = grpc: the connection is unavailable
2017-11-10_03:16:30.01932 192.168.70.244 @ - - [2017-11-10 11:16:29.875283562 +0800 CST] "GET /ITS/config.git/info/refs?service=git-upload-pack HTTP/1.1" 500 22 "" "git/2.13.3" 0.143987

备份还原

备份
  • 备份内容

db (database)

uploads (attachments)

repositories (Git repositories data)

builds (CI job output logs)

artifacts (CI job artifacts)

lfs (LFS objects)

registry (Container Registry images)

pages (Pages content)

可以通过SKIP参数跳过不需要备份的内容,例如:SKIP=db,uploads

  • 备份位置

backup_path,默认备份到/var/opt/gitlab/backups

timestamp:EPOCH_YYYY_MM_DD_${GitLab version},全名:${timestamp}_gitlab_backup.tar

  • 备份策略

默认基于流读取备份,当数据变化较快是容易出现错误file changed as we read it,这时可以修改为copy模式,STRATEGY=copy

手动备份配置文件:/etc/gitlab/gitlab.rb,/etc/gitlab/gitlab-secrets.json

执行备份命令:

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
$ sudo gitlab-rake gitlab:backup:create
[sudo] password for wanglei: 
Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ...
 * demo/sample-project ... [DONE]
 * demo/sample-project.wiki ...  [SKIPPED]
 * docs/training ... [SKIPPED]
 * docs/training.wiki ...  [SKIPPED]
 * docs/wiki ... [DONE]
 * docs/wiki.wiki ...  [DONE]
 * wanglei/demo ... [DONE]
 * wanglei/demo.wiki ...  [SKIPPED]
 * chenlong/test ... [DONE]
 * chenlong/test.wiki ...  [SKIPPED]
 * chenlong/test2 ... [DONE]
 * chenlong/test2.wiki ...  [SKIPPED]
 * demo/servlet ... [DONE]
 * demo/servlet.wiki ...  [SKIPPED]
 * my-test/cib-epay-demo ... [DONE]
 * my-test/cib-epay-demo.wiki ...  [SKIPPED]
done
Dumping uploads ... 
done
Dumping builds ... 
done
Dumping artifacts ... 
done
Dumping pages ... 
done
Dumping lfs objects ... 
done
Dumping container registry images ... 
[DISABLED]
Creating backup archive: 1508408387_2017_10_19_10.0.4_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
还原

新服务器与备份服务器的gitlab版本必须相同,且新服务器必须执行过sudo gitlab-ctl reconfigure,当前是运行状态。

拷贝备份到backup_path

1
2
3
4
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
# Verify
sudo gitlab-ctl status

执行还原命令:

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
$ sudo gitlab-rake gitlab:backup:restore BACKUP=1513827553_2017_12_21_10.2.4
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
Cleaning the database ... 
done
Restoring database ... 
Restoring PostgreSQL database gitlabhq_production ... SET
...
[DONE]
done
Restoring repositories ...
 * demo/sample-project ... [DONE]
 * docs/training ... [DONE]
 * docs/wiki ... [DONE]
 * docs/wiki.wiki ...  [DONE]
 ...
 * ETS/boss/ops-pg-aml ... [DONE]
Put GitLab hooks in repositories dirs [DONE]
done
Restoring uploads ... 
done
Restoring builds ... 
done
Restoring artifacts ... 
done
Restoring pages ... 
done
Restoring lfs objects ... 
done
# 恢复SSH keys
This will rebuild an authorized_keys file.
You will lose any data stored in authorized_keys file.
Do you want to continue (yes/no)? yes

...............
Deleting tmp directories ... done
done
done
done
done
done
done
done

手动还原配置文件:/etc/gitlab/gitlab.rb,/etc/gitlab/gitlab-secrets.json

1
2
3
4
# 重启
$ sudo gitlab-ctl restart
# 检查
$ sudo gitlab-rake gitlab:check SANITIZE=true

升级

1
2
3
4
5
# Debian/Ubuntu
$ sudo dpkg -i gitlab-ce-XXX.deb

# CentOS/RHEL
$ sudo rpm -Uvh gitlab-ce-XXX.rpm

例如:

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
$ sudo rpm -Uvh gitlab-ce-10.0.1-ce.0.el6.x86_64.rpm
warning: gitlab-ce-10.0.1-ce.0.el6.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing...                ########################################### [100%]
gitlab preinstall: Automatically backing up only the GitLab SQL database (excluding everything else!)
Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ...
[SKIPPED]
Dumping uploads ... 
[SKIPPED]
Dumping builds ... 
[SKIPPED]
Dumping artifacts ... 
[SKIPPED]
Dumping pages ... 
[SKIPPED]
Dumping lfs objects ... 
[SKIPPED]
Dumping container registry images ... 
[DISABLED]
Creating backup archive: 1506410179_2017_09_26_9.5.2_gitlab_backup.tar ... done
Uploading backup archive to remote storage  ... skipped
Deleting tmp directories ... done
done
Deleting old backups ... skipping
   1:gitlab-ce              ########################################### [100%]
Checking PostgreSQL executables:Starting Chef Client, version 12.12.15
resolving cookbooks for run list: ["gitlab::postgresql-bin"]
Synchronizing Cookbooks:
  - gitlab (0.0.1)
  - registry (0.1.0)
  - package (0.1.0)
  - consul (0.0.0)
  - runit (0.14.2)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 1 resources
Recipe: gitlab::postgresql-bin
  * ruby_block[Link postgresql bin files to the correct version] action run (skipped due to only_if)

Running handlers:
Running handlers complete
Chef Client finished, 0/1 resources updated in 07 seconds
Checking PostgreSQL executables: OK
Shutting down all GitLab services except those needed for migrations
ok: down: gitaly: 0s, normally up, want up
ok: down: gitlab-monitor: 0s, normally up
ok: down: gitlab-workhorse: 1s, normally up
ok: down: logrotate: 0s, normally up
ok: down: nginx: 0s, normally up
ok: down: node-exporter: 1s, normally up
ok: down: postgres-exporter: 0s, normally up
ok: down: postgresql: 0s, normally up
ok: down: prometheus: 1s, normally up
ok: down: redis: 0s, normally up
ok: down: redis-exporter: 0s, normally up
ok: down: sidekiq: 1s, normally up
ok: down: unicorn: 0s, normally up
ok: run: postgresql: (pid 4957) 1s
ok: run: redis: (pid 4967) 0s
run: postgresql: (pid 4957) 1s; run: log: (pid 7888) 1111069s
run: redis: (pid 4967) 0s; run: log: (pid 7824) 1111080s
Reconfiguring GitLab to apply migrations
Starting Chef Client, version 12.12.15
resolving cookbooks for run list: ["gitlab"]
Synchronizing Cookbooks:
  - gitlab (0.0.1)
  - package (0.1.0)
  - registry (0.1.0)
  - consul (0.0.0)
  - runit (0.14.2)
Installing Cookbook Gems:
...
Running handlers:
Running handlers complete
Chef Client finished, 20/475 resources updated in 01 minutes 21 seconds
gitlab Reconfigured!
Checking for an omnibus managed postgresql: OK
Checking if we already upgraded: NOT OK
Checking for a newer version of PostgreSQL to install: NOT OK
No new version of PostgreSQL installed, nothing to upgrade to
Ensuring PostgreSQL is updated: OK
Restarting previously running GitLab services
ok: run: gitaly: (pid 5545) 0s
ok: run: gitlab-monitor: (pid 5558) 1s
ok: run: gitlab-workhorse: (pid 5525) 2s
ok: run: logrotate: (pid 5562) 0s
ok: run: nginx: (pid 5572) 1s
ok: run: node-exporter: (pid 5590) 0s
ok: run: postgres-exporter: (pid 5601) 0s
ok: run: postgresql: (pid 4957) 88s
ok: run: prometheus: (pid 5614) 1s
ok: run: redis: (pid 4967) 88s
ok: run: redis-exporter: (pid 5625) 0s
ok: run: sidekiq: (pid 5651) 1s
ok: run: unicorn: (pid 5656) 0s

     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ 

Gitlab

介绍

gitlab

二进制发行包

安装

官方下载适合操作系统和CPU架构的二进制包,然后安装即可,例如:

redhat
1
2
3
4
5
$ sudo yum install -y curl policycoreutils-python openssh-server cronie
# 打开http和ssh的防火墙
$ sudo lokkit -s http -s ssh
# install
$ sudo rpm -ivh gitlab-ce-10.2.4-ce.0.el6.x86_64.rpm
debian
1
2
3
$ sudo apt-get install -y curl openssh-server ca-certificates
# install
$ sudo dpkg -i gitlab-ce_11.4.4-ce.0_amd64.deb

默认安装到/opt/gitlab目录下,配置文件/etc/gitlab/gitlab.rb,日志/var/log/gitlab/

配置

配置gitlab地址:修改配置文件中的external_url为gitlab的访问地址。

git数据存储地址:默认地址是/var/opt/gitlab/git-data/,可以通过修改参数git_data_dirs来调整,会在其目录下自动新建repositories目录存放git仓库。参考官方说明

1
git_data_dirs({ "default" => { "path" => "/app" } })

启动

redhat
1
2
3
4
# 首次启动需要配置
$ sudo gitlab-ctl reconfigure
# 启动
$ sudo gitlab-ctl start

随系统自启动,可以将gitlab-ctl start追加到/etc/rc.local

debian
1
$ sudo systemctl status gitlab-runsvdir

默认账号:root,密码在首次登录时自行设置

刷新配置

修改配置后,刷新使生效。

1
$ sudo gitlab-ctl reconfigure

命令

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
$ gitlab-ctl help
omnibus-ctl: command (subcommand)
deploy-page
  Put up the deploy page
diff-config
  Compare the user configuration with package available configuration
remove-accounts
  Delete *all* users and groups used by this package
upgrade
  Run migrations after a package upgrade
General Commands:
  cleanse
    Delete *all* gitlab data, and start from scratch.
  help
    Print this help message.
  reconfigure
    Reconfigure the application.
  show-config
    Show the configuration that would be generated by reconfigure.
  uninstall
    Kill all processes and uninstall the process supervisor (data will be preserved).
Service Management Commands:
  graceful-kill
    Attempt a graceful stop, then SIGKILL the entire process group.
  hup
    Send the services a HUP.
  int
    Send the services an INT.
  kill
    Send the services a KILL.
  once
    Start the services if they are down. Do not restart them if they stop.
  restart
    Stop the services if they are running, then start them again.
  service-list
    List all the services (enabled services appear with a *.)
  start
    Start services if they are down, and restart them if they stop.
  status
    Show the status of all the services.
  stop
    Stop the services, and do not restart them.
  tail
    Watch the service logs of all enabled services.
  term
    Send the services a TERM.
  usr1
    Send the services a USR1.
  usr2
    Send the services a USR2.
Container Registry Commands:
  registry-garbage-collect
    Run Container Registry garbage collection.
Database Commands:
  pg-upgrade
    Upgrade the PostgreSQL DB to the latest supported version
  revert-pg-upgrade
    Run this to revert to the previous version of the database

smtp配置

可以参见官方

自建邮箱

1
2
3
4
5
6
7
8
9
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.corp.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "gitlab"
gitlab_rails['smtp_password'] = "***"
gitlab_rails['smtp_domain'] = "corp.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_tls'] = false

腾讯邮箱

1
2
3
4
5
6
7
8
9
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "gitlab@abc.com"
gitlab_rails['smtp_password'] = "******"
gitlab_rails['smtp_domain'] = "abc.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

email配置

1
2
3
4
gitlab_rails['gitlab_email_from'] = 'someone'
gitlab_rails['gitlab_email_display_name'] = '【Gitlab】'
gitlab_rails['gitlab_email_reply_to'] = 'noreply@abc.com'
gitlab_rails['gitlab_email_subject_suffix'] = '[gitlab]'

邮件列表中显示的发件人:gitlab_rails['gitlab_email_display_name']

邮件详情中显示的发件人:

"gitlab_rails['gitlab_email_display_name']" gitlab_rails['gitlab_email_from']

收件人回复邮件时的地址:gitlab_rails['gitlab_email_reply_to'],并不一定是发送人地址

测试验证

1
2
3
$ sudo gitlab-rails console
Loading production environment (Rails 4.2.8)
irb(main):001:0> Notify.test_email('gitlab@abc.com', 'Message Subject', 'Message Body').deliver_now

reply to email配置

参见官方,没有成功。

1
2
3
2017-11-10_03:16:25.42049 192.168.70.244 @ - - [2017-11-10 11:16:25.388247369 +0800 CST] "GET /ITS/config.git/info/refs?service=git-upload-pack HTTP/1.1" 401 26 "" "git/2.13.3" 0.032064
2017-11-10_03:16:30.01927 2017/11/10 11:16:30 error: GET "/ITS/config.git/info/refs?service=git-upload-pack": handleGetInfoRefs: GetInfoRefsHandler: rpc error: code = 14 desc = grpc: the connection is unavailable
2017-11-10_03:16:30.01932 192.168.70.244 @ - - [2017-11-10 11:16:29.875283562 +0800 CST] "GET /ITS/config.git/info/refs?service=git-upload-pack HTTP/1.1" 500 22 "" "git/2.13.3" 0.143987

备份还原

备份
  • 备份内容

db (database)

uploads (attachments)

repositories (Git repositories data)

builds (CI job output logs)

artifacts (CI job artifacts)

lfs (LFS objects)

registry (Container Registry images)

pages (Pages content)

可以通过SKIP参数跳过不需要备份的内容,例如:SKIP=db,uploads

  • 备份位置

backup_path,默认备份到/var/opt/gitlab/backups

timestamp:EPOCH_YYYY_MM_DD_${GitLab version},全名:${timestamp}_gitlab_backup.tar

  • 备份策略

默认基于流读取备份,当数据变化较快是容易出现错误file changed as we read it,这时可以修改为copy模式,STRATEGY=copy

手动备份配置文件:/etc/gitlab/gitlab.rb,/etc/gitlab/gitlab-secrets.json

执行备份命令:

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
$ sudo gitlab-rake gitlab:backup:create
[sudo] password for wanglei: 
Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ...
 * demo/sample-project ... [DONE]
 * demo/sample-project.wiki ...  [SKIPPED]
 * docs/training ... [SKIPPED]
 * docs/training.wiki ...  [SKIPPED]
 * docs/wiki ... [DONE]
 * docs/wiki.wiki ...  [DONE]
 * wanglei/demo ... [DONE]
 * wanglei/demo.wiki ...  [SKIPPED]
 * chenlong/test ... [DONE]
 * chenlong/test.wiki ...  [SKIPPED]
 * chenlong/test2 ... [DONE]
 * chenlong/test2.wiki ...  [SKIPPED]
 * demo/servlet ... [DONE]
 * demo/servlet.wiki ...  [SKIPPED]
 * my-test/cib-epay-demo ... [DONE]
 * my-test/cib-epay-demo.wiki ...  [SKIPPED]
done
Dumping uploads ... 
done
Dumping builds ... 
done
Dumping artifacts ... 
done
Dumping pages ... 
done
Dumping lfs objects ... 
done
Dumping container registry images ... 
[DISABLED]
Creating backup archive: 1508408387_2017_10_19_10.0.4_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
还原

新服务器与备份服务器的gitlab版本必须相同,且新服务器必须执行过sudo gitlab-ctl reconfigure,当前是运行状态。

拷贝备份到backup_path

1
2
3
4
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
# Verify
sudo gitlab-ctl status

执行还原命令:

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
$ sudo gitlab-rake gitlab:backup:restore BACKUP=1513827553_2017_12_21_10.2.4
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
Cleaning the database ... 
done
Restoring database ... 
Restoring PostgreSQL database gitlabhq_production ... SET
...
[DONE]
done
Restoring repositories ...
 * demo/sample-project ... [DONE]
 * docs/training ... [DONE]
 * docs/wiki ... [DONE]
 * docs/wiki.wiki ...  [DONE]
 ...
 * ETS/boss/ops-pg-aml ... [DONE]
Put GitLab hooks in repositories dirs [DONE]
done
Restoring uploads ... 
done
Restoring builds ... 
done
Restoring artifacts ... 
done
Restoring pages ... 
done
Restoring lfs objects ... 
done
# 恢复SSH keys
This will rebuild an authorized_keys file.
You will lose any data stored in authorized_keys file.
Do you want to continue (yes/no)? yes

...............
Deleting tmp directories ... done
done
done
done
done
done
done
done

手动还原配置文件:/etc/gitlab/gitlab.rb,/etc/gitlab/gitlab-secrets.json

1
2
3
4
# 重启
$ sudo gitlab-ctl restart
# 检查
$ sudo gitlab-rake gitlab:check SANITIZE=true

升级

1
2
3
4
5
# Debian/Ubuntu
$ sudo dpkg -i gitlab-ce-XXX.deb

# CentOS/RHEL
$ sudo rpm -Uvh gitlab-ce-XXX.rpm

例如:

/ __ \ / /_/ / / /_/ /___/ /_/ / /_/ / \____/_/\__/_____/\__,_/_.___/ Upgrade complete! If your GitLab server is misbehaving try running sudo gitlab-ctl restart before anything else. If you need to roll back to the previous version you can use the database backup made during the upgrade (scroll up for the filename).

包管理器

清华大学开源软件镜像站之Gitlab Community Edition 镜像使用帮助

升级

1
2
3
4
5
6
# Debian/Ubuntu
sudo apt-get update
sudo apt-get install gitlab-ce

# Centos/RHEL
sudo yum install gitlab-ce

Gitlab权限

可见权限

可见权限有三个级别:

  • Private: Project access must be granted explicitly to each user (Member).
  • Internal: The project can be accessed by any logged in user.
  • Public: The project can be accessed without any authentication.

group和project均有,project可见级别不能高于group。

操作权限

操作权限有五个级别:

Guest Reporter Developer Master Owner

group和project均可设置,取两者最高者。

issue

commit时可以关联issue,在commit message里面包含#issueNo即可。

Gitlab CI/CD

gitlab-ci/cd

Gitlab Runner

10.0版本之前叫gitlab-ci-multi-runner,之后重命名为gitlab-runner

Install GitLab Runner

通过二进制发行包安装

下载适合操作系统和CPU平台架构的二进制包,然后安装即可,例如:

1
$ sudo rpm -ivh gitlab-runner-10.0.0-1.x86_64.rpm

默认安装到/opt/gitlab目录下,配置文件/etc/gitlab-runner/config.toml

通过包管理器安装

清华大学开源软件镜像站之Gitlab Runner 镜像使用帮助

Add GitLab’s official repository:

For GitLab Runner 10.0 and newer

1
2
3
4
5
# For Debian/Ubuntu
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash

# For RHEL/CentOS
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash

For versions older than 10.0, please use

1
2
3
4
5
# For Debian/Ubuntu
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | sudo bash

# For RHEL/CentOS
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash

Install gitlab-runner

** For GitLab Runner 10.0 and newer**

1
2
3
4
5
# For Debian/Ubuntu
sudo apt-get install gitlab-runner

# For RHEL/CentOS
sudo yum install gitlab-runner

For versions older than 10.0, please use

1
2
3
4
5
# For Debian/Ubuntu
sudo apt-get install gitlab-ci-multi-runner

# For RHEL/CentOS
sudo yum install gitlab-ci-multi-runner

Register the runner

1
$ sudo gitlab-runner register

命令

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
$ gitlab-runner help
NAME:
   gitlab-runner - a GitLab Runner

USAGE:
   gitlab-runner [global options] command [command options] [arguments...]

VERSION:
   10.0.2 (a9a76a50)

AUTHOR:
   GitLab Inc. <support@gitlab.com>

COMMANDS:
     exec                  execute a build locally
     list                  List all configured runners
     run                   run multi runner service
     register              register a new runner
     install               install service
     uninstall             uninstall service
     start                 start service
     stop                  stop service
     restart               restart service
     status                get status of a service
     run-single            start single runner
     unregister            unregister specific runner
     verify                verify all registered runners
     artifacts-downloader  download and extract build artifacts (internal)
     artifacts-uploader    create and upload build artifacts (internal)
     cache-archiver        create and upload cache artifacts (internal)
     cache-extractor       download and extract cache artifacts (internal)
     help, h               Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --debug                      debug mode [$DEBUG]
   --log-level value, -l value  Log level (options: debug, info, warn, error, fatal, panic)
   --cpuprofile value           write cpu profile to file [$CPU_PROFILE]
   --help, -h                   show help
   --version, -v                print the version