LoginSignup
36
35

More than 5 years have passed since last update.

GitLabをCentOS7にインストールしてみた

Last updated at Posted at 2015-01-22

社内でのソース管理用にインストールしてみる。
クリーンな環境で特にカスタムしなければyak率は結構低い。

インストール

オフィシャルだと事前にopensshとpostfixをインストールするような指示。
postfixインストールしていない場合sendmailと競合して他のサービスに影響があると嫌だなー・・・

# yum install https://downloads-packages.s3.amazonaws.com/centos-7.0.1406/gitlab-7.5.1_omnibus.5.2.0.ci-1.el7.x86_64.rpm

読み込んだプラグイン:fastestmirror
gitlab-7.5.1_omnibus.5.2.0.ci-1.el7.x86_64.rpm                                                                                                                                                                         | 286 MB  00:04:44
/var/tmp/yum-root-oftyrA/gitlab-7.5.1_omnibus.5.2.0.ci-1.el7.x86_64.rpm を調べています: gitlab-7.5.1_omnibus.5.2.0.ci-1.el7.x86_64
/var/tmp/yum-root-oftyrA/gitlab-7.5.1_omnibus.5.2.0.ci-1.el7.x86_64.rpm をインストール済みとして設定しています
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ gitlab.x86_64 0:7.5.1_omnibus.5.2.0.ci-1.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

==============================================================================================================================================================================================================================================
 Package                                    アーキテクチャー                           バージョン                                                       リポジトリー                                                                     容量
==============================================================================================================================================================================================================================================
インストール中:
 gitlab                                     x86_64                                     7.5.1_omnibus.5.2.0.ci-1.el7                                     /gitlab-7.5.1_omnibus.5.2.0.ci-1.el7.x86_64                                     793 M

トランザクションの要約
==============================================================================================================================================================================================================================================
インストール  1 パッケージ

合計容量: 793 M
インストール容量: 793 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : gitlab-7.5.1_omnibus.5.2.0.ci-1.el7.x86_64                                                                                                                                                                    1/1
Thank you for installing GitLab!
Configure and start GitLab by running the following command:

sudo gitlab-ctl reconfigure

GitLab should be reachable at localhost
Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
And running reconfigure again.

  検証中                  : gitlab-7.5.1_omnibus.5.2.0.ci-1.el7.x86_64                                                                                                                                                                    1/1

インストール:
  gitlab.x86_64 0:7.5.1_omnibus.5.2.0.ci-1.el7

完了しました!

オフィシャルだと次の1stepで終了とあるんだけど
bugなのか、というかbugなんだろうけど、以下やっておかないと進まなかった。

# vi /etc/gitlab/gitlab.rb
# デフォルトだと"="が入っていなくて構文エラーなので"="をつける(FQDNがlocalhostでないなら変更)
#external_url 'localhost'
external_url = '[アクセスするFQDN]'
# ついでにメール設定(デフォルトだとgitlab@[サーバホスト]で送信するため飛ばないケースがある)
gitlab_rails['gitlab_email_from'] = '[送信用のメールアドレス]'

これやらないと以下の様なエラーになった。

Recipe Compile Error in /opt/gitlab/embedded/cookbooks/gitlab/recipes/default.rb

RuntimeError

External URL must include a FQDN

なんだかしょーもないエラーだなー。。

次に

# gitlab-ctl reconfigure

なんとこれだけでおしまい。
えらい長いログを吐いて正常に終了すればOK。
後はhttpdのファイアウォール開けろよ的な動き。

クリーンな状態なOSの場合ここまでやればgitlab内部の
nginx
postgresql
redis
sidekiq
unicorn
なぞが動き出すようでブラウザからアクセスすれば表示できる。
初期のID/PWは

root
5iveL!fe

という謎なパスワード。

スクリーンショット 2014-12-03 19.00.04.png

ロゴがキモい件

gitlab_logo.png

主張しすぎでしょ。
以下のファイルを用意してあげれば差し替え可能。

/opt/gitlab/embedded/service/gitlab-rails/app/assets

brand_logo.png : ログイン画面 720×464px
favicon.ico : favicon 16×16px
logo-white.png : 左上ボタン(白) 84×79px
logo-black.png : 左上ボタン(黒) 75×65px

変更したら

# gitlab-ctl reconfigure
# gitlab-ctl restart

ポートを弄る

既存に入れていたミドルウエアと被っている場合問題が出てくる。
ymlの設定変更でなんとかしている記事も多いけどomunibus版で楽したら
chefが設定を作っているのでgitlab.rbで変更しないときちんと反映できない(reconfigureで戻る)。

例えば以下の様にしてポートをずらすなり、

/etc/gitlab/gitlab.rb
unicorn['port'] = 8080
redis['port'] = 6379
postgresql['port'] = 5432

以下の様に最初からインストールしないという方法もある。

/etc/gitlab/gitlab.rb
nginx['enable'] = false
postgresql['enable'] = false
redis['enable'] = false

この辺りの詳細はomunibus版のreadmeを見た方が安全だろう。
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

ちなみにgitlab.rbで設定を変更した場合は再起動しないと反映されない。

# gitlab-ctl reconfigure
# gitlab-ctl restart

Apacheと共存させたい

させたいのです。他にもいろいろ動いているのです。

手っ取り早くnginxのポートを変更してapacheからリバースプロキシして楽チン版でやってみる。
ポート8080はuniconeが使うので8888とか。
なかなか情報が見つからなくてハマったのだけど以下追記してもログを確認すると変わってない。

/etc/gitlab/gitlab.rb
+ nginx['listen_address'] = '*'
+ ginx['port'] = 8888

やむをえずchefのtemplateを書き換えた。

/opt/gitlab/embedded/cookbooks/gitlab/templates/default/nginx-gitlab-http.conf.erb
server {
    <% @listen_addresses.each do |listen_address| %>
-    listen <%= listen_address %>:<%= @port %>;
+    listen <%= listen_address %>:8888;
    <% end %>

反映

# gitlab-ctl reconfigure
# gitlab-ctl restart

サブディレクトリで運用する場合は
/opt/gitlab/embedded/service/gitlab-rails/config/application.rb
に記載がある通り、

# Relative url support
# Uncomment and customize the last line to run in a non-root path
# WARNING: We recommend creating a FQDN to host GitLab in a root path instead of this.
# Note that following settings need to be changed for this to work.
# 1) In your application.rb file: config.relative_url_root = "/gitlab"
# 2) In your gitlab.yml file: relative_url_root: /gitlab
# 3) In your unicorn.rb: ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
# 4) In ../gitlab-shell/config.yml: gitlab_url: "http://127.0.0.1/gitlab"
# 5) In lib/support/nginx/gitlab : do not use asset gzipping, remove block starting with "location ~ ^/(assets)/"
#
# To update the path, run: sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
#
# config.relative_url_root = "/gitlab"

でやってみればいい。1点だけ5)の部分はたぶん説明足りずなので以下の様にしたら動いた。

/opt/gitlab/embedded/cookbooks/gitlab/templates/default/nginx-gitlab-http.conf.erb
-location / {
+location /gitlab {
    alias /opt/gitlab/embedded/service/gitlab-rails/public;
    try_files uriuri/index.html $uri.html @gitlab;
}

# 消さないとアイコンがちゃんと表示されない
-  location ~ ^/(assets)/ {
-    root /opt/gitlab/embedded/service/gitlab-rails/public;
-    gzip_static on; # to serve pre-gzipped version
-    expires max;
-    add_header Cache-Control public;
-  }

以上。

36
35
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
36
35