背景:
当前版本10.5.6存在较多的安全隐患,且官方已经不在维护此版本。当前版本已经是16.6
升级必要性
- 安全漏洞和数据泄露
- 功能限制和缺失: 新版本的GitLab通常会引入新功能和增强功能;
- 缺少错误修复和性能改进: GitLab的升级通常包含对已知错误的修复和对性能的改进;
- 兼容性问题: 随着时间的推移,操作系统、数据库
- 缺乏社区支持和文档更新: GitLab的社区不断发展和演变,提新的文档不适用于旧版本。
安全漏洞
存在已经披露的安全漏洞。
GitLab的代码执行漏洞(CVE-2023-2478):
受影响的版本范围是:
- 15.4 <= GitLab CE/EE < 15.9.7
- 15.10 <= GitLab CE/EE < 15.10.6
- 15.11 <= GitLab CE/EE < 15.11.2
通过Nessux扫描出来的已经公开的安全漏洞
目前最新的版本16系列就是没影响的。所以,对于大多数用户,这个漏洞给出的修复,也是推荐升级GitLab版本。当前我们使用的版本为10.5.6,是5年前2018年。
升级的风险
- 仓库安全!
- 其他依赖问题
如何升级
- 仓库镜像备份
- 依据官方提供方案依次做升级
本文档的目的是验证升级的可行性,仓库为镜像备份恢复后进行操作,对原代码仓库无影响。
开始升级
官方升级文档:https://docs.gitlab.com/ee/update/index.html#upgrade-paths
升级路径工具:https://gitlab-com.gitlab.io/support/toolbox/upgrade-path
实际使用版本是10.5.6,最新版本16.6 版本跨度大,需要逐个版本的升级,无法直接进行升级。
可以通过官方提供的升级路径工具进行确认升级的版本路径。在官方提供工具中没有实际在用的10.5.6版本,选择最接近的10.5.8,然后升级到当前最新版本16.6.0。由于中间需要升级的大版本和小版本太多,耗费时间较长,可通过分批次升级方式进行。
操作步骤
gitlab升级路径规划:
10.8.7 => 11.11.8 => 12.0.12 => 12.1.17 => 12.10.14 => 13.0.14 => 13.1.11 => 13.8.8 => 13.12.15 => 14.0.12 => 14.3.6 => 14.9.5 => 14.10.5 => 15.0.5 => 15.4.6 => 15.11.13 => 16.1.5 => 16.3.6 => 16.6.0
升级操作:
chmod 0755 /var/opt/gitlab/postgresql
systemctl restart gitlab-runsvdir #
yum install gitlab-ce-10.8.7 -y
yum install gitlab-ce-11.11.8 -y
yum install gitlab-ce-12.0.12 -y
yum install gitlab-ce-12.1.17 -y
yum install gitlab-ce-12.10.14 -y
yum install gitlab-ce-13.0.14 -y
yum install gitlab-ce-13.1.11 -y
yum install gitlab-ce-13.8.8 -y
yum install gitlab-ce-13.12.15 -y
yum install gitlab-ce-14.0.12 -y
yum install gitlab-ce-14.3.6 -y
yum install gitlab-ce-14.9.5 -y
yum install gitlab-ce-14.10.5 -y
yum install gitlab-ce-15.0.5 -y
yum install gitlab-ce-15.4.6 -y
yum install gitlab-ce-15.11.13 -y
yum install gitlab-ce-16.1.5 -y
yum install gitlab-ce-16.3.6 -y
yum install gitlab-ce-16.6.0 -y
gitlab-ctl reconfigure
gitlab-ctl restart
PostgreSQL 升级规划
- GitLab 版本迭代过程中,其 PostgreSQL 的要求版本也在不断更新。出于谨慎性考虑,在 GitLab 升级过程中手动升级 PostgreSQL 。
GitLab 版本 | PostgreSQL 版本 |
12.0.12 | 升级至 PostgreSQL 10 |
12.10.14 | 升级至 PostgreSQL 11.7(需要手动升级) |
13.8.8 | 升级至 PostgreSQL 12.6(自动升级) |
15.4.6 | 升级至 PostgreSQL 13(需要手动升级) |
查看命令
#查看所有日志
gitlab-ctl tail
查看当前版本:
rpm -qa gitlab-ce
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
cat /var/opt/gitlab/postgresql/data/PG_VERSION
/opt/gitlab/embedded/bin/pg_ctl --version
/opt/gitlab/embedded/bin/psql --version
FAQ
1.备份目录的权限问题
[root@bogon ~]# yum install gitlab-ce-10.8.7
gitlab preinstall:
gitlab preinstall: This node does not appear to be running a database
gitlab preinstall: Skipping version check, if you think this is an error exit now
gitlab preinstall:
gitlab preinstall: Automatically backing up only the GitLab SQL database (excluding everything else!)
Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... pg_dump: [archiver (db)] connection to database "gitlabhq_production" failed: 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"?
Backup failed
解决方法:
先执行
chmod 0755 /var/opt/gitlab/postgresql
systemctl restart gitlab-runsvdir
然后在进行升级
2.登录Deploy in progress 错误
升级到gitlab-ce-12.1.17版本后登录提示 Deploy in progress
Deploy in progress
Please try again in a few minutes.
解决方案:gitlab-ctl deploy-page down
[root@bogon ~]# gitlab-ctl deploy-page down
rm -f /opt/gitlab/embedded/service/gitlab-rails/public/index.html
3.PostgreSQL 版本低错误
gitlab-ce-12.10.1更新到gitlab-c-13.0.14 版本时候失败,错误信息如下
gitlab preinstall: Your version of PostgreSQL is no longer supported. Please upgrade your PostgreSQL version to 11.
gitlab preinstall: Check https://docs.gitlab.com/omnibus/settings/database.html#upgrade-packaged-postgresql-server for details.
gitlab preinstall:
gitlab preinstall: Upgrade failed. Retry the upgrade after upgrading your PostgreSQL version.
error: %pre(gitlab-ce-13.0.14-ce.0.el7.x86_64) scriptlet failed, exit status 1
Error in PREIN scriptlet in rpm package gitlab-ce-13.0.14-ce.0.el7.x86_64
Verifying : gitlab-ce-13.0.14-ce.0.el7.x86_64 1/2
gitlab-ce-12.10.14-ce.0.el7.x86_64 was supposed to be removed but is not!
错误原因:要求PostgreSQL版本进行升级,
PostgreSQL升级操作
PostgreSQL升级命令: gitlab-ctl pg-upgrade -V 11
生成数据库统计信息:
sudo gitlab-psql -c "SELECT relname, last_analyze, last_autoanalyze FROM pg_stat_user_tables WHERE last_analyze IS NULL AND last_autoanalyze IS NULL;"
执行以上sql,如果有任何输出,则手动运行:
sudo gitlab-psql -c 'SET statement_timeout = 0; ANALYZE VERBOSE;'
查看版本命令:/opt/gitlab/embedded/bin/postgres --version
参考官方文档:
https://docs.gitlab.com/omnibus/settings/database.html#
upgrade-packaged-postgresql-server
解决方案
[root@bogon postgresql]# cd /var/opt/gitlab/postgresql/
[root@bogon postgresql]# mv data.11/ data.11-bak
[root@bogon postgresql]# gitlab-ctl pg-upgrade -V 11
Checking for an omnibus managed postgresql: OK
Checking if postgresql['version'] is set: OK
Checking if we already upgraded: NOT OK
Checking for a newer version of PostgreSQL to install
Upgrading PostgreSQL to 11.7
Checking if PostgreSQL bin files are symlinked to the expected location: OK
Waiting 30 seconds to ensure tasks complete before PostgreSQL upgrade.
See https://docs.gitlab.com/omnibus/settings/database.html#upgrade-packaged-postgresql-server for details
If you do not want to upgrade the PostgreSQL server at this time, enter Ctrl-C and see the documentation for details
Please hit Ctrl-C now if you want to cancel the operation.
Toggling deploy page:cp /opt/gitlab/embedded/service/gitlab-rails/public/deploy.html /opt/gitlab/embedded/service/gitlab-rails/public/index.html
Toggling deploy page: OK
Toggling services:ok: down: alertmanager: 0s, normally up
ok: down: gitaly: 1s, normally up
ok: down: gitlab-exporter: 0s, normally up
ok: down: grafana: 1s, normally up
ok: down: logrotate: 0s, normally up
ok: down: node-exporter: 1s, normally up
ok: down: postgres-exporter: 0s, normally up
ok: down: prometheus: 0s, normally up
ok: down: redis-exporter: 1s, normally up
ok: down: sidekiq: 1s, normally up
Toggling services: OK
Running stop on postgresql:ok: down: postgresql: 0s, normally up
Running stop on postgresql: OK
Symlink correct version of binaries: OK
Creating temporary data directory: OK
Initializing the new database: OK
……
==== Upgrade has completed ====
Please verify everything is working and run the following if so
sudo rm -rf /var/opt/gitlab/postgresql/data.10
sudo rm -f /var/opt/gitlab/postgresql-version.old
[root@bogon postgresql]# /opt/gitlab/embedded/bin/psql --version
psql (PostgreSQL) 11.7
4.gitlab 14 版本起,全面启用哈希存储,不在支持传统存储
升级gitlab-ce-13.8.8版本后 gitlab-ctl reconfigure 报错误
Running handlers:
There was an error running gitlab-ctl reconfigure:
sidekiq_service[sidekiq] (gitlab::sidekiq-cluster line 20) had an error: Mixlib::ShellOut::ShellCommandFailed: runit_service[sidekiq] (/opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/resources/sidekiq_service.rb line 50) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of /opt/gitlab/embedded/bin/sv restart /opt/gitlab/service/sidekiq ----
STDOUT: timeout: run: /opt/gitlab/service/sidekiq: (pid 11365) 117s, got TERM
STDERR:
---- End output of /opt/gitlab/embedded/bin/sv restart /opt/gitlab/service/sidekiq ----
Ran /opt/gitlab/embedded/bin/sv restart /opt/gitlab/service/sidekiq returned 1
Running handlers complete
Chef Infra Client failed. 4 resources updated in 01 minutes 26 seconds
解决方案:gitlab-ctl restart
5、存储库中有传统存储
13.12.15 升级14.0.12 报如下错误 原因是gitlab 14 版本起,全面启用哈希存储,不在支持传统存储
gitlab preinstall: Checking for unmigrated data on legacy storage
gitlab preinstall:
gitlab preinstall: Legacy storage is no longer supported. Please migrate your data to hashed storage.
gitlab preinstall: Check https://docs.gitlab.com/ee/administration/raketasks/storage.html#migrate-to-hashed-storage for details.
gitlab preinstall:
gitlab preinstall: If you want to skip this check, run the following command and try again:
gitlab preinstall:
gitlab preinstall: sudo touch /etc/gitlab/skip-unmigrated-data-check
gitlab preinstall:
error: %pre(gitlab-ce-14.0.12-ce.0.el7.x86_64) scriptlet failed, exit status 1
Error in PREIN scriptlet in rpm package gitlab-ce-14.0.12-ce.0.el7.x86_64
gitlab-ce-13.12.15-ce.0.el7.x86_64 was supposed to be removed but is not!
Verifying : gitlab-ce-13.12.15-ce.0.el7.x86_64 1/2
Verifying : gitlab-ce-14.0.12-ce.0.el7.x86_64 2/2
Failed:
gitlab-ce.x86_64 0:13.12.15-ce.0.el7 gitlab-ce.x86_64 0:14.0.12-ce.0.el7
Complete!
解决方案
gitlab-rake gitlab:storage:migrate_to_hashed
# 执行成功后,再次执行,会提示如下内容:
#There are no projects requiring storage migration. Nothing to do!
# 全部迁移成功,以下命令查看所列出的项目总数与页面的理应一致
gitlab-rake gitlab:storage:hashed_projects
# 查看,全部迁移成功以下两条命令应该为 0
gitlab-rake gitlab:storage:legacy_projects
gitlab-rake gitlab:storage:legacy_attachments
# 列出传统存储的项目以及附件
gitlab-rake gitlab:storage:list_legacy_projects
gitlab-rake gitlab:storage:list_legacy_attachments
gitlab-rake
gitlab:storage:migrate_to_hashed 执行后每次迁移时都提示成功,多次执行都返回如下内容:
Enqueuing migration of 309 projects in batches of 200.. Done!
原因:项目read-only 为true需要将所有项目批量修改为false
解决方案:
[root@bogon tmp]# gitlab-rails console
--------------------------------------------------------------------------------
Ruby: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
GitLab: 13.12.15 (6614e1562c6) FOSS
GitLab Shell: 13.18.1
PostgreSQL: 12.6
--------------------------------------------------------------------------------
Loading production environment (Rails 6.0.3.7)
irb(main):001:0>
irb(main):001:0> Project.all.find_each { |project| project.update!(repository_read_only: false) }
irb(main):001:0> Project.all.find_each { |project| project.update!(repository_read_only: true) }
执行迁移命令
gitlab-rake gitlab:storage:hashed_projects