温馨提示×

CentOS如何升级GitLab

小樊
44
2026-07-08 08:50:15
栏目: 智能运维

CentOS 上升级 GitLab 通常有两种常见场景:Omnibus 安装方式(官方推荐)Docker 安装方式。下面以 最常见、最稳妥的 Omnibus 方式 为主进行说明,并补充 Docker 场景。


一、升级前必做(非常重要)

1️⃣ 查看当前 GitLab 版本

gitlab-rake gitlab:env:info
# 或
cat /opt/gitlab/version-manifest.txt

2️⃣ 备份 GitLab(强烈建议)

gitlab-backup create

备份文件默认在:

/var/opt/gitlab/backups/

⚠️ 如果是生产环境,一定要先快照或整机备份


二、Omnibus 方式升级 GitLab(CentOS 7 / 8)

✅ 推荐升级路径(避免跨版本失败)

GitLab 不支持跨多个大版本直接升级,例如:

12.x → 16.x ❌
12.x → 13.x → 14.x → 15.x → 16.x ✅

1️⃣ 更新 GitLab YUM 源

vi /etc/yum.repos.d/gitlab_gitlab-ee.repo

或重新安装仓库(推荐):

curl -fsSL https://packages.gitlab.com/gpg.key | gpg --dearmor > /etc/pki/rpm-gpg/RPM-GPG-KEY-gitlab

重新安装仓库(以 GitLab CE 为例):

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash

2️⃣ 查看可用版本(可选)

yum --showduplicates list gitlab-ce

3️⃣ 升级 GitLab(逐步升级)

升级到指定版本(推荐)

yum install gitlab-ce-14.10.5-ce.0.el7

或直接升级到最新版

yum update gitlab-ce

⚠️ 大版本升级建议 一个版本一个版本升


4️⃣ 重新配置并重启

gitlab-ctl reconfigure
gitlab-ctl restart

5️⃣ 检查升级结果

gitlab-rake gitlab:check

三、Docker 方式升级 GitLab

1️⃣ 停止并删除旧容器

docker stop gitlab
docker rm gitlab

2️⃣ 拉取新版本镜像

docker pull gitlab/gitlab-ce:latest

3️⃣ 使用相同卷重新启动

docker run -d \
  --name gitlab \
  -p 443:443 -p 80:80 -p 22:22 \
  -v gitlab-config:/etc/gitlab \
  -v gitlab-logs:/var/log/gitlab \
  -v gitlab-data:/var/opt/gitlab \
  gitlab/gitlab-ce:latest

✅ 数据不会丢失(只要 volume 不变)


四、常见问题

❓ 升级后 502 / 500 错误

gitlab-ctl status
gitlab-ctl tail

常见原因:

  • 内存不足(GitLab 建议 ≥ 4GB)
  • gitlab-ctl reconfigure 未执行

❓ 升级失败回滚

yum downgrade gitlab-ce-旧版本

五、升级建议总结

✅ 生产环境推荐流程:

备份 → 查版本 → 按大版本逐步升级 → reconfigure → 验证

✅ 推荐升级顺序示例:

13.12 → 14.0 → 14.10 → 15.0 → 15.11 → 16.x

如果你愿意,可以告诉我:

  • ✅ CentOS 版本(7 / 8 / Stream)
  • ✅ GitLab 当前版本
  • ✅ GitLab CE 还是 EE
  • ✅ 是否生产环境

我可以给你 精确的升级命令和版本路径

0