LoginSignup
37
37

More than 5 years have passed since last update.

OS X Mountain LionにGitLab 5.0をインストールする

Last updated at Posted at 2013-04-03

公式のインストール用ドキュメントと、以下のブログ記事を参考にまとめました。
rbenvを使用したり、Ruby 2.0を使ったり、SSHとHTTPのどちらでもclone, push等できるようにするのにかなり苦労しました。。

以下、プロンプトは基本、admin権限のユーザーでの実行です。
便宜上、マシン名をgitlab_server.localとします。

準備

後でgitユーザーのホームディレクトリを作成するため、/home以下を編集可能にする。

$ sudo vi /etc/auto_master

/homeの行をコメントアウトする。

#
# Automounter master map
#

+auto_master            # Use directory service
/net                    -hosts          -nobrowse,hidefromfinder,nosuid
# /home                 auto_home       -nobrowse,hidefromfinder
/Network/Servers        -fstab
/-                      -static

設定を反映させるため、マシンを再起動する。

Homebrew

何はなくともまずはHomebrew。

$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

各種パッケージ

$ brew install git

$ brew install redis
# 自動でサービス起動するようにする
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

# gem charlock_holmes 周りで必要
$ brew install icu4c
$ brew link icu4c --force

# python2がないと動かない
$ sudo ln -s /usr/bin/python /usr/bin/python2

ユーザー

# 空いているグループIDを調べる。200番台あたりを使用する。
$ sudo dscl . -list /Groups PrimaryGroupID | cut -c 32-38 | sort -rn
# 空いているユーザーIDを調べる。200番台あたりを使用する。
$ sudo dscl . -list /Users UniqueID | cut -c 23-28 | sort -rn

$ sudo dscl . -create /Groups/git PrimaryGroupID <空いているグループID>

$ sudo dscl . -create /Users/git UniqueID <空いているユーザーID>
$ sudo dscl . -create /Users/git PrimaryGroupID <空いているグループID>
$ sudo dscl . -create /Users/git UserShell /bin/bash
$ sudo dscl . -create /Users/git NFSHomeDirectory /home/git
$ sudo dscl . -create /Users/git Password "*"

$ sudo mkdir /home/git
$ sudo chown -R git:git /home/git
$ sudo chmod 755 /home/git
$ sudo -i -u git
$ cd

# SSHでのログイン時を考慮
$ vi .bash_profile
$ vi .bashrc

$ exit
/home/git/.bash_profile
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
/home/git/.bashrc
export PATH=/usr/local/bin:$PATH
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi

git

$ sudo -i -u git

$ git config --global user.name "GitLab"
$ git config --global user.email "gitlab@localhost"

$ exit

Ruby

$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' > ~/.bashrc
$ . ~/.bashrc

$ brew install rbenv ruby-build

# for admin user

$ rbenv install 2.0.0-p0
$ rbenv global 2.0.0-p0
$ ruby -v
# -> ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.3.0]

$ gem install bundler
$ rbenv rehash

# for git user

$ sudo -i -u git

$ rbenv install 2.0.0-p0
$ rbenv global 2.0.0-p0
$ rbenv rehash

$ ruby -v
# -> ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.3.0]

$ exit

SSH

この辺りは適宜設定する。

$ sudo /etc/sshd_config
PermitRootLogin no

GitLab shell

$ sudo -i -u git
$ cd

$ git clone https://github.com/gitlabhq/gitlab-shell.git
$ cd gitlab-shell

# 特定バージョンをチェックアウト
$ git checkout v1.1.0
$ git checkout -b v1.1.0

# gitlab_urlを"http://gitlab_server.local/"に変更
$ cp config.yml.example config.yml
$ vim config.yml

# セットアップを実行
$ ./bin/install

$ exit

データベース

$ brew install mysql
# サービス起動
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

# ルートパスワードの設定、他ホストからのルートログインの禁止、アノニマスユーザーを削除、テストデータベースを削除。
# インストール直後で初期ルートパスワードは空のため、最初のプロンプトはEnterを押す。
$ cd
$ mysql_secure_installation

# MySQLにログイン
$ mysql -u root -p

# gitlabユーザーを作成($passwordにパスワード)
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$password';

# プロダクション用のデータベースを作成
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

# gitlabユーザーに権限を付与
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

# ログアウト
mysql> quit

# gitlabユーザーでデータベースに接続してみる
$ sudo -u git -H mysql -u gitlab -p -D gitlabhq_production

GitLab

リポジトリを引っ張ってくる。

$ sudo -i -u git
$ cd

$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab

# 5.0用ブランチをチェックアウト
$ cd gitlab
$ git checkout 5-0-stable

# 設定ファイルを編集
$ cp config/gitlab.yml.example config/gitlab.yml
$ vi config/gitlab.yml

# gitユーザーでチェックアウトできていれば問題ないはずだが、
# log, tmpの各ディレクトリの所有者・所有権をチェック
$ chown -R git log/
$ chown -R git tmp/
$ chmod -R u+rwX  log/
$ chmod -R u+rwX  tmp/

# Create directory for satellites
$ mkdir ~/gitlab-satellites

# プロセスID用のディレクトリ
$ mkdir tmp/pids/
$ chmod -R u+rwX  tmp/pids/

# Unicorn用の設定ファイルをコピー
$ cp config/unicorn.rb.example config/unicorn.rb
/home/git/gitlab/config/gitlab.yml


gitlab:
  host: gitlab_server.local

...

# Homebrewでインストールしたgitを使用する
git:
  bin_path: /usr/local/bin/git


MySQLの設定

# Mysql
$ cp config/database.yml.mysql config/database.yml
# ユーザー名、パスワードを変更する
$ vi config/database.yml
# gitユーザーを終える
$ exit

Gemのインストール

$ cd ~git/gitlab

$ gem install charlock_holmes --version '0.6.9'
$ rbenv rehash

# For MySQL (note, the option says "without")
$ sudo -u git -H bundle install --deployment --without development test postgres

データベースのセットアップ

$ sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

起動用スクリプトの用意

$ sudo curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab
$ sudo chmod +x /etc/init.d/gitlab

設定状況の確認

$ sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
$ sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

Assets Pipeline

$ sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

アプリを起動する

$ sudo /etc/init.d/gitlab start
$ sudo /etc/init.d/gitlab status
# -> Gitlab service / Unicorn with PID <プロセスID> is running.
     Gitlab service / Sidekiq with PID <プロセスID> is running.

Nginx

リバースプロキシとしてnginxを使用。

$ brew install nginx
$ vi /usr/local/etc/nginx/nginx.conf
/usr/local/etc/nginx/nginx.conf
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    include /usr/local/etc/nginx/sites-enabled/*; #追加する

    #これより以下はばっさり削除

}
$ mkdir /usr/local/etc/nginx/sites-available
$ mkdir /usr/local/etc/nginx/sites-enabled
$ curl --output /usr/local/etc/nginx/sites-available/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/nginx/gitlab
$ ln -s /usr/local/etc/nginx/sites-available/gitlab /usr/local/etc/nginx/sites-enabled/gitlab
$ sudo mkdir /var/log/nginx

# YOUR_SERVER_IPとYOUR_SERVER_FQDNを変更する。
# YOUR_SERVER_IPは消してポート番号のみでも問題ない。
# YOUR_SERVER_FQDNをgitlab_server.localに変更する。
$ vi /usr/local/etc/nginx/sites-available/gitlab

# 80番ポートでnginxを起動するために、rootユーザーで実行するようにする。
$ sudo cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist /Library/LaunchDaemons
# UserNameの箇所を削除する
$ sudo vi /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
$ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

結果

以上で、ローカルネットワーク内のMac, またiTunes(Bonjour for Windows)をインストール済みのWindowsマシンからも、http://gitlab_server.localでGitLabにアクセスできるはずです。

参考リンク

37
37
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
37
37