「GitLab」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(同期)
(同期)
19行目: 19行目:
 
GitLab はデータベースバックエンドを必要します。同一のマシン上でデータベースを実行する場合、先に [[MySQL]] か [[PostgreSQL]] をインストールしてください。
 
GitLab はデータベースバックエンドを必要します。同一のマシン上でデータベースを実行する場合、先に [[MySQL]] か [[PostgreSQL]] をインストールしてください。
   
{{AUR|gitlab}} パッケージを[[インストール]]してください。
+
{{Pkg|gitlab}} パッケージを[[インストール]]してください。
   
 
メール通知を受け取るには、メールサーバーをインストール・設定する必要があります。詳しくは次のカテゴリを参照: [[:カテゴリ:メールサーバー]]。
 
メール通知を受け取るには、メールサーバーをインストール・設定する必要があります。詳しくは次のカテゴリを参照: [[:カテゴリ:メールサーバー]]。
26行目: 26行目:
   
 
=== 設定ファイル ===
 
=== 設定ファイル ===
{{AUR|gitlab}} パッケージは GitLab のファイルを Linux の標準的な慣習にそって以下のようにインストールします:
+
{{Pkg|gitlab}} パッケージは GitLab のファイルを Linux の標準的な慣習にそって以下のようにインストールします:
   
 
{| class="wikitable"
 
{| class="wikitable"
 
! 説明
 
! 説明
 
! [https://github.com/gitlabhq/gitlabhq/blob/6-5-stable/doc/install/installation.md GitLab 公式]
 
! [https://github.com/gitlabhq/gitlabhq/blob/6-5-stable/doc/install/installation.md GitLab 公式]
! {{AUR|gitlab}}
+
! {{Pkg|gitlab}}
 
|----------------------------------------------------------
 
|----------------------------------------------------------
 
| GitShell の設定ファイル
 
| GitShell の設定ファイル
70行目: 70行目:
 
}}
 
}}
   
ポートやホストネームがデフォルト値と違う場合は {{ic|/usr/share/webapps/gitlab/config/unicorn.rb}} の設定を更新してください:
+
ポートやホストネームがデフォルト値と違う場合は {{ic|/usr/share/webapps/gitlab/unicorn.rb}} の設定を更新してください:
{{hc|/etc/webapps/gitlab/config/unicorn.rb|2=
+
{{hc|/etc/webapps/gitlab/unicorn.rb|2=
 
listen "127.0.0.1:8080", :tcp_nopush => true # <<-- right here
 
listen "127.0.0.1:8080", :tcp_nopush => true # <<-- right here
 
}}
 
}}
78行目: 78行目:
 
{{ic|/etc/webapps/gitlab/gitlab.yml}} を編集して以下のパラメータを設定してください:
 
{{ic|/etc/webapps/gitlab/gitlab.yml}} を編集して以下のパラメータを設定してください:
   
{{Tip|The hostname and port are used for the {{ic|git clone http://hostname:port}} as example.}}
+
{{Tip|ホストネームとポートは {{ic|git clone http://hostname:port}} などとして使われます。}}
   
 
'''ホストネーム:''' {{ic|gitlab:}} セクションで {{ic|host:}} を設定 - {{ic|localhost}} を {{ic|yourdomain.com}} に置き換えます ('''ノート:''' 'http://' や末尾のスラッシュは付けません) - 完全修飾ドメイン名を使ってください。
 
'''ホストネーム:''' {{ic|gitlab:}} セクションで {{ic|host:}} を設定 - {{ic|localhost}} を {{ic|yourdomain.com}} に置き換えます ('''ノート:''' 'http://' や末尾のスラッシュは付けません) - 完全修飾ドメイン名を使ってください。
141行目: 141行目:
 
{{bc|1=
 
{{bc|1=
 
template1=# CREATE USER your_username_here WITH PASSWORD 'your_password_here';
 
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=# CREATE DATABASE gitlabhq_production OWNER your_username_here;
 
template1=# \q
 
template1=# \q
 
}}
 
}}
  +
  +
{{Note|ユーザーをスーパーユーザーとして作成することで GitLab は「スマート」になり拡張をインストールします。[[PostgreSQL]] ではスーパーユーザーだけが拡張のインストールを許可されています。}}
   
 
新しいユーザーで新しいデータベースに接続してデータベースが使えることを確認:
 
新しいユーザーで新しいデータベースに接続してデータベースが使えることを確認:
209行目: 212行目:
   
 
{{Warning|GitLab は {{ic|bundle}} コマンドを必要とします。忘れずにインストールしてください。}}
 
{{Warning|GitLab は {{ic|bundle}} コマンドを必要とします。忘れずにインストールしてください。}}
  +
  +
{{Note|'gitlab' ユーザーで bundle が存在しないというエラーが表示される場合、おそらく ruby が {{ic|/usr/lib}} などの読み込みできないディレクトリにインストールされていることが原因です。以下のコマンドで解決できます:
  +
  +
{{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>}}
  +
}}
   
 
データベースを初期化して高度な機能を有効化:
 
データベースを初期化して高度な機能を有効化:
243行目: 256行目:
   
 
==== Git ユーザーの設定 ====
 
==== Git ユーザーの設定 ====
  +
{{Note|以下は {{ic|/usr/share/webapps/gitlab/config/gitlab.yml}} で定義した {{ic|user}} や {{ic|email_from}} と一致している必要があります。}}
{{Note|This must match the {{ic|user}} and {{ic|email_from}} defined in {{ic|/usr/share/webapps/gitlab/config/gitlab.yml}}.}}
 
   
 
# cd /usr/share/webapps/gitlab
 
# cd /usr/share/webapps/gitlab
277行目: 290行目:
 
# sudo -u gitlab bundle exec rake gitlab:check RAILS_ENV=production
 
# sudo -u gitlab bundle exec rake gitlab:check RAILS_ENV=production
   
{{note|These gitlab:env:info and gitlab:check commands will show a fatal error related to git. This is OK.}}
+
{{note|gitlab:env:info gitlab:check コマンドは git に関する致命的なエラーを出力しますが、それで問題ありません。}}
   
 
{{hc|<nowiki>$ sudo -u gitlab bundle exec rake gitlab:env:info RAILS_ENV=production</nowiki>|<nowiki>
 
{{hc|<nowiki>$ sudo -u gitlab bundle exec rake gitlab:env:info RAILS_ENV=production</nowiki>|<nowiki>
310行目: 323行目:
 
</nowiki>}}
 
</nowiki>}}
   
{{Note| {{ic|gitlab:check}} will complain about missing initscripts. This is nothing to worry about, as [[systemd]] service files are used instead (which GitLab does not recognize).}}
+
{{Note| {{ic|gitlab:check}} initscripts が存在しないというエラーを吐きます。問題はありません。代わりに [[systemd]] のサービスファイルが使われます (GitLab systemd を認識しません)}}
   
 
{{hc|<nowiki>$ sudo -u gitlab bundle exec rake gitlab:check RAILS_ENV=production</nowiki>|<nowiki>
 
{{hc|<nowiki>$ sudo -u gitlab bundle exec rake gitlab:check RAILS_ENV=production</nowiki>|<nowiki>
390行目: 403行目:
 
}}
 
}}
   
  +
{{note|1=gitlab を動作させるマシンとブラウザを使用するマシンが異なる場合、プロキシを使わなくてもセットアップがテストできるように unicorn.rb を修正してください。以下の行を:
{{note|1=If your browser runs not on the machine where gitlab is running, modify your unicorn.rb in order to be able to test your setup without the use of a proxy. The corresponding line looks like this:
 
 
<pre>listen "127.0.0.1:8080, :tcp_nopush => true</pre>
 
<pre>listen "127.0.0.1:8080, :tcp_nopush => true</pre>
  +
以下のように置き換えてください:
you should replace that with:
 
 
<pre>listen "example.yourhost.com:8080, :tcp_nopush => true</pre>
 
<pre>listen "example.yourhost.com:8080, :tcp_nopush => true</pre>
 
}}
 
}}
413行目: 426行目:
 
==== GitLab 設定の変更 ====
 
==== GitLab 設定の変更 ====
 
{{ic|/etc/webapps/gitlab/shell.yml}} を修正して GitLab サイトを {{ic|https://}} から始まる URL に変えてください。{{ic|/etc/webapps/gitlab/gitlab.yml}} を修正して {{ic|https:}} を {{ic|true}} に設定してください。
 
{{ic|/etc/webapps/gitlab/shell.yml}} を修正して GitLab サイトを {{ic|https://}} から始まる URL に変えてください。{{ic|/etc/webapps/gitlab/gitlab.yml}} を修正して {{ic|https:}} を {{ic|true}} に設定してください。
  +
  +
==== 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 の確認が失敗します。
  +
  +
Let's Encrypt の webroot を使用することでこの問題を回避することが可能です。webroot を {{ic|/srv/http/letsencrypt/}} に設定してください。
  +
  +
さらに、Let's Encrypt の gitlab へのリクエストが全て webroot に転送されるように、以下の記述を追加します:
  +
  +
{{hc|/etc/http/conf/extra/gitlab.conf|
  +
Alias "/.well-known" "/srv/http/letsencrypt/.well-known"
  +
RewriteCond %{REQUEST_URI} !/\.well-known/.*
  +
}}
   
 
===ウェブサーバーの設定===
 
===ウェブサーバーの設定===
764行目: 790行目:
 
==トラブルシューティング==
 
==トラブルシューティング==
   
Sometimes things may not work as expected. Be sure to visit the [https://github.com/gitlabhq/gitlab-public-wiki/wiki/Trouble-Shooting-Guide Trouble Shooting Guide].
+
ときどき GitLab が上手く動作しないことがあります。[https://github.com/gitlabhq/gitlab-public-wiki/wiki/Trouble-Shooting-Guide Trouble Shooting Guide] を確認してください。
   
 
=== HTTPS が緑じゃない (gravatar が https を使わない) ===
 
=== HTTPS が緑じゃない (gravatar が https を使わない) ===
  +
Redis は gravatar の画像をキャッシュするため、http で GitLab にアクセスした後に https を有効にすると、gravatar がセキュアでない画像をロードしてしまいます。gitlab ユーザーで以下を実行することでキャッシュの消去が可能です:
Redis caches gravatar images, so if you have visited your GitLab with http, then enabled https, gravatar will load up the non-secure images. You can clear the cache by doing
 
   
 
cd /usr/share/webapps/gitlab
 
cd /usr/share/webapps/gitlab
 
RAILS_ENV=production bundle exec rake cache:clear
 
RAILS_ENV=production bundle exec rake cache:clear
 
as the gitlab user.
 
   
 
=== push 時に bad line length character: API というエラーが発生する ===
 
=== push 時に bad line length character: API というエラーが発生する ===
789行目: 813行目:
 
# cd /usr/share/webapps/gitlab
 
# cd /usr/share/webapps/gitlab
   
  +
全ての gitlab ページが500エラーを返す場合、データベースの移行やアセットが古くなっている可能性があります。そうでない場合、以下のコマンドはスキップしてください。
If every gitlab page gives a 500 error, then the database migrations and the assets are probably stale. If not, skip this step.
 
 
# sudo -u gitlab -H bundle exec rake db:migrate RAILS_ENV=production
 
# sudo -u gitlab -H bundle exec rake db:migrate RAILS_ENV=production
   
  +
gitlab のデプロイが永遠に完了しない場合、アセットが再コンパイルされていない可能性があります:
If gitlab is constantly waiting for the deployment to finish, then the assets have probably not been recompiled.
 
 
# sudo -u gitlab -H bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production
 
# sudo -u gitlab -H bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production
   
  +
最後に、gitlab サービスを再起動してサイトをテストしてください:
Finally, restart the gitlab services and test your site.
 
 
# systemctl restart gitlab-unicorn gitlab-sidekiq gitlab-workhorse
 
# systemctl restart gitlab-unicorn gitlab-sidekiq gitlab-workhorse
   
 
=== /etc/webapps/gitlab/secret が空 ===
 
=== /etc/webapps/gitlab/secret が空 ===
通常は {{AUR|gitlab-shell}} と {{AUR|gitlab}} パッケージのインストール時に生成されますが、生成されなかった場合、手動で生成する必要があります:
+
通常は {{Pkg|gitlab-shell}} と {{Pkg|gitlab}} パッケージのインストール時に生成されますが、生成されなかった場合、手動で生成する必要があります:
 
# hexdump -v -n 64 -e '1/1 "%02x"' /dev/urandom > /etc/webapps/gitlab-shell/secret
 
# hexdump -v -n 64 -e '1/1 "%02x"' /dev/urandom > /etc/webapps/gitlab-shell/secret
 
# chown root:gitlab /etc/webapps/gitlab-shell/secret
 
# chown root:gitlab /etc/webapps/gitlab-shell/secret

2016年5月7日 (土) 21:25時点における版

関連記事

GitLab のホームページ より:

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

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

インストール

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

GitLab はデータベースバックエンドを必要します。同一のマシン上でデータベースを実行する場合、先に 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 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/" # <<-- right here

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

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

/etc/webapps/gitlab/unicorn.rb
listen "127.0.0.1:8080", :tcp_nopush => true # <<-- right here

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 アプリケーションのゾーンを強制することができます。

上記は 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

次に /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 を使うにはプロダクションデータベースだけをセットアップすれば十分です。

最後に、/usr/lib/systemd/system/gitlab.target/usr/lib/systemd/system/gitlab-unicorn.service を開いて mysql.service の記述を全て postgresql.service に変えてください。

ファイアウォール

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 サーバーを実行しているホストにポートを転送するようにしてください。

Satellites のアクセス権限

satellites フォルダには以下のパーミッションを設定してください:

# chmod 750 /var/lib/gitlab/satellites

Gitlab データベースの初期化

データベースを作成する前に Redis サーバーを起動:

# systemctl start redis
# systemctl enable redis

以下のコマンドで bundler をインストールして必要な gem をインストールします:

# export PATH=$PATH:/var/lib/gitlab/.gem/ruby/2.3.0/bin
# sudo -u gitlab -H gem install bundler --no-document
# cd /usr/share/webapps/gitlab
# sudo -u gitlab -H bundle install
警告: GitLab は bundle コマンドを必要とします。忘れずにインストールしてください。
ノート: 'gitlab' ユーザーで bundle が存在しないというエラーが表示される場合、おそらく ruby が /usr/lib などの読み込みできないディレクトリにインストールされていることが原因です。以下のコマンドで解決できます:
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"

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

# cd /usr/share/webapps/gitlab
# su - gitlab -s /bin/sh -c "cd '/usr/share/webapps/gitlab'; bundle exec rake gitlab:setup RAILS_ENV=production"
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

アセットをコンパイル:

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

最後に、/etc/webapps/gitlab/secret にランダムな16進数の文字列が書かれていることを確認してください。

Git ユーザーの設定

ノート: 以下は /usr/share/webapps/gitlab/config/gitlab.yml で定義した useremail_from と一致している必要があります。
# 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"

修飾ビットの調整

(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-s /var/lib/gitlab/repositories
# find /var/lib/gitlab/repositories/ -type d -print0 | xargs -0 chmod g+s

GitLab の起動とテスト

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

systemd から新しいデーモンのユニットファイルを認識させる:

# systemctl daemon-reload

MySQLPostgreSQL と Redis が正しく実行・設定されていることを確認してください。

GitLab が 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
ノート: gitlab:env:info と gitlab:check コマンドは git に関する致命的なエラーを出力しますが、それで問題ありません。
$ sudo -u gitlab bundle exec rake gitlab:env:info RAILS_ENV=production
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
ノート: gitlab:check は initscripts が存在しないというエラーを吐きます。問題はありません。代わりに systemd のサービスファイルが使われます (GitLab は systemd を認識しません)。
$ sudo -u gitlab bundle exec rake gitlab:check RAILS_ENV=production
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

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

そして http://localhost:8080http://yourdomain.com をブラウザで開いてデフォルトのユーザー情報を使ってログインすることで GitLab インスタンスをテストしてください:

username: root
password: 5iveL!fe
ノート: gitlab を動作させるマシンとブラウザを使用するマシンが異なる場合、プロキシを使わなくてもセットアップがテストできるように unicorn.rb を修正してください。以下の行を:
listen "127.0.0.1:8080, :tcp_nopush => true

以下のように置き換えてください:

listen "example.yourhost.com:8080, :tcp_nopush => true

高度な設定

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

AUR インストール

Nginx をセットアップして、以下のディレクトリを作成してください (存在しない場合):

# mkdir /etc/nginx/servers-available
# mkdir /etc/nginx/servers-enabled
ノート: 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 {
  server localhost:8080 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://localhost:8080;
  }  
}

/etc/nginx/nginx.confhttp ブロックの末尾に以下の行があることを確認してください:

include servers-enabled/*;

github の設定を有効化:

# ln -s /etc/nginx/servers-available/gitlab /etc/nginx/servers-enabled/gitlab

新しい設定を確認:

# nginx -t

最後に gitlab.target, resque.target, nginx.service を再起動してください。

手動インストール

AUR を使わなかった場合、/usr/lib/support/nginx/gitlab/etc/nginx/sites-available/ にコピーする必要があります。

次のコマンドを実行して nginx を設定してください:

# ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

/etc/nginx/sites-enabled/gitlab を編集して YOUR_SERVER_IP と YOUR_SERVER_FQDN を Gitlab をホストするサーバーの IP アドレスと完全修飾ドメイン名に置き換えてください。

/etc/nginx/nginx.confhttp ブロックの末尾に以下の行があることを確認してください:

include sites-enabled/*;

github の設定を有効化:

# ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

新しい設定を確認:

# nginx -t

最後に gitlab.target, resque.target, nginx.service を再起動してください。

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 /etc/webapps/gitlab/apache.conf.example /etc/httpd/conf/extra/gitlab.conf

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

Redis

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

[Service]
Environment=REDIS_URL=unix:///run/gitlab/redis.sock

Redis で Unix ソケットを使う

ソケットを listen するように Redis を設定している場合、デフォルト設定を修正するべきです:

/etc/redis.conf
...
# 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

# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
unixsocket /var/run/redis/redis.sock
unixsocketperm 770

/var/run/redis ディレクトリを作成して適切なパーミッションを設定:

# mkdir /var/run/redis
# chown redis:redis /var/run/redis
# chmod 755 /var/run/redis

gitgitlab ユーザーを redis グループに追加:

# usermod -a -G redis git
# usermod -a -G redis gitlab

/etc/webapps/gitlab-shell/config.yml/etc/webapps/gitlab/resque.yml ファイルを修正:

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

最後に redis, gitlab-sidekiq, gitlab-unicorn サービスを再起動してください。

詳しくは issue #6100 を見てください。

Gitlab-workhorse

8.0 から GitLab は Git の push や pull などの巨大な HTTP リクエストで特別な HTTP サーバー gitlab-workhorse を使用します。SSH の代わりに workhorse を使いたい場合、gitlab-workhorseAUR パッケージをインストールして、gitlab-workhorse.service を有効化し、ウェブサーバーを設定してください。

便利なヒント

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 exec rake db:data:dump RAILS_ENV=production

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

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

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

# sudo -u gitlab bundle 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 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 exec rake sidekiq:start RAILS_ENV=production
        ;;
    stop)
        bundle 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 exec rake cache:clear

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 exec rake db:migrate RAILS_ENV=production

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

# sudo -u gitlab -H bundle exec rake assets:clean assets:precompile 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

参照