gitlab-ce部署文档

安装部署

  1. 添加使用清华gitlab国内的镜像源地址
1
2
3
4
5
6
7
~]# vim /etc/yum.repos.d/gitlab-ce.repo                  // 添加gitlab-ce清华的yum镜像源
-------------------------------------------
[gitlab-ce]
name = gitlab-ce
baseurl = https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
enable = 1
gpgcheck = 0
  1. 使用yum安装gitlab-ce程序,可指定安装版本
1
2
3
4
5
6
7
~]# yum install -y curl policycoreutils-python openssh-server cronie    // 安装gitlab-ce依赖


~]# yum search --showduplicates gitlab-ce // 搜索并列出gitlab-ce的所有可安装版本


~]# yum install -y gitlab-ce-11.11.8-ce // 这里安装11.11.8这个版本
  1. 修改gitlab-ce的配置文件
1
2
3
4
5
6
7
8
9
10
11
12
~]# vim /etc/gitlab/gitlab.rb
-----------------------------------------------------
external_url 'http://你的http访问ip'
unicorn['port'] = 31231 // 这里使用随机端口,避免主机默认8080端口被占用服务无法启动
nginx['listen_port'] = 80 // 修改默认访问的http端口号

~]# gitlab-ctl reconfigure // 每次修改配置文件重新配置一下服务
// 出现以下信息代表gitlab服务启动成功
Running handlers:
Running handlers complete
Chef Client finished, 260/1122 resources updated in 02 minutes 17 seconds
gitlab Reconfigured!
  1. 使用浏览器访问gitlab
1
2
3
http://你gitlab服务器的ip:nginx[listen的端口号]
http://192.168.1.231 账号:root 密码:你重置的密码
// 注意第一次访问需要设置管理员密码

Gitlab汉化为中文

1.克隆汉化git到本地目录中

1
2
~]# git clone https://gitlab.com/xhang/gitlab.git
~]# cd gitlab

2.查看本地使用的是多少版本的gitlab

1
~]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

3.生成指定版本的汉化包并保存到/opt目录下面

1
~]# git diff v10.0.0 v10.0.0-zh > /opt/10.0.0-zh.diff

4.停掉gitlab服务并导入汉化包

1
2
3
4
~]# gitlab-ctl stop
~]# yum install -y patch
~]# patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < /opt/10.0.0-zh.diff
// 一路回车....

5.使gitlab重新加载配置文件并重启gitlab服务

1
2
~]# gitlab-ctl reconfigure
~]# gitlab-ctl restart

6.使用浏览器重新访问验证汉化是否成功

1
2
// 登陆成功后用户界面英文修改为中文方法
右上头像 --> settings --> preferences --> 下拉找到Language --> 简体中文 --> 刷新页面查看

Gitlab忘记root密码找回

  1. 在root用户下执行,获得用户数据,修改用户密码
1
2
3
4
5
6
7
8
9
10
11
~]# gitlab-rails console production                     // 打开gitlab控制台
Loading production environment (Rails 4.2.5.2)
irb(main):001:0> user = User.where(id: 1).first // 查看id为1的用户名
=> #<User id: 1, email: "admin@example.com", ...
irb(main):002:0> user.password='12345678' // 更改root用户的密码为12345678
=> 12345678
irb(main):003:0> user.password_confirmation='12345678' // 更改root用户的密码为12345678
=> 12345678
irb(main):004:0> user.save! // 保存更改
=> true
irb(main):005:0> quit // 退出

注意:密码没有使用引号,奇怪的是使用单引号或双引号,密码就无效,估计是包含了这个字符,不包含,就没有问题。

  1. 浏览器重新访问,使用12345678密码登陆验证

Gitlab版本升级

(注意:由于升级不能跨越大版本号,因此只能升级到当前大版本号到最高版本,方可升级到下一个大版本号)

依次执行下面指令逐步升级,在每一步安装成功后如果发现界面500,不可访问时,那么执行gitlab-ctl reconfigure指令刷新配置文件。(一定保证数据可以正常访问方可执行下一步升级指令)

1、查看当前安装的版本号

1
2
~]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
11.11.8

2、配置gitlab的yum源

1
2
3
4
5
6
~]# cat /etc/yum.repos.d/gitlab.repo 
[gitlab-ce]
name = gitlab-ce
baseurl = https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
enable = 1
gpgcheck = 0

3、查看当前主版本号的最高版本,然后使用yum安装最高版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
~]# yum search --showduplicates gitlab-ce		// 搜索所有可安装的版本号
gitlab-ce-11.11.8-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.0.0-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.0.1-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.0.2-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.0.3-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.0.4-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.0.6-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.0.8-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.0.9-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.1.0-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.1.1-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.1.2-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.1.3-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.1.4-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.1.6-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.1.8-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.1.9-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.1.11-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.1.12-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.1.13-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.1.14-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)
gitlab-ce-12.2.0-ce.0.el7.x86_64 : GitLab Community Edition (including NGINX, Postgres, Redis)

4、升级gitlab服务

由于升级不能跨越大版本号,因此只能升级到当前大版本号到最高版本,方可升级到下一个大版本号,如我的现在是11.11.8升级至12.2.0,我需要先升级至12.0.0,然后升级至12.0.9,然后升级至12.1.0,然后升级至12.1.14,最后升级至12.2.0

1
~]# yum install -y gitlab-ce-12.0.0

升级遇到的问题

0、10.0版本升级11.0版本跨大版本安装失败

1
2
报错:touch /etc/gitlab/skip-auto-migrations
问题解决:touch /etc/gitlab/skip-auto-migrations

1、10版本升级11版本后加载配置文件报错

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
错误分析:
Running handlers:
There was an error running gitlab-ctl reconfigure:

bash[migrate gitlab-rails database] (gitlab::database_migrations line 51) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of "bash" "/tmp/chef-script20190308-65247-12ck9rp" ----
STDOUT: rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/opt/gitlab/postgresql/.s.PGSQL.5432"?
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:52:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `<main>'
Tasks: TOP => gitlab:db:configure
(See full trace by running task with --trace)
STDERR:
---- End output of "bash" "/tmp/chef-script20190308-65247-12ck9rp" ----
Ran "bash" "/tmp/chef-script20190308-65247-12ck9rp" returned 1

解决办法:
gitlab-ctl stop
chmod 755 /var/opt/gitlab/postgresql/
systemctl restart gitlab-runsvdir
gitlab-ctl reconfigure
gitlab-ctl restart

Gitlab主机迁移

在迁移时,目标服务器的版本和源服务器gitlab版本要一致,若要升级高版本,要么先在源服务器升级后迁移;要么先迁移低版本至目标服务器,然后再进行升级版本

  1. 在目标服务器部署和源服务器版本一致的gitlab –> 此步骤省略……
  2. 在老服务器上将gitlab数据进行备份
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
~]# gitlab-rake gitlab:backup:create
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... skipping
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
Backup task is done.
// 提示gitlab.rb配置文件和gitlab-secrets.json文件不包含在备份中,因此我们需要手动备份
// 备份成功后文件存储在/var/opt/gitlab/backups目录下创建一个名称类似为1502357536_2017_08_10_9.4.3_gitlab_backup.tar的压缩包, 这个压缩包就是Gitlab整个的完整部分, 其中开头的1502357536_2017_08_10_9.4.3是备份创建的日期

// 备份其他文件
~]# cp /etc/gitlab/gitlab.rb /var/opt/gitlab/backups/ // 备份gitlab主配置文件
~]# cp -r var/opt/gitlab/nginx/conf /var/opt/gitlab/backups/ // 备份gitlab的web-nginx配置文件
~]# cp /etc/gitlab/gitlab-secrets.json /var/opt/gitlab/backups/
  1. 复制源服务器备份的数据至目标gitlab服务器上
1
2
3
4
5
6
7
// 前提在目标服务器安装和源服务器版本一致的gitlab
// 复制源服务器数据至本地目标服务器
~]# scp -r 192.168.1.231:/var/opt/gitlab/backups/* /root
~]# scp 192.168.1.231:/var/opt/gitlab/backups/gitlab.rb /etc/gitlab/gitlab.rb
~]# scp 192.168.1.231:/var/opt/gitlab/backups/gitlab-secrets.json /etc/gitlab/gitlab-secrets.json
~]# scp 192.168.1.231:/var/opt/gitlab/backups/conf/* /var/opt/gitlab/nginx/conf/
~]# scp 192.168.1.231:/var/opt/gitlab/backups/*.tar /root/
  1. 还原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
29
30
// 还原gitlab数据
~]# cd /root/
~]# ls
1575361653_2019_12_03_12.0.0_gitlab_backup.tar
~]# gitlab-rake gitlab:backup:restore BACKUP=1575361653_2019_12_03_12.0.0 // 注意不带后缀_gitlab_backup.tar
The backup file 1575361653_2019_12_03_12.0.0_gitlab_backup_gitlab_backup.tar does not exist!
[root@centos11 ~]# gitlab-rake gitlab:backup:restore BACKUP=1575361653_2019_12_03_12.0.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

// 提示下面信息代码恢复完成,提示我们gitlab.rb和gitlab-secrets.json文件需要我们手动进行恢复
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.

~]# gitlab-ctl reconfigure // 重新配置服务
~]# gitlab-ctl restart // 重新启动gitlab服务