0%

GitLab代码托管

GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。

官网:https://about.gitlab.com/stages-devops-lifecycle/


安装

配置Yum源
1
2
3
4
5
6
vim /etc/yum.repos.d/gitlab_gitlab-ce.repo
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
安装
1
2
yum install -y postfix
yum install gitlab-ce -y
配置

配置文件:/etc/gitlab/gitlab.rb (建议每次修改前备份此文件)

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
	external_url 'https://git.visualchina.com'    # 域名配置
gitlab_rails['time_zone'] = 'Asia/Shanghai' # 时区

nginx['redirect_http_to_https'] = true # SSL证书
nginx['ssl_certificate'] = "/data/vcg/ssl/visualchina.pem"
nginx['ssl_certificate_key'] = "/data/vcg/ssl/visualchina.key"

gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS' # remember to close this block with 'EOS' below
main: # 'main' is the GitLab 'provider ID' of this LDAP server
label: 'LDAP'
host: '172.16.239.3'
port: 389
uid: 'cn'
method: 'plain' # "tls" or "ssl" or "plain"
bind_dn: 'cn=root,dc=vcg,dc=com'
password: 'vcg@2018'
active_directory: true
allow_username_or_email_login: false
block_auto_created_users: false
base: 'ou=People,dc=vcg,dc=com'
user_filter: ''
attributes:
username: ['cn']
email: ['mail']
name: 'cn'
first_name: 'givenName'
last_name: 'sn'
EOS
配置完成后进行配置更新
1
gitlab-ctl reconfigure
检查是否配置成功
1
gitlab-rake gitlab:ldap:check(列出前100个用户)
重启gitlab服务
1
gitlab-ctl restart
访问

访问ip:80端口 配置root密码,至此部署完成。

升级

升级规范和建议

https://docs.gitlab.com/ee/policy/maintenance.html#upgrade-recommendations

首先升级到主要版本中的最新可用次要版本

例如:8.13.4 升级到 11.3.4 ,升级路径为 8.13.4 -> 8.17.7 -> 9.5.10 -> 10.8.7 -> 11.3.4

​ 即:8.17.7是版本8中的最后一个版本, 9.5.10是版本9中的最后一个版本, 10.8.7是版本10中的最后一个版本

升级操作

本次升级版本为 10.7.0 ,升级到最新版本 11.9.8 ,注:2019年04月16日

1、下载10.8.7版本的rpm包
1
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.8.7-ce.0.el7.x86_64.rpm
2、安装升级到10.8.7版本
1
rpm -Uvh gitlab-ce-10.8.7-ce.0.el7.x86_64.rpm
3、再升级到11.9.8版本
1
yum install gitlab-ce.x86_64

迁移

备份源GitLab数据
1
2
3
4
5
gitlab-rake gitlab:backup:create RAILS_ENV=production

# Creating backup archive: 1555983152_2019_04_23_11.9.8_gitlab_backup.tar ...

# 数据保存在 /var/opt/gitlab/backups,自动生成文件名,比如本次的 1555983152_2019_04_23_11.9.8_gitlab_backup.tar
SCP迁移数据
1
2
#按需替换目标地址
scp /var/opt/gitlab/backups/1555983152_2019_04_23_11.9.8_gitlab_backup.tar root@1.1.1.1:/root/var/opt/gitlab/backups
安装GitLab

请参考 安装 章节

恢复数据
1
2
gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=1555983152_2019_04_23_11.9.8
# BACKUP的时间点必须与原服务器备份后的文件名一致

维护

定期备份
1
2
3
4
crontab -l

0 14 * * * /usr/bin/gitlab-rake gitlab:backup:create
0 15 * * * find /var/opt/gitlab/backups/* -type f -mtime +3 -exec rm {} \;
gitlab-ctl命令
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
[root@iZ2ze4cng635a2k047qus5Z ~]# gitlab-ctl --help
omnibus-ctl: command (subcommand)
check-config
Check if there are any configuration in gitlab.rb that is removed in specified version
deploy-page
Put up the deploy page
diff-config
Compare the user configuration with package available configuration
prometheus-upgrade
Upgrade the Prometheus data to the latest supported version
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-password-md5
Generate MD5 Hash of user password in PostgreSQL format
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
set-replication-password
Set database replication password
Let's Encrypt Commands:
renew-le-certs
Renew the existing Let's Encrypt certificates