そういうのがいいブログ

SIerで働く30代サラリーマンSEがインフラエンジニアに憧れてLinux・クラウド・AWSの勉強をするブログ

GitLabをバージョンアップする手順(13.11.14から15.0.2へ)

※[PR]当ブログの記事の中にはプロモーションが含まれています。

・GitLabをバージョンアップする手順を知りたい。
・バージョン13からバージョン15まで順番にバージョンアップする手順を詳しく教えてほしい。

こういった疑問に答えます。

本記事の内容

  1. GitLabをバージョンアップする手順(13.11.14から15.0.2へ)

サトナカ (@souiunogaii)

この記事を書いている私は、某SIerに勤務しながら、
WEB系エンジニア・インフラエンジニアに憧れて、プログラミングおよびインフラ技術の勉強をしています。

こういった私が、解説していきます。

私が実機で試したコマンドや画像を載せて書いています。
記事の信頼性担保に繋がると思います。

GitLabをバージョンアップする手順(13.11.14から15.0.2へ)

GitLabのアップグレードパス

GitLabのバージョンアップをしばらくさぼっていた場合、いきなり最新バージョンに上げることができません。

Upgrade paths
Upgrading across multiple GitLab versions in one go is only possible by accepting downtime. The following examples assume downtime is acceptable while upgrading. If you don’t want any downtime, read how to upgrade with zero downtime.

Find where your version sits in the upgrade path below, and upgrade GitLab accordingly, while also consulting the version-specific upgrade instructions:

8.11.Z -> 8.12.0 -> 8.17.7 -> 9.5.10 -> 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.Z -> 15.0.Z -> latest 15.Y.Z

The following table, while not exhaustive, shows some examples of the supported upgrade paths.
Additional steps between the mentioned versions are possible. We list the minimally necessary steps only.
https://docs.gitlab.com/ee/update/#upgrade-paths

docs.gitlab.com

具体的なバージョンアップ手順

今回の私の環境でやりたいことは以下です。

  • 現在のバージョン:GitLab Community Edition 13.11.4
  • 更新後のバージョン:GitLab Community Edition 15.0.2

アップグレードパス

更新前 更新後 メモ
13.11.4 13.12.15
13.12.15 14.0.12 14に更新する前にunicornを無効化してpumaを有効化
14.0.12 14.3.6 更新後に手動でマイグレーションコマンド実行が必要
14.3.6 14.9.5
14.9.5 14.10.4
14.10.4 15.0.2

現在のバージョンを確認

[root@SV-MARS ~]# gitlab-rake gitlab:env:info

System information
System:
Current User:   git
Using RVM:      no
Ruby Version:   2.7.2p137
Gem Version:    3.1.4
Bundler Version:2.1.4
Rake Version:   13.0.3
Redis Version:  6.0.12
Git Version:    2.31.1
Sidekiq Version:5.2.9
Go Version:     unknown

GitLab information
Version:        13.11.4
Revision:       cea3c37b30e
Directory:      /opt/gitlab/embedded/service/gitlab-rails
DB Adapter:     PostgreSQL
DB Version:     12.6
URL:            https://gitlab.sv-mars.planet.space.com
HTTP Clone URL: https://gitlab.sv-mars.planet.space.com/some-group/some-project.git
SSH Clone URL:  git@gitlab.sv-mars.planet.space.com:some-group/some-project.git
Using LDAP:     no
Using Omniauth: yes
Omniauth Providers:

GitLab Shell
Version:        13.17.0
Repository storage paths:
- default:      /var/opt/gitlab/git-data/repositories
GitLab Shell path:              /opt/gitlab/embedded/service/gitlab-shell
Git:            /opt/gitlab/embedded/bin/git
https://gitlab.sv-mars.planet.space.com/help

アップグレードコマンド 13.11.4 ->13.12.15

dnf install gitlab-ce-13.12.15-ce.0.el8.x86_64
gitlab-ctl reconfigure
gitlab-ctl restart
[root@SV-MARS ~]# dnf install gitlab-ce-13.12.15-ce.0.el8.x86_64
gitlab_gitlab-ce                                                    319  B/s | 862  B     00:02
gitlab_gitlab-ce-source                                             266  B/s | 862  B     00:03
依存関係が解決しました。
====================================================================================================
 パッケージ          アーキテクチャー バージョン                   リポジトリー               サイズ
====================================================================================================
アップグレード:
 gitlab-ce           x86_64           13.12.15-ce.0.el8            gitlab_gitlab-ce           881 M

トランザクションの概要
====================================================================================================
アップグレード  1 パッケージ

ダウンロードサイズの合計: 881 M
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
gitlab-ce-13.12.15-ce.0.el8.x86_64.rpm                              5.9 MB/s | 881 MB     02:29
----------------------------------------------------------------------------------------------------
合計                                                                5.9 MB/s | 881 MB     02:30
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                            1/1
  scriptletの実行中: gitlab-ce-13.12.15-ce.0.el8.x86_64                                         1/2
gitlab preinstall: Automatically backing up only the GitLab SQL database (excluding everything else!)

~~~~~~~~~~~~~~~(中略)~~~~~~~~~~

gitlab Reconfigured!
Restarting previously running GitLab services
ok: run: alertmanager: (pid 2515215) 0s
ok: run: gitaly: (pid 1880) 1471501s
ok: run: gitlab-exporter: (pid 2515218) 1s
ok: run: gitlab-workhorse: (pid 2515202) 2s
ok: run: grafana: (pid 2515223) 0s
ok: run: logrotate: (pid 2515228) 0s
ok: run: nginx: (pid 2515235) 1s
ok: run: node-exporter: (pid 2515237) 0s
ok: run: postgres-exporter: (pid 2515250) 1s
ok: run: postgresql: (pid 1882) 1471504s
ok: run: prometheus: (pid 2515258) 0s
ok: run: puma: (pid 2515264) 1s
ok: run: redis: (pid 1881) 1471505s
ok: run: redis-exporter: (pid 2515272) 0s
ok: run: sidekiq: (pid 2515275) 1s

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


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).


  scriptletの実行中: gitlab-ce-13.11.4-ce.0.el8.x86_64                                          2/2
  検証             : gitlab-ce-13.12.15-ce.0.el8.x86_64                                         1/2
  検証             : gitlab-ce-13.11.4-ce.0.el8.x86_64                                          2/2

アップグレード済み:
  gitlab-ce-13.12.15-ce.0.el8.x86_64

完了しました!
[root@SV-MARS ~]# gitlab-ctl reconfigure
Starting Chef Infra Client, version 15.14.0
resolving cookbooks for run list: ["gitlab"]
Synchronizing Cookbooks:

~~~~~~~~~~~~~~~(中略)~~~~~~~~~~

Running handlers:
Running handlers complete
Chef Infra Client finished, 3/800 resources updated in 15 seconds

Deprecations:
* unicorn['worker_processes'] has been deprecated since 13.10 and will be removed in 14.0. Starting with GitLab 14.0, Unicorn is no longer supported and users must switch to Puma, following https://docs.gitlab.com/ee/administration/operations/puma.html.


Warnings:
The version of the running redis service is different than what is installed.
Please restart redis to start the new version.

sudo gitlab-ctl restart redis

gitlab Reconfigured!
[root@SV-MARS ~]# gitlab-ctl restart
ok: run: alertmanager: (pid 2518632) 1s
ok: run: gitaly: (pid 2518640) 1s
ok: run: gitlab-exporter: (pid 2518665) 1s
ok: run: gitlab-workhorse: (pid 2518669) 0s
ok: run: grafana: (pid 2518675) 1s
ok: run: logrotate: (pid 2518683) 0s
ok: run: nginx: (pid 2518691) 1s
ok: run: node-exporter: (pid 2518699) 0s
ok: run: postgres-exporter: (pid 2518707) 0s
ok: run: postgresql: (pid 2518715) 0s
ok: run: prometheus: (pid 2518794) 1s
ok: run: puma: (pid 2518810) 1s
ok: run: redis: (pid 2518815) 0s
ok: run: redis-exporter: (pid 2518824) 1s
ok: run: sidekiq: (pid 2518831) 0s

14に更新する前の設定変更(unicornを無効化しpumaを有効化)

GitLabの13から14に更新しようとすると、以下のエラーが出ます。

トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                                            1/1
  scriptletの実行中: gitlab-ce-14.0.12-ce.0.el8.x86_64                                          1/2
* unicorn['worker_processes'] has been deprecated since 13.10 and was removed in 14.0. Starting with GitLab 14.0, Unicorn is no longer supported and users must switch to Puma, following https://docs.gitlab.com/ee/administration/operations/puma.html.
Deprecations found. Please correct them and try again.
エラー: %prein(gitlab-ce-14.0.12-ce.0.el8.x86_64) スクリプトの実行に失敗しました。終了ステータス 1

Error in PREIN scriptlet in rpm package gitlab-ce
  検証             : gitlab-ce-14.0.12-ce.0.el8.x86_64                                          1/2
  検証             : gitlab-ce-13.12.15-ce.0.el8.x86_64                                         2/2

設定ファイルを書き換えます。

/etc/gitlab/gitlab.rb

unicorn の部分をコメントアウトして、逆に、pumaの部分のコメントを外します。

    868 ## GitLab Unicorn
    869 ##! Tweak unicorn settings.
    870 ##! Docs: https://docs.gitlab.com/omnibus/settings/unicorn.html
    871 ################################################################################
    872
    873 # unicorn['enable'] = false
    874 # unicorn['worker_timeout'] = 60
    875 ###! Minimum worker_processes is 2 at this moment
    876 ###! See https://gitlab.com/gitlab-org/gitlab-foss/issues/18771
    877 #unicorn['worker_processes'] = 2
    878
    879 ### Advanced settings
    880 # unicorn['listen'] = 'localhost'
    881 # unicorn['port'] = 8080
    882 # unicorn['socket'] = '/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket'
    883 # unicorn['pidfile'] = '/opt/gitlab/var/unicorn/unicorn.pid'
    884 # unicorn['tcp_nopush'] = true
    885 # unicorn['backlog_socket'] = 1024
    886
    887 ###! **Make sure somaxconn is equal or higher then backlog_socket**
    888 # unicorn['somaxconn'] = 1024
    889
    890 ###! **We do not recommend changing this setting**
    891 # unicorn['log_directory'] = "/var/log/gitlab/unicorn"
    892
    893 ### **Only change these settings if you understand well what they mean**
    895 ###!       https://github.com/kzk/unicorn-worker-killer
    896 # unicorn['worker_memory_limit_min'] = "1024 * 1 << 20"
    897 # unicorn['worker_memory_limit_max'] = "1280 * 1 << 20"
    898
    899 # unicorn['exporter_enabled'] = false
    900 # unicorn['exporter_address'] = "127.0.0.1"
    901 # unicorn['exporter_port'] = 8083
    902
    903 ################################################################################
    904 ## GitLab Puma
    905 ##! Tweak puma settings. You should only use Unicorn or Puma, not both.
    906 ##! Docs: https://docs.gitlab.com/omnibus/settings/puma.html
    907 ################################################################################
    908
    909 puma['enable'] = true
    910 puma['ha'] = false
    911 puma['worker_timeout'] = 60
    912 puma['worker_processes'] = 2
    913 puma['min_threads'] = 4
    914 puma['max_threads'] = 4
    915
    916 ### Advanced settings
    917 puma['listen'] = '127.0.0.1'
    918 puma['port'] = 8080
    919 puma['socket'] = '/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket'
    920 puma['pidfile'] = '/opt/gitlab/var/puma/puma.pid'
    921 puma['state_path'] = '/opt/gitlab/var/puma/puma.state'
    922
    923 ###! **We do not recommend changing this setting**
    924 # puma['log_directory'] = "/var/log/gitlab/puma"
    925
    926 ### **Only change these settings if you understand well what they mean**
    927 ###! Docs: https://github.com/schneems/puma_worker_killer
    928 # puma['per_worker_max_memory_mb'] = 850
    929
    930 # puma['exporter_enabled'] = false
    931 # puma['exporter_address'] = "127.0.0.1"
    932 # puma['exporter_port'] = 8083

アップグレードコマンド 13.12.15 ->14.0.12

dnf install gitlab-ce-14.0.12-ce.0.el8.x86_64
gitlab-ctl reconfigure
gitlab-ctl restart

アップグレードコマンド 14.0.12 ->14.3.6

dnf install gitlab-ce-14.3.6-ce.0.el8.x86_64
gitlab-ctl reconfigure
gitlab-ctl restart

reconfigureの後、以下のエラーが発生しました。

There was an error running gitlab-ctl reconfigure:

rails_migration[gitlab-rails] (gitlab::database_migrations line 51) had an error: Mixlib::ShellOut::ShellCommandFailed: bash[migrate gitlab-rails database] (/opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/resources/rails_migration.rb line 16) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of "bash"  "/tmp/chef-script20220611-1944-1qnl8xf" ----
STDOUT: rake aborted!
StandardError: An error has occurred, all later migrations canceled:

Expected batched background migration for the given configuration to be marked as 'finished', but it is 'active':   {:job_class_name=>"CopyColumnUsingBackgroundMigrationJob", :table_name=>"ci_stages", :column_name=>"id", :job_arguments=>[["id"], ["id_convert_to_bigint"]]}

Finalize it manualy by running

        sudo gitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,ci_stages,id,'[["id"]\, ["id_convert_to_bigint"]]']

For more information, check the documentation

        https://docs.gitlab.com/ee/user/admin_area/monitoring/background_migrations.html#database-migrations-failing-because-of-batched-background-migration-not-finished
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migration_helpers.rb:1109:in `ensure_batched_background_migration_is_finished'
/opt/gitlab/embedded/service/gitlab-rails/db/post_migrate/20210707210916_finalize_ci_stages_bigint_conversion.rb:13:in `up'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migrations/lock_retry_mixin.rb:31:in `ddl_transaction'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:61:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `<main>'

Caused by:
Expected batched background migration for the given configuration to be marked as 'finished', but it is 'active':   {:job_class_name=>"CopyColumnUsingBackgroundMigrationJob", :table_name=>"ci_stages", :column_name=>"id", :job_arguments=>[["id"], ["id_convert_to_bigint"]]}

Finalize it manualy by running

        sudo gitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,ci_stages,id,'[["id"]\, ["id_convert_to_bigint"]]']

For more information, check the documentation

        https://docs.gitlab.com/ee/user/admin_area/monitoring/background_migrations.html#database-migrations-failing-because-of-batched-background-migration-not-finished
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migration_helpers.rb:1109:in `ensure_batched_background_migration_is_finished'
/opt/gitlab/embedded/service/gitlab-rails/db/post_migrate/20210707210916_finalize_ci_stages_bigint_conversion.rb:13:in `up'
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/database/migrations/lock_retry_mixin.rb:31:in `ddl_transaction'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:61:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
== 20210707210916 FinalizeCiStagesBigintConversion: migrating =================
STDERR:
---- End output of "bash"  "/tmp/chef-script20220611-1944-1qnl8xf" ----
Ran "bash"  "/tmp/chef-script20220611-1944-1qnl8xf" returned 1

Running handlers complete
Chef Infra Client failed. 3 resources updated in 02 minutes 02 seconds

指示に従って、手動でマイグレーションを実行します。

gitlab-rake db:migrate

アップグレードコマンド 14.3.6 -> 14.9.5

dnf install gitlab-ce-14.9.5-ce.0.el8.x86_64

アップグレードコマンド 14.9.5 -> 14.10.4

dnf install gitlab-ce-14.10.4-ce.0.el8.x86_64

アップグレードコマンド 14.10.4 -> 15.0.2

dnf install gitlab-ce-15.0.2-ce.0.el8.x86_64

更新後のバージョンを確認

502エラーが起きたら

GitLabをバージョンアップすると、502エラーが出ました。

バージョンアップ直後の1~2分くらいは、502エラーが出ますが、待っていれば自動で回復します。

インフラエンジニアになるための勉強のやり方

私は、某SIerに勤務しながら、WEB系エンジニア・インフラエンジニアに憧れて、プログラミングおよびインフラ技術の勉強をしています。

現在の会社で直接担当している業務の中では、決まった技術しか触れないけれど、
「他にも将来役に立ちそうなインフラ技術を勉強したい」「働きながらでもできる効率的なインフラエンジニアの勉強方法を知りたい」と考えている方のために、
①おすすめの書籍と、②おススメのオンライン学習サイトを紹介します。

働きながら勉強するための、おススメの書籍と、オンラインで学習できるサイトの紹介です。

インフラエンジニアの勉強ができるおススメ書籍

朝の通勤時や帰宅時の電車の中や、社外打合せへの移動中などに勉強するなら、やはり書籍が一番だと思います。

インフラエンジニアの教科書

LINE社に創業時から在籍しているインフラエンジニア・プロマネの「佐野裕」さんの本です。 twitter.com

膨大なトラフィックをさばくLINE社にて構築・保守を行っている現役エンジニアが記すITインフラの必須知識と経験の数々! サーバ、OS、ネットワーク機器、データセンター、購買と商談、障害対応、大規模インフラ、成長するために必要なスキルなど、基礎知識から実践まで言及。 ITインフラの世界が理解できる珠玉の1冊!

インフラエンジニアの教科書
(C&R研究所)
佐野裕

1週間でLPICの基礎が学べる本

Linuxの資格「LPIC」の試験対策を初心者向けに書いた入門書です。

Linuxの資格として広く知られているLPICですが、あまり知識の無いまま試験対策を始める人も多いのではないでしょうか。しかし、試験対策書は試験範囲についてのみ解説しているものが多く、初心者が理解するのは困難です。本書は、初心者がスムーズに試験対策を行えるよう、事前に基礎固めを行うLinux入門書です。試験情報や模擬問題も掲載しているので、資格取得を視野に入れた効率的な基礎学習が行えます。

1週間でLPICの基礎が学べる本
第3版 徹底攻略シリーズ
(インプレス)
中島能和

インフラエンジニアの勉強ができるオンライン学習サイト

Udemy (オンライン動画学習サイト)

Udemy(ユーデミー)は、オンラインで動画で学習できるサービスです。
ITエンジニア系の講座もたくさん公開されています。

≫Udemy 世界最大級のオンライン学習サイト

Udemyの特徴
  • ユーザー登録すれば、第1回の講座は無料で視聴できる
  • 無料のコンテンツもある
  • 過去に受講した人の人数や、受講した人の評価も表示されるので選びやすい

≫Udemy 世界最大級のオンライン学習サイト

開発の人気オンラインコース

以上、読んでいただきありがとうございました。