百度360必应搜狗淘宝本站头条
当前位置:网站首页 > IT知识 > 正文

gitlab-ce 版本升级及问题处理

liuian 2025-01-16 20:09 29 浏览


背景:

当前版本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年。

升级的风险

  1. 仓库安全!
  2. 其他依赖问题

如何升级

  1. 仓库镜像备份
  2. 依据官方提供方案依次做升级

本文档的目的是验证升级的可行性,仓库为镜像备份恢复后进行操作,对原代码仓库无影响。

开始升级

官方升级文档: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

相关推荐

打开新世界,教你用RooCode+Copliot+Mcp打造一个自己的Manus

本文耗时两天打造,想要一遍走通需要花点时间,建议找个专注的时间开搞!这不仅是个免费使用claude3.5的方案,也是一个超级智能体方案,绝对值得一试!最近Manus真是赚足了眼球,然而我还是没有邀请码...

Git仓库(git仓库有哪些)

#Git仓库使用方法流程详解##一、环境搭建与基础配置###1.1安装与初始化-**安装Git**:官网下载安装包,默认配置安装-**配置全局信息**:```bashgitconfig...

idea版的cursor:Windsurf Wave 7(ideawalk)

在企业环境中,VisualStudioCode和JetBrains系列是最常用的开发工具,覆盖了全球绝大多数开发者。这两类IDE各有优势,但JetBrains系列凭借其针对特定语言和企业场景的深度...

Ai 编辑器 Cursor 零基础教程:推箱子小游戏实战演练

最近Ai火的同时,Ai编辑器Cursor同样火了一把。今天我们就白漂一下Cursor,使用免费版本搞一个零基础教程,并实战演练一个“网页版的推箱子小游戏”。通过这篇文章,让你真正了解cursor是什么...

ChatGPT深度集成于苹果Mac软件 编码能力得到提升

【CNMO科技消息】近日,OpenAI发布了针对MacOS的桌面应用程序,并宣布了一系列与各类应用程序的互操作性功能,标志着ChatGPT正在从聊天机器人向AI智能体工具进化。此次发布的MacOS桌面...

日常开发中常用的git操作命令和使用技巧

日常开发中常用的git操作命令,从配置、初始化本地仓库到提交代码的常用git操作命令使用git前的配置刚使用git,先要在电脑上安装好git,接着我们需要配置一下帐户信息:用户名和邮箱。#设置用户名...

Trae IDE 如何与 GitHub 无缝对接?

TraeIDE内置了GitHub集成功能,让开发者可以直接在IDE里管理代码仓库和版本控制。1.直接从GitHub克隆项目如果你想把GitHub上的代码拉到本地,Trae提供了...

China&#39;s diplomacy to further provide strong support for country&#39;s modernization: FM

BEIJING,March7(Xinhua)--ChineseForeignMinisterWangYisaidFridaythatChina'sdiplomacywil...

三十分钟入门基础Go(Java小子版)(java入门级教程)

前言Go语言定义Go(又称Golang)是Google的RobertGriesemer,RobPike及KenThompson开发的一种静态、强类型、编译型语言。Go语言语法与...

China will definitely take countermeasures in response to arbitrary pressure: FM

BEIJING,March7(Xinhua)--Chinawilldefinitelytakecountermeasuresinresponsetoarbitrarypre...

Go操作etcd(go操作docker实现沙箱)

Go语言操作etcd,这里推荐官方包etcd/clientv3。文档:https://pkg.go.dev/go.etcd.io/etcd/clientv3etcdv3使用gRPC进行远程过程调...

腾讯 Go 性能优化实战(腾讯游戏优化软件)

作者:trumanyan,腾讯CSIG后台开发工程师项目背景网关服务作为统一接入服务,是大部分服务的统一入口。为了避免成功瓶颈,需要对其进行尽可能地优化。因此,特别总结一下golang后台服务...

golang 之JWT实现(golang gin jwt)

什么是JSONWebToken?JSONWebToken(JWT)是一个开放标准(RFC7519),它定义了一种紧凑且自包含的方式,用于在各方之间以JSON方式安全地传输信息。由于此信息是经...

一文看懂 session 和 cookie(session cookie的区别)

-----------cookie大家应该都熟悉,比如说登录某些网站一段时间后,就要求你重新登录;再比如有的同学很喜欢玩爬虫技术,有时候网站就是可以拦截住你的爬虫,这些都和cookie有关。如果...

有望取代 java?GO 语言项目了解一下

GO语言在编程界一直让人又爱又恨,有人说“GO将统治下一个十年”,“几乎所有新的、有趣的东西都是用Go写的”;也有人说它过于死板,使用感太差。国外有Google、AWS、Cloudflar...