GitLabをVPS(CentOS 5.7)に(ボロボロになりながら)インストールしてみたよ

ハマリまくって死ぬかと思いました。
結果として何とか入りはしましたが、確実にアカンやろこれみたいなのもあって
突っ込まれること覚悟で書いていきたいと思います。

そもそもGitLabってなに?

gitのリポジトリ管理ツールであるgitosisというツールのwebフロントエンド。
あの有名なgithubみたいなのを自前のサーバーに持てるよ!というもの。

目標

初期化したてのVPS(CentOS 5.7)にGitlabをインストールして動かす。

1.下準備

gitlabはrailsで動いているのでrubyが必要です。
その他、SQLiteやpygmentsに依存しているのでSQLiteとeasy_installもインストールします。
また、gitlab言うくらいですからgitも必要です。
例によってyumに入っているものは古いので、ソースからインストールします。


そもそもgccとかも入ってないのでインストール。

[root@localhost src]# cd /usr/local/src/
[root@localhost src]# yum install gcc gcc-c++


rubyをインストール

[root@localhost src]# wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz
[root@localhost src]# tar xvzf ruby-1.9.2-p290.tar.gz
[root@localhost src]# ./configure --prefix=/usr
[root@localhost src]# make
[root@localhost src]# make install


SQLiteをインストール

[root@localhost src]# wget http://www.sqlite.org/sqlite-autoconf-3070900.tar.gz
[root@localhost src]# tar zxvf sqlite-autoconf-3070900.tar.gz
[root@localhost src]# ./configure
[root@localhost src]# make
[root@localhost src]# make install


以下のエラーが出ましたが、とりあえず無視することに
(今思えば、後にどハマリしたのはこの辺りが原因だった気がする…。)

Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.


gitをインストール

[root@localhost src]# wget http://git-core.googlecode.com/files/git-1.7.7.2.tar.gz
[root@localhost src]# tar xzvf git-1.7.7.2.tar.gz
[root@localhost src]# cd git-1.7.7.2
[root@localhost git-1.7.7.2]# ./configure
[root@localhost git-1.7.7.2]# make


依存パッケージが無いと怒られたのでインストール。

[root@localhost git-1.7.7.2]# yum install zlib-devel


気を取り直してもう一度makeしてinstall

[root@localhost git-1.7.7.2]# make
[root@localhost git-1.7.7.2]# make install


easy_installをインストール

[root@localhost src]# wget http://peak.telecommunity.com/dist/ez_setup.py
[root@localhost src]# python ez_setup.py


gemでrailsをインストール

[root@localhost src]# gem install rails


エラー

ERROR:  Loading command: install (LoadError)
    no such file to load -- zlib
ERROR:  While executing gem ... (NameError)
    uninitialized constant Gem::Commands::InstallCommand


rubyインストール時にzlibが入ってないと出るっぽいのでrubyのインストールからやり直しました。
で、再度改めて

[root@localhost src]# gem install rails

入りました。


rubySQLiteクライアントをインストール。

[root@localhost ruby-1.9.2-p290]# gem install sqlite3

2.GitLabインストール

GitLabをインストールします。
基本的にはgithubリポジトリからcloneしてきてREAD MEに沿うだけ…の筈なんですが
いろいろどハマリしました…。


READ ME通りに…。

[root@localhost src]# git clone git://github.com/gitlabhq/gitlabhq.git
[root@localhost src]# cd gitlabhq/
[root@localhost gitlabhq]# easy_install pygments
[root@localhost gitlabhq]# gem install bundler
[root@localhost gitlabhq]# bundle


エラー発生

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for libxml/parser.h... no
-----
libxml2 is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.


どうやらlibxmlが無いと言われている模様。
インストールして再度実行すると…?

[root@localhost gitlabhq]# bundle
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/bin/ruby
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- openssl (LoadError)
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from /usr/lib/ruby/1.9.1/net/https.rb:92:in `<top (required)>'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from /usr/lib/ruby/gems/1.9.1/gems/ruby_core_source-0.1.5/lib/contrib/uri_ext.rb:11:in `<top (required)>'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from /usr/lib/ruby/gems/1.9.1/gems/ruby_core_source-0.1.5/lib/ruby_core_source.rb:6:in `<top (required)>'
        from <internal:lib/rubygems/custom_require>:33:in `require'
        from <internal:lib/rubygems/custom_require>:33:in `rescue in require'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from extconf.rb:2:in `<main>'


Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/linecache19-0.5.12 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/gems/linecache19-0.5.12/ext/trace_nums/gem_make.out
An error occured while installing linecache19 (0.5.12), and Bundler cannot continue.
Make sure that `gem install linecache19 -v '0.5.12'` succeeds before bundling.


opensslが無いと言われているような気がするのでインストールして組み込む。

[root@localhost gitlabhq]# yum install openssl-devel
[root@localhost gitlabhq]# cd /usr/local/src/ruby-1.9.2-p290/ext/openssl
[root@localhost openssl]# ruby extconf.rb
[root@localhost openssl]# make
[root@localhost openssl]# make install


3度目の正直!!!

[root@localhost gitlabhq]# bundle

通った!!!


次の工程へ進むと

[root@localhost gitlabhq]# bundle exec rake db:setup RAILS_ENV=production
ruby: symbol lookup error: /usr/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.4/lib/sqlite3/sqlite3_native.so: undefined symbol: sqlite3_initialize

とか

[root@localhost gitlabhq]# bundle exec rake db:setup RAILS_ENV=production
ruby: symbol lookup error: /usr/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.4/lib/sqlite3/sqlite3_native.so: undefined symbol: sqlite3_open_v2

とかエラーが…。


lddしてみると

[root@localhost gitlabhq]# ldd /usr/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.4/lib/sqlite3/sqlite3_native.so
        libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0xb7f71000)
        libpthread.so.0 => /lib/libpthread.so.0 (0xb7f52000)
        librt.so.1 => /lib/librt.so.1 (0xb7f49000)
        libdl.so.2 => /lib/libdl.so.2 (0xb7f44000)
        libcrypt.so.1 => /lib/libcrypt.so.1 (0xb7f12000)
        libm.so.6 => /lib/libm.so.6 (0xb7ee9000)
        libc.so.6 => /lib/libc.so.6 (0xb7d8f000)
        /lib/ld-linux.so.2 (0xb7fd8000)

参照してるsoが違うっぽい?


グーグル先生に聞いてみると
gem install sqlite3するときにオプション指定するといいらしいので試す

[root@localhost gitlabhq]# gem install sqlite3 -- --with-sqlite3-include=/usr/local/include --with-sqlite3-lib=/usr/local/lib


どうですか?

[root@localhost gitlabhq]# ldd /usr/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.4/lib/sqlite3/sqlite3_native.so
        libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0xb7f71000)
        libpthread.so.0 => /lib/libpthread.so.0 (0xb7f52000)
        librt.so.1 => /lib/librt.so.1 (0xb7f49000)
        libdl.so.2 => /lib/libdl.so.2 (0xb7f44000)
        libcrypt.so.1 => /lib/libcrypt.so.1 (0xb7f12000)
        libm.so.6 => /lib/libm.so.6 (0xb7ee9000)
        libc.so.6 => /lib/libc.so.6 (0xb7d8f000)
        /lib/ld-linux.so.2 (0xb7fd8000)

変わってない…。


他にはLD_LIBRARY_PATHを設定する方法があるらしいので試すもやはり結果は変わらず…。
この辺りになるともう完全に疲弊していてフラフラになっていた僕は

[root@localhost gitlabhq]# mv /usr/lib/libsqlite3.so.0  /usr/lib/libsqlite3.so.0.tmp

/usr/lib/libsqlite3.so.0 なんて無くなってしまえばええんや!!!
とばかりにリネームして再度SQLite3インストール

[root@localhost gitlabhq]# gem install sqlite3 -- --with-sqlite3-include=/usr/local/include --with-sqlite3-lib=/usr/local/lib


再実行

[root@localhost gitlabhq]# bundle exec rake db:setup RAILS_ENV=production
[root@localhost gitlabhq]# bundle exec rake db:seed_fu RAILS_ENV=production

通った…だと…?


そして、最後にGitLabを起動してみます。
80番はかぶるのでとりあえず8080ポートで。

[root@localhost gitlabhq]# rails s -e production -p 8080

動きました。


なんかもう、完全に間違ってる感ありますが僕はもういろいろ限界にきていました…。
今から思うと、最初の方の依存ライブラリのインストール辺りが非常に怪しいですね。
この経験値を持ってもう一回最初からやり直したほうがいい気がしています。

3.gitosisインストール

GitLabのバックエンドであるgitosisをインストールします。
gitosisインストールしないとGitLabが稼動してもgit的なことは何も出来ません。


まずはgitosisのリソースをgithubからclone

[root@localhost src]# git clone git://eagain.net/gitosis.git


インストール

[root@localhost src]# cd gitosis/
[root@localhost gitosis]# ls -l
[root@localhost gitosis]# python setup.py install


gitosisで使うユーザを作ってそのユーザに変身します

[root@localhost gitosis]# useradd -g root git
[root@localhost gitosis]# su git


リポジトリにアクセスするための鍵を作成

[git@localhost ~]$ ssh-keygen -t rsa


gitosisを初期化します

[git@localhost ~]$ gitosis-init < ~/.ssh/id_rsa.pub
[git@localhost ~]$ chmod 755 ~/repositories/gitosis-admin.git/hooks/post-update


以上でインストールは完了です。
実際にはGitLabの設定とかもしないとダメですが、今回はとりあえずインストールまでで。


あと、ずっとrootで作業してたお陰でファイルの権限関係で引っかかったりとかしましたが
その辺は、怒られたところをちくちくchownしたりchmodしたりすれば大丈夫でした。