どぶお/開発しよう!

GitLabをインストールする  

2012-01-14 : 作成

gitを使い始めたばかりでgitoliteを使ったこともない、RailsはおろかRubyも使ったことがない、という状況で試したのでかなり苦労しました・・・
なお、ネット上ではGitLab + gitosisの情報(恐らくGitLab 1.2)が多いですが、2011年12月下旬にリリースされた2.0からgitoliteが標準になったようです。なお、gitoliteは以前のバージョン(CentOS6でRPMがあります)と最近のアーカイブではインストール方法などが異なっていますので、新たにインストールするならここで示したようにgitで取得したアーカイブを使う方が簡単だと思います。これを認識しておかないと大混乱します(しました)。

実行ユーザーの作成  

まずはWebサーバ上の管理ユーザーを作成します。gitというユーザーを使用しますが、コマンド名等と紛らわしいのでユーザーgitを表す時は斜体gitで表現します。ホームディレクトリは/home/gitにします。

# groupadd -g 600 git                         <-- GID:600で作成
# useradd -m -g 600 -u 600 git                <-- UID:600で作成
# passwd git                                        <-- シェルで作業するのでパスワードを設定しておく
# su - git                                          <-- ユーザーgitで作業
% git config --global user.name "Git Administrator" <-- 適当に
% git config --global user.email "git@localhost"    <-- 適当に

user.nameとuser.emailを設定しておかないとGitLabでの動作の時にエラーが発生します。

% cd .ssh
% ssh-keygen -t rsa -N "" -f id_rsa    <-- パスフレーズなしで作成

以降、インストールはユーザーgitで行います。

gitoliteのインストール  

% cd <-- gitホームディレクトリで作業
% git clone git://github.com/sitaramc/gitolite
% gitolite/src/gl-system-install

ここでgitoliteの実行ファイル群にパスを通せと言われるのでこの場のみパスを通す。

% export PATH=/home/git/bin:$PATH
% ln -s .ssh/id_rsa.pub GitlabAdmin.pub <-- gitoliteの識別名として使われるのでリンクで名前を付ける
% gl-setup -q ~/GitlabAdmin.pub
creating gitolite-admin...
Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/
creating testing...
Initialized empty Git repository in /home/git/repositories/testing.git/
[master (root-commit) 052c845] start
 2 files changed, 6 insertions(+), 0 deletions(-)
 create mode 100644 conf/gitolite.conf
 create mode 100644 keydir/GitlabAdmin.pub

このようにキーが追加されます。
パスフレーズなしでgitアカウントにログインできるかを確認およびknown_hostへのlocalhostの追加を行うためにsshでログインします(ログイン時にはbl-auth-commandが使われるのでシェルには入れない)。

% ssh localhost
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
PTY allocation request failed on channel 0  <-- このような応答があればOK

gitolite-adminリポジトリにアクセスできるかを確認。

% git clone git@localhost:gitolite-admin
Cloning into gitolite-admin...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.

これでgitoliteのインストールは完了です。

GitLabのインストール  

続いてGitLabをインストールします。これも作業はユーザーgitで行います。

参考

rpmでインストール  

GitLabはRuby 1.9.2以上が必要になりますが、Vine6では1.8.7なので、1.9.3-p0のRPMパッケージを作成しました。これらをインストールします。RPMを使わない場合はソースなどからインストールして下さい。なお、RubyおよびRailsの複数バージョンを使いたい場合はRVMというものを使うといいみたいです(ここでは取り上げませんが)。

apt  

続いて、aptで以下のパッケージをインストールします。ひょっとしたらこれ以外にも必要な物があるかもしれませんが、さほど複雑なライブラリはなかった気がします(aptでインストール可能なものばかり)。

インストール  

ここまできたら、Rubyのパッケージをgemを使ってインストールします。
GitLabのバージョンによって内容が変わるので、本家のWikiを確認することをオススメします。GitLab 2.1.0は以下の手順でインストールできました。

# eazy_install pygments
# gem install bundler
# gem install charlock_holmes -v '0.6.8'

ようやくGitLab本体のインストールを行います。2012年2月現在のバージョンは2.1(2012-01-22)と書いてありました。

% cd  <-- ホームディレクトリからスタートします
% git clone http://github.com/gitlabhq/gitlabhq.git
% cd gitlabhq
% bundle <-- githubのCAを認証する設定をしていないとSSLのエラー
Fetching https://github.com/gitlabhq/grit.git
error: SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed while accessing https://github.com /gitlabhq/grit.git/info/refs

以上のようなエラーが出る場合はこのディレクトリのGemfileを編集します。またはGitHubをHTTPSで使えるようにしておきたい場合は下記のページを参照して必要な証明書をインストールして下さい。

Gemfileの編集
Gemfile中のhttps://github.com/...http://github.com/...に変更します。3ヶ所あるはずです。

修正したら再度bundleを実行します。途中でsudoを実行するためにパスワード入力があるので認証して下さい。

% bundle install --without development test
% bundle exec rake db:setup RAILS_ENV=production
...(省略)
-- assume_migrated_upto_version(20120110180749, ["/home/git/gitlabhq/db/migrate"])
   -> 0.8604s
% bundle exec rake db:seed_fu RAILS_ENV=production

== Seed from /home/git/gitlabhq/db/fixtures/production/001_admin.rb

Administrator account created:

login.........admin@local.host
password......5iveL!fe

最初はこのアカウントでログインします。

動作テスト  

ポート8080でサーバを起動してみる

% rails s -e production -p 8080

8080にアクセスしてログインできたらとりあえずOK。

passengerでapacheからRailsを動かす  

参考

passengerのインストール  

# gem install passenger
# passenger-install-apache2-module

apache2の設定を行います。

apache2ディレクトリのconf.d/passenger.conf
LoadModule passenger_module /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.11
PassengerRuby /usr/bin/ruby
RailsPoolIdleTime 3600
以上でpassengerの初期設定ができました。

その他エラー  

エラーを修正したらapacheの再起動をお忘れなく!

could not find any magic files!が出た  

プロジェクトを表示させようとした時に以下のエラーが出ました。

Started GET "/lab/test_project" for hostname at 2012-01-14 21:11:19 +0900
  Processing by ProjectsController#show as HTML
  Parameters: {"id"=>"test_project"}
Completed 500 Internal Server Error in 13ms

StandardError (could not find any magic files!):
  config/initializers/gitlabhq/20_grit_ext.rb:19:in `transcoding'
  config/initializers/gitlabhq/20_grit_ext.rb:13:in `content'
  app/models/repository.rb:98:in `commit'
  app/models/project.rb:73:in `commit'
  app/models/project.rb:177:in `has_commits?'
  app/controllers/projects_controller.rb:70:in `show'

これはcharlock_holmesがちゃんとインストールされていない時に発生するようです。 READMEによると、--with-icu-dirオプションを付けてインストールしろとのこと。

# gem install charlock_holmes -- --with-icu-dir=/usr/share/icu/4.4
Building native extensions.  This could take a while...
Successfully installed charlock_holmes-0.6.8
1 gem installed
Installing ri documentation for charlock_holmes-0.6.8...
unable to convert "\xE5" from ASCII-8BIT to UTF-8 for ext/charlock_holmes/src/file-5.08/magic/Magdir/riff, skipping
...略(7行ぐらい)
Installing RDoc documentation for charlock_holmes-0.6.8...
unable to convert "\xE5" from ASCII-8BIT to UTF-8 for ext/charlock_holmes/src/file-5.08/magic/Magdir/riff, skipping
...略(7行ぐらい)

なんかunable to convertがいっぱい出ましたが、回避されるようになりました。

コメント