追記 2013/04/08
単に GitLab を動かすだけなら ruby をシステムグローバルにインストールする必要は無いので
rvm とか rbenv とか、もしくは /home/git/ruby-1.9.3/ あたりにインストールする方がいいかもしれない。
なんかいろいろ変わったらしいので入れてみました。
依存パッケージのインストール
epel リポジトリを追加します。
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
開発ツールをインストールします。
yum groupinstall 'Development Tools'
その他の必要なパッケージをインストールします。
おおむね gitlab-recipes/install/CentOS_6.md の通りですが、
あきらかに不要そうなパッケージは除いています。
yum install vim-enhanced httpd readline readline-devel ncurses-devel gdbm-devel glibc-devel \
tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc \
sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel \
libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel \
python-devel redis sudo mysql-server wget \
mysql-devel crontabs logwatch logrotate \
perl-Time-HiRes
最新にアップデートして再起動しておきます。
yum update
reboot
CheckInstall のインストール
ruby を RPM にするために checkinstall をインストールします。
checkinstall は x64 だといろいろ問題がありますが、修正したものがあるのでそれを使います。
cd /usr/local/src
git clone https://github.com/ngyuki/checkinstall.git
cd checkinstall/
make
make install
mkdir -p ~/rpmbuild/SOURCES
checkinstall --pkgversion=1.6.3
rpm -ivh ~/rpmbuild/RPMS/x86_64/checkinstall-1.6.3-1.x86_64.rpm
Ruby 1.9.3 のインストール
CentOS6 の標準レポの ruby-1.8.7 だと動作しないので ruby-1.9.3 を入れます。
configure
で --disable-install-doc
をつけないと checkinstall の「tempディレクトリにファイルをコピー..」という段階で致命的に時間がかかります(数時間とかのオーダーでかかるらしいです)。
GitLab のサーバ上で ruby でコーディングすることは無いのでドキュメントのために無駄に時間をかける必要もないでしょう。
cd /usr/local/src
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz
tar xvzf ruby-1.9.3-p392.tar.gz
cd ruby-1.9.3-p392
./configure --prefix=/usr --disable-install-doc
make
checkinstall で RPM を作成します。そこそこ時間がかかりますが途中で中断しないようにしてください。
途中で中断してからもう一度 checkinstall すると中途半端な RPM になってしまいます。
checkinstall --fstrans=no --pkgname=ruby --pkgversion=1.9.3 --pkgrelease=p392 --exclude=$(pwd)
出来上がった RPM をインストールします。
rpm -ivh ~/rpmbuild/RPMS/x86_64/ruby-1.9.3-p392.x86_64.rpm
bundler
も必要なのでインストールしておきます。
gem install bundler --no-rdoc --no-ri
理由はわかりませんが charlock_holmes
をバージョン指定でインストールしておく必要があるようです。
gem install charlock_holmes --version '0.6.9' --no-rdoc --no-ri
「/usr/bin/ruby は ruby-1.8.7-p357.i386 に必要とされています
」というエラー
ruby の RPM のインストールで「/usr/bin/ruby は ruby-1.8.7-p357.i386 に必要とされています
」というエラーになる場合、中途半端な RPM になっています。
/usr/bin/ruby
などに ruby 関連のファイルが作成されているはずなので、それらを全て手動で削除してから checkinstall をやり直してください。
MySQL を開始して mysql_secure_installation
します。
chkconfig mysqld on
service mysqld start
mysql_secure_installation
GitLab のためのユーザとデータベースを作成します。パスワードは適当に要変更です。
mysql -u root -p mysql
CREATE USER gitlabhq@localhost IDENTIFIED BY 'password';
CREATE DATABASE gitlabhq_production;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON gitlabhq_production.* TO gitlabhq@localhost;
Redis の起動
Redis が必要らしいので起動しておきます。
chkconfig redis on
service redis start
Git アカウント
git アカウントを作成します。
adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git git
su - git
.ssh/authorized_keys
を適切なパーミッションで作成しておきます。これをやっておかないと git push
で怒られます(sshd に)。
mkdir .ssh
touch .ssh/authorized_keys
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
ついでに git config
しておきます。
git config --global user.name "GitLab"
git config --global user.email "gitlab@example.com"
GitLab Shell のセットアップ
GitLab Shell をクローンして 5.0 のためのバージョンをチェックアウトします。
git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
git checkout -b v1.1.0 v1.1.0
config.yml.example
をコピーして gitlab_url
を書き換えます。
cp config.yml.example config.yml
sed -i 's|http://localhost/|http://localhost:3000/|' config.yml
diff -u config.yml.example config.yml
--- config.yml.example 2013-04-02 22:00:28.813622014 +0900
+++ config.yml 2013-04-02 22:01:06.584622431 +0900
@@ -2,7 +2,7 @@
user: git
# Url to gitlab instance. Used for api calls
-gitlab_url: "http://localhost/"
+gitlab_url: "http://localhost:3000/"
# Repositories path
repos_path: "/home/git/repositories"
最後に次のコマンドを実行して GitLab Shell のセットアップは完了です。
./bin/install
GitLab のセットアップ
GitLab をクローンして 5-0-stable
ブランチをチェックアウトします。
cd ~
git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd gitlab
git checkout 5-0-stable
config/gitlab.yml.example
をコピーしてホスト名やメールアドレスを変更します。
cp config/gitlab.yml.example config/gitlab.yml
vi config/gitlab.yml
diff -u config/gitlab.yml.example config/gitlab.yml
--- config/gitlab.yml.example 2013-04-02 22:04:42.552625248 +0900
+++ config/gitlab.yml 2013-04-02 22:07:09.330628529 +0900
@@ -15,7 +15,7 @@
## GitLab settings
gitlab:
## Web server settings
- host: localhost
+ host: gitlab.example.com
port: 80
https: false
# Uncomment and customize to run in non-root path
@@ -27,10 +27,10 @@
## Email settings
# Email address used in the "From" field in mails sent by GitLab
- email_from: gitlab@localhost
+ email_from: gitlab@example.com
# Email address of your support contact (default: same as email_from)
- support_email: support@localhost
+ support_email: support@example.com
## Project settings
default_projects_limit: 10
書込可能ディレクトリのオーナーとパーミッションを設定します(不要?)。
chown -R git log/
chown -R git tmp/
chmod -R u+rwX log/
chmod -R u+rwX tmp/
config/unicorn.rb.example
をコピーして listen を変更します。
cp config/unicorn.rb.example config/unicorn.rb
sed -i config/unicorn.rb -e '/^listen/{
a listen 3000
s/^listen/#listen/
}'
diff -u config/unicorn.rb.example config/unicorn.rb
--- config/unicorn.rb.example 2013-04-02 22:03:39.954624770 +0900
+++ config/unicorn.rb 2013-04-02 22:07:33.742626105 +0900
@@ -17,7 +17,8 @@
#listen 8080 # listen to port 8080 on all TCP interfaces
#listen "127.0.0.1:8080" # listen to port 8080 on the loopback interface
-listen "#{app_dir}/tmp/sockets/gitlab.socket"
+#listen "#{app_dir}/tmp/sockets/gitlab.socket"
+listen 3000
pid "#{app_dir}/tmp/pids/unicorn.pid"
stderr_path "#{app_dir}/log/unicorn.stderr.log"
config/database.yml.mysql
をコピーして username と password を変更します。
cp config/database.yml.mysql config/database.yml
vi config/database.yml
diff -u config/database.yml.mysql config/database.yml
--- config/database.yml.mysql 2013-04-02 22:03:39.953624770 +0900
+++ config/database.yml 2013-04-02 22:12:23.071238884 +0900
@@ -7,8 +7,8 @@
reconnect: false
database: gitlabhq_production
pool: 5
- username: root
- password: "secure password"
+ username: gitlabhq
+ password: password
# host: localhost
# socket: /tmp/mysql.sock
satellites ディレクトリを作成します。
cd ~
mkdir gitlab-satellites
bundle で Gem をインストールします。
cd gitlab
bundle install --deployment --without development test postgres
データベースを初期化します。
bundle exec rake gitlab:setup RAILS_ENV=production
root に戻ります。
exit
init スクリプトの設置
サービス起動のための init スクリプトを設置します。
curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab-centos
ただし、この init スクリプトは GitLab 4.1 用で、そのままでは動かないので修正します。
sed -i.orig 's/USER=\$NAME/USER=git/' /etc/init.d/gitlab
diff -u /etc/init.d/gitlab.orig /etc/init.d/gitlab
--- /etc/init.d/gitlab.orig 2013-04-02 22:19:57.585375138 +0900
+++ /etc/init.d/gitlab 2013-04-02 22:19:59.838364486 +0900
@@ -20,7 +20,7 @@
NAME=gitlab
# The username and path to the gitlab source
-USER=$NAME
+USER=git
APP_PATH=/home/$USER/gitlab
# The PID and LOCK files used by unicorn and sidekiq
init スクリプトを有効にします
chmod +x /etc/init.d/gitlab
chkconfig --add gitlab
インストールの確認
うまくインストール出来ているかどうか確認します。この作業は git アカウントで行います。
su - git
cd gitlab
以下のコマンドでいろいろ情報を表示します。
bundle exec rake gitlab:env:info RAILS_ENV=production
次のような内容が表示されます。
System information
System: CentOS release 6.4 (Final)
Current User: git
Using RVM: no
Ruby Version: 1.9.3p392
Gem Version: 1.8.23
Bundler Version:1.3.4
Rake Version: 10.0.3
GitLab information
Version: 5.0.0
Revision: 8b76157
Directory: /home/git/gitlab
DB Adapter: mysql2
URL: http://gitlab.example.com
HTTP Clone URL: http://gitlab.example.com/some-project.git
SSH Clone URL: git@gitlab.example.com:some-project.git
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version: 1.1.0
Repositories: /home/git/repositories/
Hooks: /home/git/gitlab-shell/hooks/
Git: /usr/bin/git
以下のコマンドでいろいろチェックします。
bundle exec rake gitlab:check RAILS_ENV=production
次のような内容が表示されます。Running? と Init script up-to-date? が赤字の no になると思います。
Checking Environment ...
Git configured for git user? ... yes
Has python2? ... yes
python2 is supported version? ... yes
Checking Environment ... Finished
Checking Gitlab Shell ...
GitLab Shell version? ... OK (1.1.0)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
post-receive hook up-to-date? ... yes
post-receive hooks in repos are links: ... can't check, you have no projects
Checking Gitlab Shell ... Finished
Checking Sidekiq ...
Running? ... no
Try fixing it:
sudo -u git -H bundle exec rake sidekiq:start RAILS_ENV=production
For more information see:
doc/install/installation.md in section "Install Init Script"
see log/sidekiq.log for possible errors
Please fix the error above and rerun the checks.
Checking Sidekiq ... Finished
Checking GitLab ...
Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Init script exists? ... yes
Init script up-to-date? ... no
Try fixing it:
Redownload 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.
Projects have satellites? ... can't check, you have no projects
Checking GitLab ... Finished
git アカウントでの作業は完了です。
exit
GitLab 開始
service
コマンドで開始します。
service gitlab start
次のURLでログイン画面が表示されます。
http://gitlab.example.com:3000/
次の通りに入力してログインできます。
Email: admin@local.host
Password: 5iveL!fe
多分そのままでも使えますが、Apache 経由のアクセスになるように変更します。
vi /etc/httpd/conf.d/gitlab.conf
次の通りに gitlab.conf
を作成します。
<VirtualHost *:80>
ServerName gitlab.example.net
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
Apache を起動します。
chkconfig httpd on
service httpd start
次のURLでアクセス出来ます。
http://gitlab.example.com/
使ってみた感じ
GitLab 3.0.3(今使ってるバージョン) と比べると、下記のような点が良い感じだと思いました。
gitolite がいらないのでインストールがめちゃくちゃ楽
GitHub のようにリポジトリのURLが username/repository のようになった
↑にともないグループ(GitHub でいうところの組織?)を作れるようになった
リポジトリを任意で public にできる(プロトコルは HTTP)
Wiki が Git でアクセスできる!(GitHub の Gollum という Wiki エンジンが使われているらしい)
「ローカルで編集 → Git で Push」で Wiki が更新できる