:::: MENU ::::

CentOS6.3にGitlab5.3をインストールする

ひさしぶりに Gitlab を入れ直してみる。
バージョンが上がってだいぶ使いやすくなっているとの噂。
Redmine も ruby1.9 で使えるようになったので、共存とか気にせず入れる。

以下のサイトを参考に入れてみた。

事前に入れておくもの

ruby1.9 のインストールは省略

radis のインストール

# yum install redis
# /etc/init.d/redis start
# chkconfig redis on

入れておかないと bundle でこけるはず

# yum --enablerepo=epel install libicu-devel
# gem install charlock_holmes --version '0.6.9' --with-icu-dir/usr/share/icu/4.2.1/ --no-rdoc --no-ri

git ユーザ作成

# useradd -c 'GitLab' -s /bin/bash git
# su - git
$ cd /home/git
$ mkdir .ssh
$ touch .ssh/authorized_keys
$ chmod 600 .ssh/authorized_keys
$ chmod 700 .ssh
$ git config --global user.name  "GitLab"
$ git config --global user.email "gitlab@localhost"

gitlab-shell のインストール

$ git clone https://github.com/gitlabhq/gitlab-shell.git
$ cd gitlab-shell/
$ git checkout v1.5.0
$ git checkout -b v1.5.0
Switched to a new branch 'v1.5.0'

$ cp config.yml.example config.yml
$ vi config.yml
gitlab_url: "http://gitlab.hogehoge.com/"

$ ./bin/install
mkdir -p /home/git/repositories: true
mkdir -p /home/git/.ssh: true
chmod 700 /home/git/.ssh: true
touch /home/git/.ssh/authorized_keys: true
chmod 600 /home/git/.ssh/authorized_keys: true
chmod -R ug+rwX,o-rwx /home/git/repositories: true
find /home/git/repositories -type d -print0 | xargs -0 chmod g+s: true

gitlab 用のデータベースを作成

$ mysql -u root -p
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
Query OK, 1 row affected (0.03 sec)

mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost' identified by 'gitpass';
Query OK, 0 rows affected (0.07 sec)

gitlab のインストール

# su - git
$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
$ cd gitlab
$ git checkout 5-3-stable
Branch 5-3-stable set up to track remote branch 5-3-stable from origin.
Switched to a new branch '5-3-stable'

$ cp config/gitlab.yml.example config/gitlab.yml
$ vi config/gitlab.yml
host: gitlab.hogehoge.com
bin_path: /usr/local/bin/git

$ chown -R git log/
$ chown -R git tmp/
$ chmod -R u+rwX  log/
$ chmod -R u+rwX  tmp/
$ mkdir /home/git/gitlab-satellites
$ mkdir tmp/pids/
$ chmod -R u+rwX  tmp/pids/

$ cp config/database.yml.mysql config/database.yml
$ vi config/database.yml
username: gitlab
password: "gitpass"

$ bundle install --deployment --without development test postgres
Fetching source index from https://rubygems.org/
Fetching https://github.com/gitlabhq/raphael-rails.git
remote: Counting objects: 46, done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 46 (delta 7), reused 45 (delta 6)
Unpacking objects: 100% (46/46), done.
Installing rake (10.0.4)
Installing i18n (0.6.1)
...

$ bundle exec rake gitlab:setup RAILS_ENV=production
...
Administrator account created:

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

$ bundle exec rake gitlab:env:info RAILS_ENV=production

System information
System:         CentOS release 6.3 (Final)
Current User:   git
Using RVM:      no
Ruby Version:   1.9.3p374
Gem Version:    1.8.25
Bundler Version:1.3.5
Rake Version:   10.0.4

GitLab information
Version:        5.3.0
Revision:       148eade
Directory:      /home/git/gitlab
DB Adapter:     mysql2
URL:            http://gitlab.hogehoge.com
HTTP Clone URL: http://gitlab.hogehoge.com/some-project.git
SSH Clone URL:  git@gitlab.hogehoge.com:some-project.git
Using LDAP:     no
Using Omniauth: no

GitLab Shell
Version:        1.5.0
Repositories:   /home/git/repositories/
Hooks:          /home/git/gitlab-shell/hooks/
Git:            /usr/local/bin/git

$ bundle exec rake gitlab:check RAILS_ENV=production

起動シェルを取ってきて起動させる

$ su -
# curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab-centos
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
103  2166  103  2166    0     0   2402      0 --:--:-- --:--:-- --:--:--  9417

# chmod +x /etc/init.d/gitlab
# chkconfig gitlab on

passenger のインストール

# gem install passenger --no-rdoc --no-ri
# export APXS2=/usr/local/apache2/bin/apxs
# export PATH=/usr/local/apache2/bin:$PATH
# passenger-install-apache2-module

# cat /usr/local/apache2/conf/extra/gitlab.conf
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.5/libout/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.5
PassengerDefaultRuby /usr/local/bin/ruby

<VirtualHost *:80>
ServerAdmin hogehoge@localhost
DocumentRoot "/home/git/gitlab/public"
ServerName gitlab.hogehoge.com
ErrorLog "logs/gitlab-error_log"
CustomLog "logs/gitlab-access_log" combined env=!nolog
<Directory "/home/git/gitlab/public">
Options Includes FollowSymLinks -MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

gitlab に登録する公開鍵を作る

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hogehoge/.ssh/id_rsa): /home/hogehoge/.ssh/gitlab_id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hogehoge/.ssh/gitlab_id_rsa.
Your public key has been saved in /home/hogehoge/.ssh/gitlab_id_rsa.pub.
...

$ vi .ssh/config
$ cat .ssh/config
Host gitlab.hogehoge.com
User git
Hostname gitlab.hogehoge.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab_id_rsa

# cat /home/hogehoge/.ssh/gitlab_id_rsa.pub

公開鍵を Gitlab に登録。

git リポジトリを作って push してみる

$ git init
Initialized empty Git repository in /home/hogehoge/workspace/test/.git/
$ touch README
$ git add .
$ git remote add origin git@gitlab.hogehoge.com:root/test.git
$ git commit -m "first commit."
$ git push -u origin master

途中で起きたエラー集

puma.rb がなかった&sockets フォルダがなかった

# /etc/init.d/gitlab start
Starting puma: /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/shared_helpers.rb:2:in `require': no such file to load -- rubygems (LoadError)
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/shared_helpers.rb:2
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/setup.rb:1:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/setup.rb:1
[失敗]
Starting sidekiq: /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/shared_helpers.rb:2:in `require': no such file to load -- rubygems (LoadError)
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/shared_helpers.rb:2
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/setup.rb:1:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/setup.rb:1
[失敗]

$ cp config/puma.rb.example config/puma.rb
$ mkdir tmp/sockets

ruby が 2 つあった

ruby1.8 系は使ってないので消す

# which -a ruby
/usr/local/bin/ruby
/usr/bin/ruby

# yum remove ruby
Loaded plugins: fastestmirror, security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package ruby.x86_64 0:1.8.7.352-7.el6_2 will be erased
--> Finished Dependency Resolution
...

コミットし忘れていたときに起きるエラー

$ git push -u origin master
error: src refspec master does not match any.

$ git commit -m "first commit."
$ git push -u origin master

ssh のポートを変えていたときに起きるエラー

$ git push -u origin master
ssh: connect to host gitlab.14code.com port 22: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

$ vi .ssh/config
Host gitlab.hogehoge.com
User git
Hostname gitlab.hogehoge.com
Port 22022
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab_id_rsa