GitLab

提供: ArchWiki
2022年7月30日 (土) 12:18時点におけるKusanaginoturugi (トーク | 投稿記録)による版 (カテゴリを削除)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
ナビゲーションに移動 検索に移動

関連記事

GitLab のホームページ より:

GitLab は git リポジトリの管理、コードレビュー、イシュートラッキング、アクティビティフィード、wiki を提供します。エンタープライズは自社運用な GitLab をインストールして LDAP や Active Directory サーバーと接続してセキュアな認証を行います。単一の GitLab サーバーだけで 25,000 以上のユーザーを管理することができますが、サーバーを複数用意すれば更に多数のユーザーを使えるようにすることが可能です。

実際に動作するサンプル版が GitLab.com に存在します。

インストール

ノート:
  • RVM を使いたい場合はインストールする前に #rvm で GitLab を実行 を参照してください。
  • この記事ではまず HTTPS を使わないで GitLab をインストール・設定する方法を説明します。HTTPS が必要な場合は #高度な設定 を参照して SSL をセットアップしてください。

GitLab は Redis とデータベースバックエンドを必要します。同一のマシン上でデータベースを実行する場合、先に MySQLPostgreSQL をインストールしてください。

gitlab パッケージをインストールしてください。

メール通知を受け取るには、メールサーバーをインストール・設定する必要があります。詳しくは次のカテゴリを参照: カテゴリ:メールサーバー

設定

設定ファイル

gitlab パッケージは GitLab のファイルを Linux の標準的な慣習にそって以下のようにインストールします:

説明 GitLab 公式 gitlab
GitShell の設定ファイル /home/git/gitlab-shell/config.yml /etc/webapps/gitlab-shell/config.yml
GitLab の設定ファイル /home/git/gitlab/config/gitlab.yml /etc/webapps/gitlab/gitlab.yml
ユーザー (ホームディレクトリ) git (/home/git) gitlab (/var/lib/gitlab)
ヒント: Arch Build System が使用できるのであれば、PKGBUILD や関連するファイルを編集することで gitlab のホームディレクトリを好きな場所に変更できます。

基本設定

GitLab

/etc/webapps/gitlab/gitlab.yml を編集して以下のパラメータを設定してください:

ヒント: ホストネームとポートは git clone http://hostname:port などとして使われます。

ホストネーム: gitlab: セクションで host: を設定 - localhostyourdomain.com に置き換えます (ノート: 'http://' や末尾のスラッシュは付けません) - 完全修飾ドメイン名を使ってください。

ポート: port: は紛らわしいかもしれません。gitlab サーバー (unicorn) が動作するポートではありません。ユーザーがブラウザを使って最初にアクセスするときのポートです。ブラウザから 'yourdomain.com' にアクセスするようにしたい場合、ドメイン名にポート番号は基本的に付けないので、port:80 のままにしておきます。ブラウザに 'yourdomain.com:3425' などと入力させるときのみ、port:3425 と設定します。また、ウェブサーバーの設定も変更して、設定したポートを使うようにしてください。

タイムゾーン (任意): time_zone: パラメータは任意ですが、GitLab アプリケーションのゾーンを強制することができます。

最後に uploads ディレクトリに適切なパーミッションを設定:

# chmod 700 /var/lib/gitlab/uploads

GitLab Shell

ノート: 同一のホスト上で GitLab をホストする場合 gitlab_url はデフォルト値のままで問題ありません。

/etc/webapps/gitlab-shell/config.yml を編集して gitlab_url: で適当な url とポートを設定してください:

/etc/webapps/gitlab-shell/config.yml
# GitLab user. git by default
user: gitlab

# Url to gitlab instance. Used for api calls. Should end with a slash.
# Default: http://localhost:8080/
# You only have to change the default if you have configured Unicorn
# to listen on a custom port, or if you have configured Unicorn to
# only listen on a Unix domain socket.
gitlab_url: "http://localhost:8080/"

http_settings:
#  user: someone
#  password: somepass
...

ポートやホストネームがデフォルト値と違う場合は /etc/webapps/gitlab/unicorn.rb の設定を更新してください:

/etc/webapps/gitlab/unicorn.rb
listen "/run/gitlab/gitlab.socket", :backlog => 1024
listen "127.0.0.1:8080", :tcp_nopush => true

Redis

デフォルトとは異なる構成で Redis を使用するときは (アドレスやポート、Unix ソケットなどが異なる場合)、REDIS_URL 環境変数を正しく設定する必要があります。systemd サービスファイルを拡張することで設定できます。/etc/systemd/system/gitlab-unicorn.service.d/redis.conf ファイルを作成して REDIS_URL 環境変数を挿入してください:

/etc/systemd/system/gitlab-unicorn.service.d/redis.conf
[Service]
Environment=REDIS_URL=unix:///run/gitlab/redis.sock
Redis で Unix ソケットを使う

Redis#ソケットを使うの手順にしたがって、デフォルト設定を調整してください [1]

  • gitgitlab ユーザーを redis グループに追加。
  • 設定ファイルを更新:
/etc/webapps/gitlab/resque.yml
development: unix:/run/redis/redis.sock
test: unix:/run/redis/redis.sock
production: unix:/run/redis/redis.sock
/etc/webapps/gitlab-shell/config.yml
# Redis settings used for pushing commit notices to gitlab
redis:
  bin: /usr/bin/redis-cli
  host: 127.0.0.1
  port: 6379
  # pass: redispass # Allows you to specify the password for Redis
  database: 5 # Use different database, default up to 16
  socket: /run/redis/redis.sock # uncomment this line
  namespace: resque:gitlab

詳細設定

データベースバックエンド

Gitlab を実行する前にデータベースバックエンドが必要になります。現在 GitLab は MariaDBPostgreSQL をサポートしています。デフォルトでは、GitLab は MySQL を使うことになっています。PostgreSQL を使用する場合、特別な設定が必要です。

MariaDB

MySQL (MariaDB) をセットアップする場合、gitlabhq_production という名前のデータベースと、そのデータベースの全ての権限を持ったユーザーを作成してください (デフォルト: gitlab):

$ mysql -u root -p
mysql> CREATE DATABASE `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
mysql> \q

新しいユーザーで新しいデータベースへの接続を試行:

$ mysql -u gitlab -p -D gitlabhq_production

MySQL テンプレートファイルをコピー:

# cp /usr/share/doc/gitlab/database.yml.mysql /etc/webapps/gitlab/database.yml

次に /etc/webapps/gitlab/database.yml を開いて gitlabhq_productionusername:password: を設定してください:

/etc/webapps/gitlab/database.yml
#
# PRODUCTION
#
production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  collation: utf8_general_ci
  database: gitlabhq_production
  pool: 10
  username: username
  password: "password"
  # host: localhost
  # socket: /run/mysqld/mysqld.sock # If running MariaDB as socket
...

ファイルは誰からでも読み込めるようにするべきではありません。gitlab ユーザーのプロセスだけが読み書きできるようにします:

# chmod 600 /etc/webapps/gitlab/database.yml
# chown gitlab:gitlab /etc/webapps/gitlab/database.yml

MySQL データベースの作成・管理に関する詳しい情報は MariaDB のドキュメントGitLab 公式の (汎用) インストールガイド を見てください。

PostgreSQL

PostgreSQL にログインして gitlabhq_production データベースとユーザーを作成してください。your_username_hereyour_password_here は実際の値に置き換えてください:

# psql -d template1
template1=# CREATE USER your_username_here WITH PASSWORD 'your_password_here';
template1=# ALTER USER your_username_here SUPERUSER;
template1=# CREATE DATABASE gitlabhq_production OWNER your_username_here;
template1=# \q
ノート: ユーザーをスーパーユーザーとして作成することで GitLab は「スマート」になり拡張をインストールします。PostgreSQL ではスーパーユーザーだけが拡張のインストールを許可されています。

新しいユーザーで新しいデータベースに接続してデータベースが使えることを確認:

# psql -d gitlabhq_production

続行する前に PostgreSQL テンプレートファイルをコピーしてください (デフォルトの MySQL 設定ファイルを上書きします):

# cp /usr/share/doc/gitlab/database.yml.postgresql /etc/webapps/gitlab/database.yml

新しい /etc/webapps/gitlab/database.yml を開いて username:password: の値を設定します。例:

/etc/webapps/gitlab/database.yml
#
# PRODUCTION
#
production:
  adapter: postgresql
  encoding: unicode
  database: gitlabhq_production
  pool: 10
  username: your_username_here
  password: "your_password_here"
  # host: localhost
  # port: 5432
  # socket: /tmp/postgresql.sock
...

/etc/webapps/gitlab/database.yml に記載されている他のデータベースの設定について心配する必要はありません。GitLab を使うにはプロダクションデータベースだけをセットアップすれば十分です。

ファイアウォール

iptables ファイアウォールを通り抜けて Gitlab に直接アクセスできるようにしたい場合、ポートとネットワークアドレスを調整してください:

# iptables -A tcp_inbound -p TCP -s 192.168.1.0/24 --destination-port 80 -j ACCEPT

API のアクセスを有効にするには:

# iptables -A tcp_inbound -p TCP -s 192.168.1.0/24 --destination-port 8080 -j ACCEPT

ルーターを使っている場合、WAN からアクセスできるようにしたいとき、GitLab サーバーを実行しているホストにポートを転送するようにしてください。

Gitlab データベースの初期化

データベースを作成する前に Redis サーバーを起動してください。

データベースを初期化して高度な機能を有効化:

# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake gitlab:setup RAILS_ENV=production"

最後に以下のコマンドを実行して環境チェックを実行:

# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake gitlab:env:info RAILS_ENV=production"
# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake gitlab:check RAILS_ENV=production"
ノート:
  • gitlab:env:infogitlab:check コマンドは git に関するエラーを表示しますが問題ありません。
  • gitlab:checkCheck GitLab API access: FAILED. code: 401 というエラーで失敗する場合、トラブルシューティングセクションの #API アクセス時に 401 Unauthorized#/etc/webapps/gitlab/secret が空を参照して解決してください。
  • gitlab:check は initscripts が存在しないとエラーを吐きます。systemd サービスファイルを使用するため問題ありません (GitLab から認識されないだけです)。

Git ユーザーの設定

# cd /usr/share/webapps/gitlab
# sudo -u gitlab -H git config --global user.name  "GitLab"
# sudo -u gitlab -H git config --global user.email "example@example.com"
# sudo -u gitlab -H git config --global core.autocrlf "input"

修飾ビットの調整

ユーザーとグループが正しく設定されていないと gitlab check が通過しません:

# chmod -R ug+rwX,o-rwx /var/lib/gitlab/repositories/
# chmod -R ug-s /var/lib/gitlab/repositories
# find /var/lib/gitlab/repositories/ -type d -print0 | xargs -0 chmod g+s

GitLab の起動とテスト

ノート: 何か問題が発生する場合は #トラブルシューティング/usr/share/webapps/gitlab/log ディレクトリのログファイルを見てください。

MySQL または PostgreSQLRedis が適切にセットアップ・実行されていることを確認してください。

データベースバックエンドの起動後、gitlab-sidekiqgitlab-unicorn ユニットを両方とも起動することで GitLab を独自のウェブサーバー (Unicorn) で起動できます。

システムの起動時に GitLab を自動的に実行したいときは gitlab.target, gitlab-sidekiq, gitlab-unicorn サービスを有効化してください。

そして http://localhost:8080http://yourdomain.com をブラウザで開いて GitLab インスタンスをテストしてください。パスワードの作成が要求されます:

username: root
password: You'll be prompted to create one on your first visit.

アップデート時のデータベースアップグレード

gitlab パッケージをアップデートした後、データベースをアップグレードする必要があります:

# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake db:migrate RAILS_ENV=production"

アップグレード後、gitlab 関連のサービスを再起動してください:

# systemctl daemon-reload
# systemctl restart gitlab-sidekiq gitlab-unicorn gitlab-workhorse gitlab-gitaly

高度な設定

SSH 接続のカスタマイズ

SSH を標準以外のポートで実行している場合、GitLab ユーザーの SSH 設定を変更する必要があります:

/var/lib/gitlab/.ssh/config
host localhost      # Give your setup a name (here: override localhost)
user gitlab         # Your remote git user
port 2222           # Your port number
hostname 127.0.0.1; # Your server name or IP

/etc/webapps/gitlab/gitlab.yml ファイルのオプション (例: ssh_user, ssh_host, admin_uri) も変更してください。

HTTPS/SSL

GitLab 設定の変更

/etc/webapps/gitlab/shell.yml を修正して GitLab サイトを https:// から始まる URL に変えてください。/etc/webapps/gitlab/gitlab.yml を修正して https:true に設定してください。

Let's Encrypt

URL を検証する際、Let's Encrypt は https://gitlab.YOUR_SERVER_FQDN/.well-known/acme-challenge/A_LONG_ID のように gitlab サーバーにアクセスできるかどうか試行します。しかしながら、gitlab の設定によって、gitlab.YOUR_SERVER_FQDN へのリクエストはプロキシ (gitlab-workhorse) に全て転送されるため、URL の確認が失敗します。

Let's Encrypt の webroot を使用することでこの問題を回避することが可能です。webroot を /srv/http/letsencrypt/ に設定してください。

さらに、Let's Encrypt の gitlab へのリクエストが全て webroot に転送されるように、以下の記述を追加します:

/etc/http/conf/extra/gitlab.conf
Alias "/.well-known"  "/srv/http/letsencrypt/.well-known"
RewriteCond   %{REQUEST_URI}  !/\.well-known/.*

ウェブサーバーの設定

Gitlab に組み込まれている http サーバー、Unicorn を使うかわりに別のウェブサーバーで Gitlab を使いたい場合、以下の手順に従ってください。

Node.js

Node.js の http-master を使用することでポート 8080 で動作している GitLab アプリケーションにトラフィックを転送する http プロキシをポート 443 に設定することができます。ドメインの OpenSSL 鍵を作成して CA 証明書を取得 (もしくは自己署名) した後に、https://github.com/CodeCharmLtd/http-master を読んでください。HTTPS を使って GitLab にリクエストを転送する方法が載っています。http-master は node-http-proxy を元に作成されています。

Nginx と unicorn

/usr/share/doc/gitlab/nginx.conf.example または /usr/share/doc/gitlab/nginx-ssl.conf.example/etc/nginx/servers-available/gitlab にコピーしてください。詳しくは Nginx#サーバーブロックを参照。

/etc/nginx/servers-available/gitlab ファイルをアップデートして nginx のサービスを再起動してください。

認証できない場合、/etc/nginx/servers-available/gitlab に以下のヘッダーを追加してください:

proxy_set_header    X-Forwarded-Ssl     on; # Only when using SSL
proxy_set_header    X-Frame-Options     SAMEORIGIN; 
別の設定例
ノート: localhost:8080 を gitlab のアドレスに example.com をサーバーの名前に置き換える必要があります。
ヒント: SSL を有効にする前に Nginx#SSL を見てください。

以下の内容で /etc/nginx/servers-available/gitlab ファイルを作成:

/etc/nginx/servers-available/gitlab
# Created by: Sameer Naik
# Contributor: francoism90
# Source: https://gist.github.com/sameersbn/becd1c976c3dc4866ef8
upstream gitlab-workhorse {
  server unix:/run/gitlab/gitlab-workhorse.socket fail_timeout=0;
}

server {
  listen 80;
  #listen 443 ssl; # uncomment to enable ssl
  keepalive_timeout 70;
  server_name example.com
  server_tokens off;
  #ssl_certificate ssl/example.com.crt;
  #ssl_certificate_key ssl/example.com.key;
  charset utf-8;
  root /dev/null;
  
  # Increase this if you want to upload larger attachments
  client_max_body_size 20m;
  
  location / {
      proxy_read_timeout 300;
      proxy_connect_timeout 300;
      proxy_redirect off;
      
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-Ssl on;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Frame-Options SAMEORIGIN;
      
      proxy_pass http://gitlab-workhorse;
  }  
}

Apache と unicorn

公式リポジトリから apacheインストールしてください。

Unicorn の設定

公式のインストールガイドに書かれているように、unicorn の設定ファイルをコピーしてください:

# sudo -u git -H cp /usr/share/webapps/gitlab/config/unicorn.rb.example /usr/share/webapps/gitlab/config/unicorn.rb

config/unicorn.rb を編集し以下の行をアンコメントして listen ポートを追加します:

listen "127.0.0.1:8080"
ヒント: カスタムポートを設定することもできます。Apache のバーチャルホストでも忘れずに設定してください。下を参照。
Gitlab のバーチャルホストの作成

Gitlab のバーチャルホストの設定ファイルを作成して以下の行を調整して挿入してください。ssl セクションについては LAMP#TLS/SSL を参照。SSL が必要ないときは、削除してください。SSL バーチャルホストは汎用の IP ではなく特定の IP を必要とします。Unicorn のカスタムポートを設定している場合、BalanceMember 行で忘れずに設定してください。

サンプル を使って開始できます。

ホストの有効化と unicorn の起動

Gitlab のバーチャルホストを有効化して Apache をリロード:

/etc/httpd/conf/httpd.conf
 Include /etc/httpd/conf/extra/gitlab.conf

Apache の gitlab.conf ファイルをコピー:

# cp /usr/share/doc/gitlab/apache.conf.example /etc/httpd/conf/extra/gitlab.conf

最後に gitlab-unicorn.service起動してください。

Gitlab-workhorse

8.0 から GitLab は Git の push/pull などの巨大な HTTP リクエスト用に特別な HTTP サーバー gitlab-workhorse を使用しています。SSH の代わりに workhorse を使いたい場合、gitlab-workhorse.service を有効化してウェブサーバーを設定してください。GitLab チームによれば gitlab-unicorn よりも gitlab-workhorse を使用することが推奨されています: https://gitlab.com/gitlab-org/gitlab-ce/issues/22528#note_16036216

ノート: Unicorn が不要になるわけではないので gitlab-unicorn.service を無効化・停止してはいけません。Unicorn が使用するポートを変更している場合、gitlab-workhorse.service-authBackend 設定を適宜変更してください。

デフォルトでは gitlab-workhorse/run/gitlab/gitlab-workhorse.socket を listen します。gitlab-workhorse.service を編集して -listenAddr パラメータを変更することで指定したアドレスを listen するようになります (例: -listenAddr 127.0.0.1:8181)。アドレスを listen する場合、ネットワークタイプを -listenNetwork tcp に設定する必要があります。

nginx を使用している場合、nginx の設定ファイルも忘れずに編集してください。gitlab-unicorn から gitlab-workhorse に切り替えるには以下の設定を編集します:

/etc/nginx/servers-available/gitlab
upstream gitlab {
   server unix:/run/gitlab/gitlab-workhorse.socket fail_timeout=0;
}

...
      
      proxy_pass http://unix:/run/gitlab/gitlab-workhorse.socket;
  }  
}

便利なヒント

Rake の警告の修正

gitlab プロジェクトで rake タスクを実行すると、次のエラーが発生します: fatal: Not a git repository (or any of the parent directories): .git。これは bundle のバグなので、無視してもかまいません。エラーを消したい場合は、以下を実行してください:

# cd /usr/share/webapps/gitlab
# sudo -u gitlab git init
# sudo -u gitlab git commit -m "initial commit" --allow-empty

/var のフック

# mkdir -m700 /var/log/gitlab /var/tmp/gitlab
# chown gitlab:gitlab /var/log/gitlab /var/tmp/gitlab
# sudo -u gitlab -i
# cd ~/gitlab
# d=log; mv $d/* /var/$d/gitlab; rm -f $d/.gitkeep; rm -r $d && ln -s /var/$d/gitlab $d
# d=tmp; mv $d/* /var/$d/gitlab; rm -f $d/.gitkeep; rm -r $d && ln -s /var/$d/gitlab $d

隠しオプション

Gitlab のホームディレクトリに移動して:

# cd /usr/share/webapps/gitlab

次を実行:

# rake -T | grep gitlab
rake gitlab:app:check                         # GITLAB | Check the configuration of the GitLab Rails app
rake gitlab:backup:create                     # GITLAB | Create a backup of the GitLab system
rake gitlab:backup:restore                    # GITLAB | Restore a previously created backup
rake gitlab:check                             # GITLAB | Check the configuration of GitLab and its environment
rake gitlab:cleanup:block_removed_ldap_users  # GITLAB | Cleanup | Block users that have been removed in LDAP
rake gitlab:cleanup:dirs                      # GITLAB | Cleanup | Clean namespaces
rake gitlab:cleanup:repos                     # GITLAB | Cleanup | Clean repositories
rake gitlab:env:check                         # GITLAB | Check the configuration of the environment
rake gitlab:env:info                          # GITLAB | Show information about GitLab and its environment
rake gitlab:generate_docs                     # GITLAB | Generate sdocs for project
rake gitlab:gitlab_shell:check                # GITLAB | Check the configuration of GitLab Shell
rake gitlab:import:all_users_to_all_groups    # GITLAB | Add all users to all groups (admin users are added as owners)
rake gitlab:import:all_users_to_all_projects  # GITLAB | Add all users to all projects (admin users are added as masters)
rake gitlab:import:repos                      # GITLAB | Import bare repositories from gitlab_shell -> repos_path into GitLab project instance
rake gitlab:import:user_to_groups[email]      # GITLAB | Add a specific user to all groups (as a developer)
rake gitlab:import:user_to_projects[email]    # GITLAB | Add a specific user to all projects (as a developer)
rake gitlab:satellites:create                 # GITLAB | Create satellite repos
rake gitlab:setup                             # GITLAB | Setup production application
rake gitlab:shell:build_missing_projects      # GITLAB | Build missing projects
rake gitlab:shell:install[tag,repo]           # GITLAB | Install or upgrade gitlab-shell
rake gitlab:shell:setup                       # GITLAB | Setup gitlab-shell
rake gitlab:sidekiq:check                     # GITLAB | Check the configuration of Sidekiq
rake gitlab:test                              # GITLAB | Run all tests
rake gitlab:web_hook:add                      # GITLAB | Adds a web hook to the projects
rake gitlab:web_hook:list                     # GITLAB | List web hooks
rake gitlab:web_hook:rm                       # GITLAB | Remove a web hook from the projects
rake setup                                    # GITLAB | Setup gitlab db

バックアップとリストア

gitlab システムのバックアップを作成:

# sudo -u gitlab -H rake RAILS_ENV=production gitlab:backup:create

先に作成したバックアップファイル /home/gitlab/gitlab/tmp/backups/20130125_11h35_1359131740_gitlab_backup.tar をリストア:

# sudo -u gitlab -H rake RAILS_ENV=production gitlab:backup:restore BACKUP=/home/gitlab/gitlab/tmp/backups/20130125_11h35_1359131740
ノート: バックアップフォルダは config/gitlab.yml に設定されています。GitLab のバックアップとリストアについては こちら に記載があります。

sqlite から mysql への移行

最新のコードを取得してください。

データを保存:

# cd /home/gitlab/gitlab
# sudo -u gitlab bundle-2.3 exec rake db:data:dump RAILS_ENV=production

#Mysql の手順に従ってデータベースをセットアップ:

# sudo -u gitlab bundle-2.3 exec rake db:setup RAILS_ENV=production

最後にデータをリストア:

# sudo -u gitlab bundle-2.3 exec rake db:data:load RAILS_ENV=production

rvm で GitLab を実行

rvm で gitlab を実行するにはまず rvm をセットアップしてください:

curl -L https://get.rvm.io | bash -s stable --ruby=1.9.3
ノート: 互換問題を避けるためにバージョン 1.9.3 を使用することが現在推奨されています。

完全にインストールするためにユーザーを変更 (例: git) して rvm を有効化してください:

su - git
source "$HOME/.rvm/scripts/rvm"

それから上のインストール手順に従ってください。ただし、rvm 環境が有効にならないため systemd スクリプトが上手く動きません。unicornsidekiq のシェルスクリプトを作成して環境を有効にしてサービスを起動させることを推奨します:

gitlab.sh
#!/bin/sh
source `/home/git/.rvm/bin/rvm 1.9.3 do rvm env --path`
bundle-2.3 exec "unicorn_rails -c /usr/share/webapps/gitlab/config/unicorn.rb -E production"
sidekiq.sh
#!/bin/sh
source `/home/git/.rvm/bin/rvm 1.9.3 do rvm env --path`
case $1 in
    start)
        bundle-2.3 exec rake sidekiq:start RAILS_ENV=production
        ;;
    stop)
        bundle-2.3 exec rake sidekiq:stop RAILS_ENV=production
        ;;
    *)
        echo "Usage $0 {start|stop}"
esac

それから上記の systemd ファイルを編集してスクリプトが使われるようにしてください。以下の行を修正します:

gitlab.service
ExecStart=/home/git/bin/gitlab.sh
sidekiq.service
ExecStart=/home/git/bin/sidekiq.sh start
ExecStop=/home/git/bin/sidekiq.sh stop

SMTP を使って Gitlab からメールを送信

gitlab サーバーから gmail (あるいは他のメールサービス) を使ってメールを送信することができます。これにより、gitlab サーバーにメールデーモンをインストールする手間が省けます。

メールサーバーの設定にあわせて smtp_settings.rb を修正してください:

/usr/share/webapps/gitlab/config/initializers/smtp_settings.rb
if Rails.env.production?
  Gitlab::Application.config.action_mailer.delivery_method = :smtp

  Gitlab::Application.config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'gmail.com',
    user_name:            'username@gmail.com',
    password:             'application password',
    authentication:       'plain',
    enable_starttls_auto: true
  }
end

Gmail はメールの受信を拒否します (拒否した旨のメールが届きます)。セキュア認証を無効化する必要があります (拒否メールのリンクに従ってください)。セキュアな方法としては username@gmail.com の2段階認証を有効にして設定ファイルにアプリケーションパスワードを設定する方法があります。

トラブルシューティング

ときどき GitLab が上手く動作しないことがあります。Trouble Shooting Guide を確認してください。

HTTPS が緑じゃない (gravatar が https を使わない)

Redis は gravatar の画像をキャッシュするため、http で GitLab にアクセスした後に https を有効にすると、gravatar がセキュアでない画像をロードしてしまいます。gitlab ユーザーで以下を実行することでキャッシュの消去が可能です:

cd /usr/share/webapps/gitlab
RAILS_ENV=production bundle-2.3 exec rake cache:clear

API アクセス時に 401 Unauthorized

/etc/webapps/gitlab/secret/etc/webapps/gitlab-shell/secret のファイルに中身があるか確認してください。

push 時に bad line length character: API というエラーが発生する

push しようとすると以下のエラーが表示される場合:

fatal: protocol error: bad line length character: API

/etc/webapps/gitlab-shell/secret/usr/share/webapps/gitlab/.gitlab_shell_secret が一致していることを確認してください。

一致していない場合、以下のコマンドでファイルを再作成してください:

# ln -s /etc/webapps/gitlab-shell/secret /usr/share/webapps/gitlab/.gitlab_shell_secret

アップデート後のエラー

AUR からパッケージを更新したとき、データベースの移行やアセットのアップデートに失敗することがあります。再起動で問題が解決しない場合、以下の方法を試してみてください。

まず、gitlab のインストールディレクトリに移動:

# cd /usr/share/webapps/gitlab

全ての gitlab ページが500エラーを返す場合、データベースの移行やアセットが古くなっている可能性があります。そうでない場合、以下のコマンドはスキップしてください。

# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake db:migrate RAILS_ENV=production"

gitlab のデプロイが永遠に完了しない場合、アセットが再コンパイルされていない可能性があります:

# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake gitlab:assets:clean gitlab:assets:compile cache:clear RAILS_ENV=production"

最後に、gitlab サービスを再起動してサイトをテストしてください:

# systemctl restart gitlab-unicorn gitlab-sidekiq gitlab-workhorse

/etc/webapps/gitlab/secret が空

通常は gitlab-shellgitlab パッケージのインストール時に生成されますが、生成されなかった場合、手動で生成する必要があります:

# hexdump -v -n 64 -e '1/1 "%02x"' /dev/urandom > /etc/webapps/gitlab-shell/secret
# chown root:gitlab /etc/webapps/gitlab-shell/secret
# chmod 640 /etc/webapps/gitlab-shell/secret
# hexdump -v -n 64 -e '1/1 "%02x"' /dev/urandom > /etc/webapps/gitlab/secret
# chown root:gitlab /etc/webapps/gitlab/secret
# chmod 640 /etc/webapps/gitlab/secret

参照