Gitlab 跨版本升级记录
Gitlab 跨版本升级记录
需求
- 由于公司需要使用Rancher的pipeline,但是在绑定公司Gitlab的时候报错,后查看是由于Gitlab 的版本太低导致,所以需要升级Gitlab,并且原Gitlab服务器配置较低,正好升级下配置。
- 目前Gitlab中rom组实在是太大了,Git备份总共198G,Rom组占了170G,所以打算将rom组剥离出来,给rom组一个单独的gitlab,其它组共用一个
环境说明
原Gitlab : 8.10.2 –> 新Gitlab : 11.x
操作系统:Centos7
主机类型: 虚拟机
CPU: 8核
内存:16G
由于升级版本差距较大,直接在原服务器升级风险较大,并且还需要给rom组单独一套gitlab,所以新准备一台服务器重新部署升级,给rom组以外的研发人员使用,原gitlab不作升级给rom组使用。
注意事项
gitlab不能跨多个版本升级,并且不同版本的gitlab导入gitlab-gake的备份数据会报以下错误,所以只能安装与旧服务器同版本的gitlab之后在按顺序升级
1
2
3
4
5
6
7
8gitlab-rake gitlab:backup:restore
Unpacking backup ... done
GitLab version mismatch:
Your current GitLab version (11.6.5) differs from the GitLab version in the backup!
Please switch to the following version and try again:
version: 8.10.2
Hint: git checkout v8.10.2gitlab的gitlab-rake命令不会备份任何的配置文件,需要用户自行配置到少要备份以下文件
1. 安装gitlab:8.10.2
Gitlab rpm包下载地址:https://packages.gitlab.com/gitlab/gitlab-ce?page=116
国内推荐用这个:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
要用到的包提前下载好备用,还有下载完的包一定要检查MD5,血和泪的教训1
2
3
4
5
6我的升级顺序为: 8.10.2 --> 8.17.8 --> 9.5.5 --> 10.8.5 --> 11.7.0
我用到的包:
gitlab-ce-8.17.8-ce.0.el7.x86_64.rpm
gitlab-ce-9.5.5-ce.0.el7.x86_64.rpm
gitlab-ce-10.8.5-ce.0.el7.x86_64.rpm
gitlab-ce-11.7.0-ce.0.el7.x86_64.rpm
安装
1 | rpm -ivh gitlab-ce-8.10.2-ce.0.el7.x86_64.rpm |
参数解释:1
2
3
4
5
6
7
8
9
10
11-i, --install install package(s) 安装包
-U, --upgrade=<packagefile>+ upgrade package(s) 更新包,后面会用到
-h, --hash print hash marks as package installs (good with -v)
## 2. 备份原数据
最好停掉gitlab,防止有人提交代码
```shell
gitlab-ctl stop unicorn
gitlab-ctl stop nginx
备份数据
1 | gitlab-rake gitlab:backup:create |
3. 还原数据
3.1 将gitlab数据备份后,拷贝到新主机的/var/opt/gitlab/backups 目录,此目录为gitlab默认的备份目录
198G备份文件,漫长的等待…
- BACKUP=timestamp_of_backup 如果备份目录有多个备份文件可指定时间戳
- force=yes 不询问authorized_keys文件是否应该重新生成,并设定“yes”表示将删除数据库表,启用“写入authorized_keys文件”设置,并更新LDAP提供程序。
1 | ls /var/opt/gitlab/backups/ |
将原服务器的配置文件拷贝到新主机,并更新配置
需要注意拷贝过来的配置文件中的data目录是否与现在的目录的一致
1 | scp 10.60.0.120:/etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb |
4. 测试
访问git地址验证数据是否正常恢复,然后删除rom组的数据,需要注意虽然在页面删除了数据,但是gitlab可能出于安全考虑并没有将数据从机器上删除,需要手动删除。
1
rm -rf /var/opt/gitlab/git-data/repositories/rom
重新备份一下数据1
2
3
4 gitlab-rake gitlab:backup:create
// 备份完后在查看一下备份文件的大小,美滋滋
du -sh /home/backups/1548406242_gitlab_backup.tar
24G /home/backups/1548406242_gitlab_backup.tar
4. 升级
我们现在使用的是8.10.2版本,从官网看8.x最高版本为8.17.8,版本差距也有点大,所以先拍了个虚拟机快照,然后直接升级。
1 | rpm -Uvh gitlab-ce-8.17.8-ce.0.el7.x86_64.rpm |
测试了一下没啥问题,看来不用怕了,直接走起
1 | rpm -Uvh gitlab-ce-9.5.5-ce.0.el7.x86_64.rpm |
万万没想到最后一步出错了,看意思是gitlab.rb配置文件中的‘git_data_dir’ 被替换成了‘git_data_dirs’
[‘support_email’] 已经在10.2版本中弃用,11.0版本已经移除了,提示的很明显,该删的删,该移除的移除,之后记得要重新更新配置的命令然后在重新升级
1 | gitlab-ctl reconfigure |
Ok 升级完成,测试下访问,推送,拉代码 没问题就万事大吉啦。
FQA
下面的错误是因为postgresql目录权限不对,有两种解决方法,推荐方法2:
- 将目录修改成正确的权限,可查看原服务器对应目录的权限,改成一样的即可
- 可以使用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
32Unpacking backup ...
done
Before restoring the database we recommend removing 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)? Do you want to continue (yes/no)? yes
Removing all tables. Press `Ctrl-C` within 5 seconds to abort
Cleaning the database ...
rake aborted!
PG::ConnectionBad: FATAL: could not open relation mapping file "global/pg_filenode.map": Permission denied
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/opt/gitlab/embedded/service/gem/ruby/2.1.0/gems/activerecord-4.2.7/lib/active_record/connection_handling.rb:87:in `connection'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:27:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/backup.rake:50:in `block (3 levels) in <top (required)>'
Tasks: TOP => gitlab:db:drop_tables
(See full trace by running task with --trace)
这个错误是因为疏忽大意,下包没检查md5,下载的包是有问题的导致安装时出现问题。
1 | rpm -Uvh gitlab-ce-9.5.5-ce.0.el7.x86_64.rpm |
gitlab 11.7 默认开启CI/CD 需要手动关闭:
- 点击Admin area(一个小扳手) -> settings -> CI/CD ->Continuous Integration and Deployment 点击Exand ->将Default to Auto DevOps pipeline for all projects和Enable shared runners for new projects勾去掉,我在这的时候保存时报500的错误,错误日志如下:
1 | Started PATCH "/admin/application_settings" for 127.0.0.1 at 2019-01-29 21:02:10 -0500 |
解决方案如下:1
2
3
4
5
6
7
8
9 sudo gitlab-rails c:
-------------------------------------------------------------------------------------
GitLab: 11.7.0 (1d9280e)
GitLab Shell: 8.4.4
postgresql: 9.6.11
-------------------------------------------------------------------------------------
Loading production environment (Rails 5.0.7.1)
irb(main):001:0> settings = ApplicationSetting.last
irb(main):001:0> settings.update_column(:runners_registration_token_encrypted, nil)
以下问题没有遇到,但是转过来备用吧,忘了出处了。。。
如果升级后出现500的错误有可能是数据库升级异常导致的,可尝试使用以下方法解决1
2 gitlab-rake db:migrate:status // 查看数据库升级状态up 为正常,如果有down的说明有问题
gitlab-rake db:migrate // 数据库关系升级
升级后出现以下错误:Error executing action run on resource ‘ruby_block[directory resource: /var/opt/gitlab/git-data/repositories]’
错误信息: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
32resolving cookbooks for run list: ["gitlab"]
Synchronizing Cookbooks:
- package (0.0.0)
- runit (0.14.2)
- gitlab (0.0.1)
Installing Cookbook Gems:
Compiling Cookbooks...
Recipe: gitlab::default
* directory[/etc/gitlab] action create (up to date)
/sbin/init: Unbekannte Option »--version«
-.mount loaded active mounted /
Converging 284 resources
* directory[/etc/gitlab] action create (up to date)
* directory[Create /var/opt/gitlab] action create (up to date)
* directory[/opt/gitlab/embedded/etc] action create (up to date)
* template[/opt/gitlab/embedded/etc/gitconfig] action create (up to date)
Recipe: gitlab::web-server
* group[gitlab-www] action create (up to date)
* user[gitlab-www] action create (up to date)
Recipe: gitlab::users
* directory[/var/opt/gitlab] action create (up to date)
* group[git] action create (up to date)
* user[git] action create (up to date)
* template[/var/opt/gitlab/.gitconfig] action create (up to date)
Recipe: gitlab::gitlab-shell
* ruby_block[directory resource: /var/opt/gitlab/git-data] action run
================================================================================
Error executing action `run` on resource 'ruby_block[directory resource: /var/opt/gitlab/git-data]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
解决方法:1
chmod 2770 /var/opt/gitlab/git-data/repositories
导入后可能会出现以下报错,可尝试清除缓存
报错如下:1
No repository The repository for this project does not exist. This means you can not push code until you create an empty repository or import existing one.
清除缓存的命令如下:
1 | gitlab-rake cache:clear |
参考文档
本文作者 : WGY
原文链接 : http://geeklive.cn/2019/01/30/gitlab_migrate/undefined/gitlab_migrate/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!