CentOS 6.2 に GitLab をインストールする
少し前に GitHub クローンである GitLab を検証していた際の環境構築メモを整理がてらまとめてみました。
GITLAB
http://gitlabhq.com/
現在公式リポジトリでは 2.3.1 が最新のようですが、試した時のバージョンなので 2.2.0 での記事になっています。
2013.08.16 追記
新しいバージョンについて記事を書いています。
こちらも参照してください。
GitLab 5.4.0 を CentOS 6.4 にインストールする
環境
使用した各ソフトウェアのバージョンは以下になります。
CentOS | 6.2(i686) |
---|---|
Git | 1.7.1 |
Ruby | ruby 1.9.3p125 |
gitolite | 最新 |
GitLab | 2.2.0 |
gitolite、GitLab 以外については既に導入済みとし、ここでは解説を省きます。
また、Yum リポジトリとしては EPEL が追加済みのサーバで作業していました。
他にもいくつかのライブラリなどはインストール済みのところから構築をスタートしているため、途中エラーになるようであれば適宜導入してください ^^;
ユーザの作成と公開鍵の準備
gitolite 管理用ユーザ git と gitlab 実行用ユーザ gitlabhq ユーザを作成します。
また、gitlabhq ユーザを git グループにも所属させておきます。
# useradd git # useradd gitlabhq # usermod -G git gitlabhq
グループに所属するユーザからリポジトリを参照できるように、/home/git にグループに対するパーミッションを設定します。
# chmod g+rx /home/git
gitolite へ登録するための管理ユーザ用公開鍵を作成するため gitlabhq ユーザになります。
# su - gitlabhq
一旦 localhost に ssh 接続を試み、/home/gitlabhq/.ssh/known_hosts が作成され localhost が登録されるところまで実行します。
$ ssh localhost The authenticity of host 'localhost (127.0.0.1)' can't be established. RSA key fingerprint is dc:ef:1d:f9:6b:17:13:73:cf:2e:09:ce:34:46:af:14. Are you sure you want to continue connecting (yes/no)? yes # ここは yes と入力 Warning: Permanently added 'localhost' (RSA) to the list of known hosts. gitlabhq@localhost's password: # ここまで来たら Ctrl-C で終了して OK
公開鍵を作成し、 git ユーザのホームディレクトリに移動させておきます。
$ ssh-keygen -t rsa -P "" -f ~/.ssh/gitadmin $ exit # root に戻ります # mv /home/gitlabhq/.ssh/gitadmin.pub /home/git
gitolite のインストール
git ユーザになり、gitolite を github から clone しインストールします。
# su - git
$ git clone git://github.com/sitaramc/gitolite
$ gitolite/src/gl-system-install
/home/git/bin に PATH を通した状態で先ほど作成した公開鍵を引数に gl-setup を実行します。
$ sh -c "PATH=/home/git/bin:$PATH; gl-setup /home/git/gitadmin.pub" The default settings in the rc file (/home/git/.gitolite.rc) are fine for most people but if you wish to make any changes, you can do so now. hit enter...
ここで Enter キーを押すと設定ファイル /home/git/.gitolite.rc を開いた状態で vi が起動するので、$REPO_UMASK の値を以下のように変更します。
$REPO_UMASK = 0077;
↓
$REPO_UMASK = 0007;
変更したら :wq で保存して終了すると以下のようなメッセージが流れ gitolite のインストールは完了です。
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) 7d38524] gl-setup /home/git/gitadmin.pub 2 files changed, 8 insertions(+), 0 deletions(-) create mode 100644 conf/gitolite.conf create mode 100644 keydir/gitadmin.pub
gitlabhq ユーザでの SSH 設定
gitlabhq ユーザになり、~/.ssh/config を作成します。
$ exit # gitlabhq ユーザに su するため root に戻る # su - gitlabhq $ vi ~/.ssh/config
環境に合わせ、以下のような内容を記述します。
Host localhost HostName localhost User git IdentityFile ~/.ssh/gitadmin
作成したら権限を変更。
$ chmod 0600 ~/.ssh/config
また、gitlabhq ユーザでの git の初期設定を行っておきます。
$ git config --global user.email "gitadmin@example.com" $ git config --global user.name "gitadmin"
GitLab のインストール
root ユーザになり、必要なライブラリをインストールします。
$ exit # root に戻ります # yum install -y python-devel python-pip redis libicu-devel # pip-python install pygments # gem install bundler --no-rdoc --no-ri
インストールが完了したら Redis を起動しておきます。
# service redis start
gitlabhq ユーザになり、v2.2.0 の tarball を取得し展開します。
# su - gitlabhq $ wget --content-disposition https://github.com/gitlabhq/gitlabhq/tarball/v2.2.0 $ tar xzf gitlabhq-gitlabhq-v2.2.0-0-g9e6d071.tar.gz $ ln -s gitlabhq-gitlabhq-8373315 gitlabhq
bundle install は --deployment オプション付きで実行することに注意して下さい。
$ cd /home/gitlabhq/gitlabhq $ bundle install --deployment --without development test
設定ファイルの雛形をコピーします。
$ cp config/database.yml.example config/database.yml $ cp config/gitlab.yml.example config/gitlab.yml
環境に合わせてサーバ設定を変更します。
$ vi config/gitlab.yml
ここでは host をサーバのものに変更しました。
# Gitlab application config file # Email used for notification # about new issues, comments email: from: notify@gitlabhq.com host: gitlabhq.com # Git Hosting congiguration git_host: system: gitolite admin_uri: git@localhost:gitolite-admin base_path: /home/git/repositories/ host: 192.0.2.0 git_user: git # port: 22 # Git settings # Use default values unless you understand it git: # Max size of git object like commit, in bytes # This value can be increased if you have a very large commits git_max_size: 5242880 # 5.megabytes # Git timeout to read commit, in seconds git_timeout: 10
以下を実行して初期データを投入します。
$ bundle exec rake db:setup RAILS_ENV=production $ bundle exec rake db:seed_fu RAILS_ENV=production
ここで db:seed_fu 実行後にデフォルトの管理者アカウント情報が表示されるのでメモしておきます。
完了したらサーバを起動します。
$ bundle exec rails s -e production
これでブラウザからアクセスすると先ほど db:seed_fu 実行後に表示されたアカウント情報でログインできます。
ログインしたら「Visit Admin Area」より新規に管理ユーザを登録し、デフォルトのアカウントは削除しておいた方が良いでしょう。
管理ユーザを作成したら、プロジェクトを作成してみて、上手く行くようであれば GitLab サーバの構築は成功です。
GitLab からのプロジェクトの作成に失敗する場合にはディレクトリのパーミッションをよく見直してみて下さい。
以上で GitLab サーバ構築は完了です。
後は Passenger で起動するように設定したりすると思いますが、長くなったので、そちらについては次回まとめたいと思います。
参考
Fedora · gitlabhq/gitlabhq Wiki
https://github.com/gitlabhq/gitlabhq/wiki/Fedora
CentOS6.2(gitlab2.1+redmine1.3)(rvm+passenger+nginx) Vol.1 - studio3104::Blog::Infrastructure
http://studio3104.hatenablog.com/entry/2012/01/22/235052