GitLab 伺服器升級指南:從版本 14.9.3 升級

在使用 GitLab 14.9.3 版本的情況下,想要升級到最新版本 16,需要按照以下的升級路徑進行升級。請務必遵循這個順序進行升級,以確保升級的成功性。

升級可以參考 GitLab 升級文件

升級路徑摘要

以下總結目前的升級路徑:

  • GitLab 14: 14.0.12 > 14.3.6 > 14.9.5 > 14.10.5.
  • GitLab 15: 15.0.5 > 15.1.6 > 15.4.6 > 15.11.13.
  • GitLab 16: 16.0.x > 16.1 > 16.2.x > 16.3 > 最新的 16.Y.Z.

直接升級的錯誤情況

如果直接使用 apt 升級最新版本是會失敗的,以下範例是我目前版本 14.9.3 直接使用 apt upgrate 升級後的錯誤

Preparing to unpack .../gitlab-ce_15.0.0-ce.0_amd64.deb ...
gitlab preinstall: It seems you are upgrading from major version 14 to major version 15.
gitlab preinstall: It is required to upgrade to the latest 14.10.x version first before proceeding.
gitlab preinstall: Please follow the upgrade documentation at https://docs.gitlab.com/ee/update/index.html#upgrade-paths
dpkg: error processing archive /var/cache/apt/archives/gitlab-ce_15.0.0-ce.0_amd64.deb (--unpack):

升級步驟

以上面的範例來看要升級到 15 要先升級到 14.10.x 版本號可以到 GitLab packages

查找版本

方法一

以 14.10.4 為範例

https://packages.gitlab.com/gitlab/gitlab-ce/packages/ubuntu/focal/gitlab-ce_14.10.5-ce.0_arm64.deb https://packages.gitlab.com/gitlab/gitlab-ee/packages/ubuntu/focal/gitlab-ee_14.10.4-ee.0_amd64.deb

可以看到 ce 跟 ee 的版本有點不一樣

方法二

sudo apt list --upgradable gitlab-ce -a

由此可以看到目前可以安裝的版本

Listing... Done
gitlab-ce/bionic 14.10.5-ce.0 amd64
gitlab-ce/bionic 14.10.4-ce.0 amd64
gitlab-ce/bionic 14.10.3-ce.0 amd64
gitlab-ce/bionic 14.10.2-ce.0 amd64
gitlab-ce/bionic 14.10.1-ce.0 amd64
gitlab-ce/bionic 14.10.0-ce.0 amd64
gitlab-ce/bionic 14.9.5-ce.0 amd64
gitlab-ce/bionic 14.9.4-ce.0 amd64
gitlab-ce/bionic 14.9.3-ce.0 amd64
gitlab-ce/bionic 14.9.2-ce.0 amd64
gitlab-ce/bionic 14.9.1-ce.0 amd64
gitlab-ce/bionic 14.9.0-ce.0 amd64

升級指令

方法一

找到版號後可以使用以下兩種方法升級

sudo apt upgrade -y gitlab-ce=14.10.4-ce.0

方法二

或是使用

sudo apt install gitlab-ce=14.10.4-ce.0

升級成功

升級成功後會顯示如下

     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/


Upgrade complete! If your GitLab server is misbehaving try running
  sudo gitlab-ctl restart
before anything else.
If you need to roll back to the previous version you can use the database
backup made during the upgrade (scroll up for the filename).

提示重新啟動服務就重新啟動一下

sudo gitlab-ctl restart 
backup sudo gitlab-ctl restart
ok: run: alertmanager: (pid 23788) 0s
ok: run: gitaly: (pid 23799) 0s
ok: run: gitlab-exporter: (pid 23814) 0s
ok: run: gitlab-kas: (pid 23816) 1s
ok: run: gitlab-workhorse: (pid 23828) 0s
ok: run: grafana: (pid 23837) 1s
ok: run: logrotate: (pid 23851) 0s
ok: run: node-exporter: (pid 23857) 0s
ok: run: postgres-exporter: (pid 23865) 1s
ok: run: postgresql: (pid 23874) 0s
ok: run: prometheus: (pid 23876) 1s
ok: run: puma: (pid 23895) 0s
ok: run: redis: (pid 23900) 1s
ok: run: redis-exporter: (pid 23906) 0s
ok: run: registry: (pid 23915) 0s
ok: run: sidekiq: (pid 23926) 0s

後續升級

繼續升級後續版本,如果想要一直升級可以用一下指令方法慢慢的把版本推到新版

sudo apt install gitlab-ce=14.9.5-ce.0
sudo gitlab-ctl restart
sudo apt install gitlab-ce=14.10.5-ce.0
sudo gitlab-ctl restart
sudo apt install gitlab-ce=15.0.0-ce.0
sudo gitlab-ctl restart
sudo apt install gitlab-ce
sudo gitlab-ctl restart

錯誤解決

如果系統的 repo 沒有更新就會出現以下錯誤,他會覺得你已經是最新版了

Unable to upgrade: gitlab-ce is already the newest version (13.12.15-ce.0)

可以使用這個指令來指定安裝系統 https://about.gitlab.com/upgrade-to-package-repository/

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash

但是可能因為你的系統太新安裝舊版會找不到 repository 所以可以強制改成比較舊版的看看是不是可以成功

  • Ubuntu 20.04.6 LTS (Focal Fossa)
  • Ubuntu 18.04 LTS (Bionic Beaver)
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo os=ubuntu dist=focal bash
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo os=ubuntu dist=bionic bash