「GitLab」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(同期)
(同期)
17行目: 17行目:
 
* この記事ではまず HTTPS を使わないで GitLab をインストール・設定する方法を説明します。HTTPS が必要な場合は [[#高度な設定]] を参照して SSL をセットアップしてください。}}
 
* この記事ではまず HTTPS を使わないで GitLab をインストール・設定する方法を説明します。HTTPS が必要な場合は [[#高度な設定]] を参照して SSL をセットアップしてください。}}
   
GitLab はデータベースバックエンドを必要します。同一のマシン上でデータベースを実行する場合、先に [[MySQL]] か [[PostgreSQL]] をインストールしてください。
+
GitLab は [[Redis]] とデータベースバックエンドを必要します。同一のマシン上でデータベースを実行する場合、先に [[MySQL]] か [[PostgreSQL]] をインストールしてください。
   
 
{{Pkg|gitlab}} パッケージを[[インストール]]してください。
 
{{Pkg|gitlab}} パッケージを[[インストール]]してください。
30行目: 30行目:
 
{| class="wikitable"
 
{| class="wikitable"
 
! 説明
 
! 説明
! [https://github.com/gitlabhq/gitlabhq/blob/6-5-stable/doc/install/installation.md GitLab 公式]
+
! [https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md GitLab 公式]
 
! {{Pkg|gitlab}}
 
! {{Pkg|gitlab}}
 
|----------------------------------------------------------
 
|----------------------------------------------------------
49行目: 49行目:
   
 
===基本設定===
 
===基本設定===
  +
  +
====GitLab====
  +
{{ic|/etc/webapps/gitlab/gitlab.yml}} を編集して以下のパラメータを設定してください:
  +
  +
{{Tip|ホストネームとポートは {{ic|git clone http://hostname:port}} などとして使われます。}}
  +
  +
'''ホストネーム:''' {{ic|gitlab:}} セクションで {{ic|host:}} を設定 - {{ic|localhost}} を {{ic|yourdomain.com}} に置き換えます ('''ノート:''' 'http://' や末尾のスラッシュは付けません) - 完全修飾ドメイン名を使ってください。
  +
  +
'''ポート:''' {{ic|port:}} は紛らわしいかもしれません。gitlab サーバー (unicorn) が動作するポートではありません。ユーザーがブラウザを使って最初にアクセスするときのポートです。ブラウザから 'yourdomain.com' にアクセスするようにしたい場合、ドメイン名にポート番号は基本的に付けないので、{{ic|port:}} は {{ic|80}} のままにしておきます。ブラウザに 'yourdomain.com:3425' などと入力させるときのみ、{{ic|port:}} を {{ic|3425}} と設定します。また、ウェブサーバーの設定も変更して、設定したポートを使うようにしてください。
  +
  +
'''タイムゾーン (任意):''' {{ic|time_zone:}} パラメータは任意ですが、GitLab アプリケーションのゾーンを強制することができます。
  +
  +
最後に ''uploads'' ディレクトリに適切なパーミッションを設定:
  +
  +
# chmod 700 /var/lib/gitlab/uploads
  +
 
====GitLab Shell====
 
====GitLab Shell====
 
{{Note|同一のホスト上で GitLab をホストする場合 {{ic|gitlab_url}} はデフォルト値のままで問題ありません。}}
 
{{Note|同一のホスト上で GitLab をホストする場合 {{ic|gitlab_url}} はデフォルト値のままで問題ありません。}}
62行目: 78行目:
 
# to listen on a custom port, or if you have configured Unicorn to
 
# to listen on a custom port, or if you have configured Unicorn to
 
# only listen on a Unix domain socket.
 
# only listen on a Unix domain socket.
gitlab_url: "http://localhost:8080/" # <<-- right here
+
gitlab_url: "http://localhost:8080/"
   
 
http_settings:
 
http_settings:
70行目: 86行目:
 
}}
 
}}
   
ポートやホストネームがデフォルト値と違う場合は {{ic|/usr/share/webapps/gitlab/unicorn.rb}} の設定を更新してください:
+
ポートやホストネームがデフォルト値と違う場合は {{ic|/etc/webapps/gitlab/unicorn.rb}} の設定を更新してください:
 
{{hc|/etc/webapps/gitlab/unicorn.rb|2=
 
{{hc|/etc/webapps/gitlab/unicorn.rb|2=
listen "127.0.0.1:8080", :tcp_nopush => true # <<-- right here
+
listen "/run/gitlab/gitlab.socket", :backlog => 1024
  +
listen "'''127.0.0.1:8080'''", :tcp_nopush => true
 
}}
 
}}
   
====GitLab====
+
====Redis====
  +
デフォルトとは異なる構成で [[Redis]] を使用するときは (アドレスやポート、Unix ソケットなどが異なる場合)、''REDIS_URL'' 環境変数を正しく設定する必要があります。systemd サービスファイルを拡張することで設定できます。{{ic|/etc/systemd/system/gitlab-unicorn.service.d/redis.conf}} ファイルを作成して ''REDIS_URL'' 環境変数を挿入してください:
{{ic|/etc/webapps/gitlab/gitlab.yml}} を編集して以下のパラメータを設定してください:
 
  +
{{hc|/etc/systemd/system/gitlab-unicorn.service.d/redis.conf|<nowiki>
  +
[Service]
  +
Environment=REDIS_URL=unix:///run/gitlab/redis.sock</nowiki>}}
   
  +
=====Redis で Unix ソケットを使う=====
{{Tip|ホストネームとポートは {{ic|git clone http://hostname:port}} などとして使われます。}}
 
   
  +
[[Redis#ソケットを使う]]の手順にしたがって、デフォルト設定を調整してください [https://github.com/gitlabhq/gitlabhq/issues/6100]。
'''ホストネーム:''' {{ic|gitlab:}} セクションで {{ic|host:}} を設定 - {{ic|localhost}} を {{ic|yourdomain.com}} に置き換えます ('''ノート:''' 'http://' や末尾のスラッシュは付けません) - 完全修飾ドメイン名を使ってください。
 
   
  +
* {{ic|git}} と {{ic|gitlab}} ユーザーを {{ic|redis}} [[グループ]]に追加。
'''ポート:''' {{ic|port:}} は紛らわしいかもしれません。gitlab サーバー (unicorn) が動作するポートではありません。ユーザーがブラウザを使って最初にアクセスするときのポートです。ブラウザから 'yourdomain.com' にアクセスするようにしたい場合、ドメイン名にポート番号は基本的に付けないので、{{ic|port:}} は {{ic|80}} のままにしておきます。ブラウザに 'yourdomain.com:3425' などと入力させるときのみ、{{ic|port:}} を {{ic|3425}} と設定します。また、ウェブサーバーの設定も変更して、設定したポートを使うようにしてください。
 
   
  +
* 設定ファイルを更新:
'''タイムゾーン (任意):''' {{ic|time_zone:}} パラメータは任意ですが、GitLab アプリケーションのゾーンを強制することができます。
 
  +
{{hc|/etc/webapps/gitlab/resque.yml|2=
  +
development: unix:/var/run/redis/redis.sock
  +
test: unix:/run/redis/redis.sock
  +
production: unix:/run/redis/redis.sock
  +
}}
   
  +
{{hc|/etc/webapps/gitlab-shell/config.yml|2=
上記は GitLab を動作させるのに最小限必要な設定です。勇気がある人はコメントを読んで必要に応じて他の設定もカスタマイズしてください。
 
  +
# 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: /var/run/redis/redis.sock # '''uncomment''' this line
  +
namespace: resque:gitlab
  +
}}
   
 
=== 詳細設定 ===
 
=== 詳細設定 ===
106行目: 141行目:
   
 
$ mysql -u '''gitlab''' -p -D gitlabhq_production
 
$ mysql -u '''gitlab''' -p -D gitlabhq_production
  +
  +
MySQL テンプレートファイルをコピー:
  +
  +
# cp /usr/share/doc/gitlab/database.yml.mysql /etc/webapps/gitlab/database.yml
   
 
次に {{ic|/etc/webapps/gitlab/database.yml}} を開いて {{ic|gitlabhq_production}} の {{ic|username:}} と {{ic|password:}} を設定してください:
 
次に {{ic|/etc/webapps/gitlab/database.yml}} を開いて {{ic|gitlabhq_production}} の {{ic|username:}} と {{ic|password:}} を設定してください:
123行目: 162行目:
 
password: '''"password"'''
 
password: '''"password"'''
 
# host: localhost
 
# host: localhost
# socket: /run/mysqld/mysqld.sock # If running MariaDB as socket
+
# socket: /var/run/mysqld/mysqld.sock # If running MariaDB as socket
 
...
 
...
 
}}
 
}}
176行目: 215行目:
   
 
{{ic|/etc/webapps/gitlab/database.yml}} に記載されている他のデータベースの設定について心配する必要はありません。GitLab を使うにはプロダクションデータベースだけをセットアップすれば十分です。
 
{{ic|/etc/webapps/gitlab/database.yml}} に記載されている他のデータベースの設定について心配する必要はありません。GitLab を使うにはプロダクションデータベースだけをセットアップすれば十分です。
 
最後に、{{ic|/usr/lib/systemd/system/gitlab.target}} と {{ic|/usr/lib/systemd/system/gitlab-unicorn.service}} を開いて {{ic|mysql.service}} の記述を全て {{ic|postgresql.service}} に変えてください。
 
   
 
==== ファイアウォール ====
 
==== ファイアウォール ====
190行目: 227行目:
   
 
ルーターを使っている場合、WAN からアクセスできるようにしたいとき、GitLab サーバーを実行しているホストにポートを転送するようにしてください。
 
ルーターを使っている場合、WAN からアクセスできるようにしたいとき、GitLab サーバーを実行しているホストにポートを転送するようにしてください。
 
==== Satellites のアクセス権限 ====
 
 
{{ic|satellites}} フォルダには以下のパーミッションを設定してください:
 
 
# chmod 750 /var/lib/gitlab/satellites
 
   
 
==== Gitlab データベースの初期化 ====
 
==== Gitlab データベースの初期化 ====
   
データベースを作成する前に Redis サーバーを起動:
+
データベースを作成する前に [[Redis]] サーバーを起動してください。
   
  +
データベースを初期化して高度な機能を有効化:
# systemctl start redis
 
  +
# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake gitlab:setup RAILS_ENV=production"
# systemctl enable redis
 
   
以下のコマンドで bundler インストールして必要な gem インストールします:
+
最後に以下のコマンドを実行して環境チェック実行:
   
  +
# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake gitlab:env:info RAILS_ENV=production"
# export PATH=$PATH:/var/lib/gitlab/.gem/ruby/2.3.0/bin
 
  +
# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake gitlab:check RAILS_ENV=production"
# sudo -u gitlab -H gem install bundler --no-document
 
# cd /usr/share/webapps/gitlab
 
# sudo -u gitlab -H bundle install
 
   
  +
{{note|
{{Warning|GitLab は {{ic|bundle}} コマンドを必要とします。忘れずにインストールしてください。}}
 
  +
*''gitlab:env:info'' と ''gitlab:check'' コマンドは git に関するエラーを表示しますが問題ありません。
 
  +
*''gitlab:check'' が ''Check GitLab API access: FAILED. code: 401'' というエラーで失敗する場合、トラブルシューティングセクションの [[#API アクセス時に 401 Unauthorized]] や [[#/etc/webapps/gitlab/secret が空]]を参照して解決してください。
{{Note|'gitlab' ユーザーで bundle が存在しないというエラーが表示される場合、おそらく ruby が {{ic|/usr/lib}} などの読み込みできないディレクトリにインストールされていることが原因です。以下のコマンドで解決できます:
 
  +
*''gitlab:check'' は initscripts が存在しないとエラーを吐きます。[[systemd]] サービスファイルを使用するため問題ありません (GitLab から認識されないだけです)。
 
{{bc|<nowiki>
 
su - gitlab -s /bin/sh -c "export PATH=$PATH:/var/lib/gitlab/.gem/ruby/2.3.0/bin; gem install bundler --no-document"
 
su - gitlab -s /bin/sh -c "export PATH=$PATH:/var/lib/gitlab/.gem/ruby/2.3.0/bin; cd /usr/share/webapps/gitlab; bundle install"
 
su - gitlab -s /bin/sh -c "export PATH=$PATH:/var/lib/gitlab/.gem/ruby/2.3.0/bin; cd /usr/share/webapps/gitlab; bundle exec rake gitlab:setup RAILS_ENV=production"
 
su - gitlab -s /bin/sh -c "export PATH=$PATH:/var/lib/gitlab/.gem/ruby/2.3.0/bin; cd /usr/share/webapps/gitlab; bundle exec rake assets:precompile RAILS_ENV=production"
 
</nowiki>}}
 
 
}}
 
}}
 
データベースを初期化して高度な機能を有効化:
 
# cd /usr/share/webapps/gitlab
 
# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle exec rake gitlab:setup RAILS_ENV=production"
 
 
{{bc|<nowiki>
 
Missing `db_key_base` for 'production' environment. The secrets will be generated and stored in `config/secrets.yml`
 
This will create the necessary database tables and seed the database.
 
You will lose any previous data stored in the database.
 
Do you want to continue (yes/no)? yes
 
 
gitlabhq_production already exists
 
-- enable_extension("plpgsql")
 
-> 0.0009s
 
-- create_table("abuse_reports", {:force=>true})
 
-> 0.0300s
 
-- create_table("application_settings", {:force=>true})
 
-> 0.0116s
 
 
...
 
 
Administrator account created:
 
 
login.........root
 
password......5iveL!fe
 
</nowiki>}}
 
 
アセットをコンパイル:
 
 
# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle exec rake assets:precompile RAILS_ENV=production"
 
 
最後に、{{ic|/etc/webapps/gitlab/secret}} にランダムな16進数の文字列が書かれていることを確認してください。
 
   
 
==== Git ユーザーの設定 ====
 
==== Git ユーザーの設定 ====
{{Note|以下は {{ic|/usr/share/webapps/gitlab/config/gitlab.yml}} で定義した {{ic|user}} や {{ic|email_from}} と一致している必要があります。}}
 
   
 
# cd /usr/share/webapps/gitlab
 
# cd /usr/share/webapps/gitlab
264行目: 254行目:
   
 
==== 修飾ビットの調整 ====
 
==== 修飾ビットの調整 ====
  +
ユーザーとグループが正しく設定されていないと gitlab check が通過しません:
(The gitlab check won't pass if the user and group ownership isn't configured properly)
 
   
 
# chmod -R ug+rwX,o-rwx /var/lib/gitlab/repositories/
 
# chmod -R ug+rwX,o-rwx /var/lib/gitlab/repositories/
272行目: 262行目:
 
== GitLab の起動とテスト ==
 
== GitLab の起動とテスト ==
 
{{note|何か問題が発生する場合は [[#トラブルシューティング]] や {{ic|/usr/share/webapps/gitlab/log}} ディレクトリのログファイルを見てください。}}
 
{{note|何か問題が発生する場合は [[#トラブルシューティング]] や {{ic|/usr/share/webapps/gitlab/log}} ディレクトリのログファイルを見てください。}}
  +
[[MySQL]] または [[PostgreSQL]] と [[Redis]] が適切にセットアップ・実行されていることを確認してください。
systemd から新しいデーモンのユニットファイルを認識させる:
 
   
  +
データベースバックエンドの起動後、{{ic|gitlab-sidekiq}} と {{ic|gitlab-unicorn}} ユニットを両方とも[[起動]]することで GitLab を独自のウェブサーバー (Unicorn) で起動できます。
# systemctl daemon-reload
 
 
[[MySQL]] や [[PostgreSQL]] と Redis が正しく実行・設定されていることを確認してください。
 
 
GitLab が {{ic|redis}} を正しくロードできない場合など、必要であれば [[#Redis で Unix ソケットを使う]] を見てください。
 
 
データベースバックエンドを起動した後、GitLab とウェブサーバー (Unicorn) を起動します:
 
 
# systemctl start gitlab-sidekiq gitlab-unicorn
 
 
以下のコマンドを使うことで正しく設定がされているかどうか確認できます:
 
 
# cd /usr/share/webapps/gitlab
 
# sudo -u gitlab bundle exec rake gitlab:env:info RAILS_ENV=production
 
# sudo -u gitlab bundle exec rake gitlab:check RAILS_ENV=production
 
 
{{note|gitlab:env:info と gitlab:check コマンドは git に関する致命的なエラーを出力しますが、それで問題ありません。}}
 
 
{{hc|<nowiki>$ sudo -u gitlab bundle exec rake gitlab:env:info RAILS_ENV=production</nowiki>|<nowiki>
 
fatal: Not a git repository (or any of the parent directories): .git
 
 
System information
 
System: Arch rolling
 
Current User: gitlab
 
Using RVM: no
 
Ruby Version: 2.2.3p173
 
Gem Version: 2.4.5.1
 
Bundler Version:1.10.6
 
Rake Version: 10.4.2
 
Sidekiq Version:3.3.0
 
 
GitLab information
 
Version: 7.14.0
 
Revision: fatal: Not a git repository (or any of the parent directories): .git
 
Directory: /usr/share/webapps/gitlab
 
DB Adapter: mysql2
 
URL: http://gitlab.arch
 
HTTP Clone URL: http://gitlab.arch/some-project.git
 
SSH Clone URL: git@gitlab.arch:some-project.git
 
Using LDAP: no
 
Using Omniauth: no
 
 
GitLab Shell
 
Version: 2.6.4
 
Repositories: /var/lib/gitlab/repositories/
 
Hooks: /usr/share/webapps/gitlab-shell/hooks/
 
Git: /usr/bin/git
 
</nowiki>}}
 
 
{{Note| {{ic|gitlab:check}} は initscripts が存在しないというエラーを吐きます。問題はありません。代わりに [[systemd]] のサービスファイルが使われます (GitLab は systemd を認識しません)。}}
 
 
{{hc|<nowiki>$ sudo -u gitlab bundle exec rake gitlab:check RAILS_ENV=production</nowiki>|<nowiki>
 
fatal: Not a git repository (or any of the parent directories): .git
 
Checking Environment ...
 
 
Git configured for gitlab user? ... yes
 
Has python2? ... yes
 
python2 is supported version? ... yes
 
 
Checking Environment ... Finished
 
 
Checking GitLab Shell ...
 
 
GitLab Shell version >= 1.7.9 ? ... OK (1.8.0)
 
Repo base directory exists? ... yes
 
Repo base directory is a symlink? ... no
 
Repo base owned by gitlab:gitlab? ... yes
 
Repo base access is drwxrws---? ... yes
 
update hook up-to-date? ... yes
 
update hooks in repos are links: ... can't check, you have no projects
 
Running /srv/gitlab/gitlab-shell/bin/check
 
Check GitLab API access: OK
 
Check directories and files:
 
/srv/gitlab/repositories: OK
 
/srv/gitlab/.ssh/authorized_keys: OK
 
Test redis-cli executable: redis-cli 2.8.4
 
Send ping to redis server: PONG
 
gitlab-shell self-check successful
 
 
Checking GitLab Shell ... Finished
 
 
Checking Sidekiq ...
 
 
Running? ... yes
 
Number of Sidekiq processes ... 1
 
 
Checking Sidekiq ... Finished
 
 
Checking LDAP ...
 
 
LDAP is disabled in config/gitlab.yml
 
 
Checking LDAP ... Finished
 
 
Checking GitLab ...
 
 
Database config exists? ... yes
 
Database is SQLite ... no
 
All migrations up? ... fatal: Not a git repository (or any of the parent directories): .git
 
yes
 
GitLab config exists? ... yes
 
GitLab config outdated? ... no
 
Log directory writable? ... yes
 
Tmp directory writable? ... yes
 
Init script exists? ... no
 
Try fixing it:
 
Install the init script
 
For more information see:
 
doc/install/installation.md in section "Install Init Script"
 
Please fix the error above and rerun the checks.
 
Init script up-to-date? ... can't check because of previous errors
 
projects have namespace: ... can't check, you have no projects
 
Projects have satellites? ... can't check, you have no projects
 
Redis version >= 2.0.0? ... yes
 
Your git bin path is "/usr/bin/git"
 
Git version >= 1.7.10 ? ... yes (1.8.5)
 
 
Checking GitLab ... Finished
 
</nowiki>}}
 
   
 
システムの起動時に GitLab を自動的に実行したいときは {{ic|gitlab.target}}, {{ic|gitlab-sidekiq}}, {{ic|gitlab-unicorn}} サービスを有効化してください。
 
システムの起動時に GitLab を自動的に実行したいときは {{ic|gitlab.target}}, {{ic|gitlab-sidekiq}}, {{ic|gitlab-unicorn}} サービスを有効化してください。
   
そして http://localhost:8080 や http://yourdomain.com をブラウザで開いてデフォルトのユーザー情報を使ってログインすることで GitLab インスタンスをテストしてください:
+
そして http://localhost:8080 や http://yourdomain.com をブラウザで開いて GitLab インスタンスをテストしてください。パスワードの作成が要求されます:
   
 
{{bc|
 
{{bc|
 
username: root
 
username: root
  +
password: You'll be prompted to create one on your first visit.
password: 5iveL!fe
 
 
}}
 
}}
   
  +
== アップデート時のデータベースアップグレード ==
{{note|1=gitlab を動作させるマシンとブラウザを使用するマシンが異なる場合、プロキシを使わなくてもセットアップがテストできるように unicorn.rb を修正してください。以下の行を:
 
  +
{{Pkg|gitlab}} パッケージをアップデートした後、データベースをアップグレードする必要があります:
<pre>listen "127.0.0.1:8080, :tcp_nopush => true</pre>
 
  +
# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle-2.3 exec rake db:migrate RAILS_ENV=production"
以下のように置き換えてください:
 
  +
<pre>listen "example.yourhost.com:8080, :tcp_nopush => true</pre>
 
  +
アップグレード後、gitlab 関連のサービスを再起動してください:
}}
 
  +
# systemctl daemon-reload
  +
# systemctl restart gitlab-sidekiq gitlab-unicorn gitlab-workhorse
   
 
== 高度な設定 ==
 
== 高度な設定 ==
429行目: 303行目:
 
==== Let's Encrypt ====
 
==== Let's Encrypt ====
   
URL を検証する際、Let's Encrypt は {{ic|<nowiki>https://gitlab.</nowiki>''YOUR_SERVER_FQDN''/.well-known/''A_LONG_ID''}} のように gitlab サーバーにアクセスできるかどうか試行します。しかしながら、gitlab の設定によって、{{ic|gitlab.''YOUR_SERVER_FQDN''}} へのリクエストはプロキシ (gitlab-workhorse) に全て転送されるため、URL の確認が失敗します。
+
URL を検証する際、Let's Encrypt は {{ic|<nowiki>https://gitlab.</nowiki>''YOUR_SERVER_FQDN''/.well-known/acme-challenge/''A_LONG_ID''}} のように gitlab サーバーにアクセスできるかどうか試行します。しかしながら、gitlab の設定によって、{{ic|gitlab.''YOUR_SERVER_FQDN''}} へのリクエストはプロキシ (gitlab-workhorse) に全て転送されるため、URL の確認が失敗します。
   
 
Let's Encrypt の webroot を使用することでこの問題を回避することが可能です。webroot を {{ic|/srv/http/letsencrypt/}} に設定してください。
 
Let's Encrypt の webroot を使用することでこの問題を回避することが可能です。webroot を {{ic|/srv/http/letsencrypt/}} に設定してください。
448行目: 322行目:
 
====Nginx と unicorn====
 
====Nginx と unicorn====
   
  +
{{ic|/usr/share/doc/gitlab/nginx.conf.example}} または {{ic|/usr/share/doc/gitlab/nginx-ssl.conf.example}} を {{ic|/etc/nginx/servers-available/gitlab}} にコピーしてください。詳しくは [[Nginx#サーバーブロック]]を参照。
=====AUR インストール=====
 
  +
[[Nginx]] をセットアップして、以下のディレクトリを作成してください (存在しない場合):
 
  +
{{ic|/etc/nginx/servers-available/gitlab}} ファイルをアップデートして nginx のサービスを[[再起動]]してください。
   
# mkdir /etc/nginx/servers-available
+
認証できない場合、{{ic|/etc/nginx/servers-available/gitlab}} に以下のヘッダーを追加してください:
  +
proxy_set_header X-Forwarded-Ssl on; # Only when using SSL
# mkdir /etc/nginx/servers-enabled
 
  +
proxy_set_header X-Frame-Options SAMEORIGIN;
  +
  +
===== 別の設定例 =====
   
 
{{Note|{{ic|localhost:8080}} を gitlab のアドレスに {{ic|example.com}} をサーバーの名前に置き換える必要があります。}}
 
{{Note|{{ic|localhost:8080}} を gitlab のアドレスに {{ic|example.com}} をサーバーの名前に置き換える必要があります。}}
462行目: 340行目:
 
# Contributor: francoism90
 
# Contributor: francoism90
 
# Source: https://gist.github.com/sameersbn/becd1c976c3dc4866ef8
 
# Source: https://gist.github.com/sameersbn/becd1c976c3dc4866ef8
upstream gitlab {
+
upstream gitlab-workhorse {
server localhost:8080 fail_timeout=0;
+
server unix:/run/gitlab/gitlab-workhorse.socket fail_timeout=0;
 
}
 
}
   
493行目: 371行目:
 
proxy_set_header X-Frame-Options SAMEORIGIN;
 
proxy_set_header X-Frame-Options SAMEORIGIN;
 
 
proxy_pass http://localhost:8080;
+
proxy_pass http://gitlab-workhorse;
 
}
 
}
 
}
 
}
 
}}
 
}}
 
{{ic|/etc/nginx/nginx.conf}} の {{ic|http}} ブロックの末尾に以下の行があることを確認してください:
 
 
include servers-enabled/*;
 
 
{{ic|github}} の設定を有効化:
 
 
# ln -s /etc/nginx/servers-available/gitlab /etc/nginx/servers-enabled/gitlab
 
 
新しい設定を確認:
 
 
# nginx -t
 
 
最後に {{ic|gitlab.target}}, {{ic|resque.target}}, {{ic|nginx.service}} を再起動してください。
 
 
=====手動インストール=====
 
AUR を使わなかった場合、{{ic|/usr/lib/support/nginx/gitlab}} を {{ic|/etc/nginx/sites-available/}} にコピーする必要があります。
 
 
次のコマンドを実行して nginx を設定してください:
 
 
# ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
 
 
{{ic|/etc/nginx/sites-enabled/gitlab}} を編集して YOUR_SERVER_IP と YOUR_SERVER_FQDN を Gitlab をホストするサーバーの IP アドレスと完全修飾ドメイン名に置き換えてください。
 
 
{{ic|/etc/nginx/nginx.conf}} の {{ic|http}} ブロックの末尾に以下の行があることを確認してください:
 
 
include sites-enabled/*;
 
 
{{ic|github}} の設定を有効化:
 
 
# ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
 
 
新しい設定を確認:
 
 
# nginx -t
 
 
最後に {{ic|gitlab.target}}, {{ic|resque.target}}, {{ic|nginx.service}} を再起動してください。
 
   
 
====Apache と unicorn====
 
====Apache と unicorn====
562行目: 403行目:
 
Apache の {{ic|gitlab.conf}} ファイルをコピー:
 
Apache の {{ic|gitlab.conf}} ファイルをコピー:
   
# cp /etc/webapps/gitlab/apache.conf.example /etc/httpd/conf/extra/gitlab.conf
+
# cp /usr/share/doc/gitlab/apache.conf.example /etc/httpd/conf/extra/gitlab.conf
   
 
最後に {{ic|gitlab-unicorn.service}} を[[起動]]してください。
 
最後に {{ic|gitlab-unicorn.service}} を[[起動]]してください。
   
=== Redis ===
+
=== Gitlab-workhorse ===
デフォルトとは異なる構成で Redis を使用するときは (アドレスやポート、Unix ソケットなどが異なる場合)、''REDIS_URL'' 環境変数を正しく設定する必要があります。systemd サービスファイルを拡張することで設定できます。{{ic|/etc/systemd/system/gitlab-unicorn.service.d/redis.conf}} ファイルを作成して ''REDIS_URL'' 環境変数を挿入してください:
 
[Service]
 
Environment=REDIS_URL=unix:///run/gitlab/redis.sock
 
   
  +
8.0 から GitLab は Git の push/pull などの巨大な HTTP リクエスト用に特別な HTTP サーバー {{Pkg|gitlab-workhorse}} を使用しています。SSH の代わりに workhorse を使いたい場合、{{ic|gitlab-workhorse.service}} を有効化してウェブサーバーを設定してください。GitLab チームによれば {{ic|gitlab-unicorn}} よりも {{Pkg|gitlab-workhorse}} を使用することが推奨されています: https://gitlab.com/gitlab-org/gitlab-ce/issues/22528#note_16036216 。
==== Redis で Unix ソケットを使う ====
 
   
  +
{{Note|Unicorn が不要になるわけではないので {{ic|gitlab-unicorn.service}} を無効化・停止してはいけません。Unicorn が使用するポートを変更している場合、{{ic|gitlab-workhorse.service}} の {{ic|-authBackend}} 設定を適宜変更してください。}}
ソケットを listen するように Redis を設定している場合、デフォルト設定を修正するべきです:
 
   
  +
デフォルトでは {{Pkg|gitlab-workhorse}} は {{ic|/run/gitlab/gitlab-workhorse.socket}} を listen します。{{ic|gitlab-workhorse.service}} を編集して {{ic|-listenAddr}} パラメータを変更することで指定したアドレスを listen するようになります (例: {{ic|-listenAddr 127.0.0.1:8181}})。アドレスを listen する場合、ネットワークタイプを {{ic|-listenNetwork tcp}} に設定する必要があります。
{{hc|/etc/redis.conf|2=
 
...
 
# Accept connections on the specified port, default is 6379.
 
# If port 0 is specified Redis will not listen on a TCP socket.
 
port 0
 
...
 
# By default Redis listens for connections from all the network interfaces
 
# available on the server. It is possible to listen to just one or multiple
 
# interfaces using the "bind" configuration directive, followed by one or
 
# more IP addresses.
 
#
 
# Examples:
 
#
 
# bind 192.168.1.100 10.0.0.1
 
bind 127.0.0.1
 
   
  +
nginx を使用している場合、nginx の設定ファイルも忘れずに編集してください。gitlab-unicorn から gitlab-workhorse に切り替えるには以下の設定を編集します:
# Specify the path for the Unix socket that will be used to listen for
 
  +
{{hc|/etc/nginx/servers-available/gitlab|2=
# incoming connections. There is no default, so Redis will not listen
 
  +
upstream gitlab {
# on a unix socket when not specified.
 
  +
server unix:/run/gitlab/gitlab-workhorse.socket fail_timeout=0;
#
 
  +
}
unixsocket /var/run/redis/redis.sock
 
unixsocketperm 770
 
}}
 
   
{{ic|/var/run/redis}} ディレクトリを作成して適切なパーミッションを設定:
 
# mkdir /var/run/redis
 
# chown redis:redis /var/run/redis
 
# chmod 755 /var/run/redis
 
 
{{ic|git}} と {{ic|gitlab}} ユーザーを {{ic|redis}} グループに追加:
 
 
# usermod -a -G redis git
 
# usermod -a -G redis gitlab
 
 
{{ic|/etc/webapps/gitlab-shell/config.yml}} と {{ic|/etc/webapps/gitlab/resque.yml}} ファイルを修正:
 
 
{{hc|/etc/webapps/gitlab/resque.yml|2=
 
development: unix:/var/run/redis/redis.sock
 
test: unix:/run/redis/redis.sock
 
production: unix:/run/redis/redis.sock
 
}}
 
 
{{hc|/etc/webapps/gitlab-shell/config.yml|2=
 
...
 
# 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: /var/run/redis/redis.sock # uncomment this line
 
namespace: resque:gitlab
 
 
...
 
...
  +
  +
proxy_pass http://unix:/run/gitlab/gitlab-workhorse.socket;
  +
}
  +
}
 
}}
 
}}
 
最後に {{ic|redis}}, {{ic|gitlab-sidekiq}}, {{ic|gitlab-unicorn}} サービスを再起動してください。
 
 
詳しくは issue [https://github.com/gitlabhq/gitlabhq/issues/6100 #6100] を見てください。
 
 
=== Gitlab-workhorse ===
 
 
8.0 から GitLab は Git の push や pull などの巨大な HTTP リクエストで特別な HTTP サーバー {{ic|gitlab-workhorse}} を使用します。SSH の代わりに workhorse を使いたい場合、{{AUR|gitlab-workhorse}} パッケージをインストールして、{{ic|gitlab-workhorse.service}} を有効化し、ウェブサーバーを設定してください。
 
   
 
==便利なヒント==
 
==便利なヒント==
711行目: 500行目:
 
データを保存:
 
データを保存:
 
# cd /home/gitlab/gitlab
 
# cd /home/gitlab/gitlab
# sudo -u gitlab bundle exec rake db:data:dump RAILS_ENV=production
+
# sudo -u gitlab bundle-2.3 exec rake db:data:dump RAILS_ENV=production
   
 
[[#Mysql]] の手順に従ってデータベースをセットアップ:
 
[[#Mysql]] の手順に従ってデータベースをセットアップ:
# sudo -u gitlab bundle exec rake db:setup RAILS_ENV=production
+
# sudo -u gitlab bundle-2.3 exec rake db:setup RAILS_ENV=production
   
 
最後にデータをリストア:
 
最後にデータをリストア:
# sudo -u gitlab bundle exec rake db:data:load RAILS_ENV=production
+
# sudo -u gitlab bundle-2.3 exec rake db:data:load RAILS_ENV=production
   
 
===rvm で GitLab を実行===
 
===rvm で GitLab を実行===
723行目: 512行目:
 
rvm で gitlab を実行するにはまず rvm をセットアップしてください:
 
rvm で gitlab を実行するにはまず rvm をセットアップしてください:
   
curl -L https://get.rvm.io | bash -s stable --ruby=1.9.3
+
curl -L https://get.rvm.io | bash -s stable --ruby=1.9.3
   
 
{{Note|互換問題を避けるためにバージョン 1.9.3 を使用することが現在推奨されています。}}
 
{{Note|互換問題を避けるためにバージョン 1.9.3 を使用することが現在推奨されています。}}
729行目: 518行目:
 
For the complete installation you will want to be the final user (e.g. {{ic|git}}) so make sure to switch to this user and activate your rvm:
 
For the complete installation you will want to be the final user (e.g. {{ic|git}}) so make sure to switch to this user and activate your rvm:
   
su - git
+
su - git
source "$HOME/.rvm/scripts/rvm"
+
source "$HOME/.rvm/scripts/rvm"
   
 
Then continue with the installation instructions from above. However, the systemd scripts will not work this way, because the environment for the rvm is not activated. The recommendation here is to create to separate shell scripts for {{ic|unicorn}} and {{ic|sidekiq}} to activate the environment and then start the service:
 
Then continue with the installation instructions from above. However, the systemd scripts will not work this way, because the environment for the rvm is not activated. The recommendation here is to create to separate shell scripts for {{ic|unicorn}} and {{ic|sidekiq}} to activate the environment and then start the service:
737行目: 526行目:
 
#!/bin/sh
 
#!/bin/sh
 
source `/home/git/.rvm/bin/rvm 1.9.3 do rvm env --path`
 
source `/home/git/.rvm/bin/rvm 1.9.3 do rvm env --path`
bundle exec "unicorn_rails -c /usr/share/webapps/gitlab/config/unicorn.rb -E production"</nowiki>
+
bundle-2.3 exec "unicorn_rails -c /usr/share/webapps/gitlab/config/unicorn.rb -E production"</nowiki>
 
}}
 
}}
   
745行目: 534行目:
 
case $1 in
 
case $1 in
 
start)
 
start)
bundle exec rake sidekiq:start RAILS_ENV=production
+
bundle-2.3 exec rake sidekiq:start RAILS_ENV=production
 
;;
 
;;
 
stop)
 
stop)
bundle exec rake sidekiq:stop RAILS_ENV=production
+
bundle-2.3 exec rake sidekiq:stop RAILS_ENV=production
 
;;
 
;;
 
*)
 
*)
796行目: 585行目:
   
 
cd /usr/share/webapps/gitlab
 
cd /usr/share/webapps/gitlab
RAILS_ENV=production bundle exec rake cache:clear
+
RAILS_ENV=production bundle-2.3 exec rake cache:clear
  +
  +
=== API アクセス時に 401 Unauthorized ===
  +
{{ic|/etc/webapps/gitlab/secret}} と {{ic|/etc/webapps/gitlab-shell/secret}} のファイルに中身があるか確認してください。
   
 
=== push 時に bad line length character: API というエラーが発生する ===
 
=== push 時に bad line length character: API というエラーが発生する ===
814行目: 606行目:
   
 
全ての gitlab ページが500エラーを返す場合、データベースの移行やアセットが古くなっている可能性があります。そうでない場合、以下のコマンドはスキップしてください。
 
全ての gitlab ページが500エラーを返す場合、データベースの移行やアセットが古くなっている可能性があります。そうでない場合、以下のコマンドはスキップしてください。
# sudo -u gitlab -H bundle exec rake db:migrate RAILS_ENV=production
+
# sudo -u gitlab -H bundle-2.3 exec rake db:migrate RAILS_ENV=production
   
 
gitlab のデプロイが永遠に完了しない場合、アセットが再コンパイルされていない可能性があります:
 
gitlab のデプロイが永遠に完了しない場合、アセットが再コンパイルされていない可能性があります:
# sudo -u gitlab -H bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production
+
# sudo -u gitlab -H bundle-2.3 exec rake gitlab:assets:clean gitlab:assets:compile cache:clear RAILS_ENV=production
   
 
最後に、gitlab サービスを再起動してサイトをテストしてください:
 
最後に、gitlab サービスを再起動してサイトをテストしてください:

2017年4月9日 (日) 15:03時点における版

関連記事

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:/var/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: /var/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: /var/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

高度な設定

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 を使用することが現在推奨されています。

For the complete installation you will want to be the final user (e.g. git) so make sure to switch to this user and activate your rvm:

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

Then continue with the installation instructions from above. However, the systemd scripts will not work this way, because the environment for the rvm is not activated. The recommendation here is to create to separate shell scripts for unicorn and sidekiq to activate the environment and then start the service:

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

Then modify the above systemd files so they use these scripts. Modify the given lines:

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 will reject mails received this way (and send you a mail that it did). You will need to disable secure authentication (follow the link in the rejection mail) to work around this. The more secure approach is to enable two-factor authentication for username@gmail.com and to set up an application password for this configuration file.

トラブルシューティング

ときどき 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エラーを返す場合、データベースの移行やアセットが古くなっている可能性があります。そうでない場合、以下のコマンドはスキップしてください。

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

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

# sudo -u gitlab -H 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

参照