Gitlabを会社でインストールした時のメモ。基本的には以下のサイトを翻訳したレベル
https://github.com/gitlabhq/gitlab-recipes/tree/master/install/centos
前提条件
※EPELとPUIAS_6のリポジトリを利用可能な状態であること
インストール手順
Gitlabに必要なパッケージをインストール
# yum groupinstall 'Development Tools'
# yum install readline-devel ncurses-devel tcl-devel openssl-devel curl-devel expat-devel sqlite-devel libffi-devel libxml2-devel libxslt libxslt-devel libicu libicu-devel python-devel logwatch git
# yum install --enablerepo=epel redis
# yum install --enablerepo=epel libyaml libyaml-devel
# yum install mysql-server mysql-devel
# yum install --enablerepo=epel nginx
redisを自動起動設定後、起動
# chkconfig redis on
# service redis start
Rubyのインストール
各バージョンは https://www.ruby-lang.org/ja/downloads/ から確認
# mkdir /tmp/ruby && cd /tmp/ruby
# curl --progress http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz
# cd ruby-2.0.0-353
# ./configure --prefix=/usr/local/
# ./configure
# make && make install
# which ruby
バージョン確認
GemでBundlerのインストール
# gem install bundler --no-ri --no-rdoc
# gem install charlock_holmes --version '0.6.9.4'
MySQLのセットアップ
自動起動
起動
セキュアセットアップ(Rootパスワードの設定以外は、すべてYでよい)
# /usr/bin/mysql_secure_installation
Gitlab用のDBの作成
# mysql -u root -p
> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'ぱすわーど';
> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
> \q
作成したDBの接続テスト
# mysql -u gitlab -p -D gitlabhq_production
> \q
Gitユーザーの追加
# adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
GitLab Shellのインストール
# su - git
$ git clone https://github.com/gitlabhq/gitlab-shell.git
$ cd gitlab-shell
$ git checkout v1.7.4
$ cp config.yml.example config.yml
$ ./bin/install
Gitlabのインストール
# su - git
$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
$ cd /home/git/gitlab
最新の安定版のブランチをチェックアウト
$ git checkout 6-3-stable
設定ファイルを修正
$ cp config/gitlab.yml.example config/gitlab.yml
$ sed -i 's|localhost|GitLabURL|g' config/gitlab.yml
※ sedでlocalhostsを一括置換した。config/gitlab.yml は適宜修正する
$ mkdir /home/git/gitlab-satellites
$ mkdir tmp/pids/
$ mkdir tmp/sockets/
$ chmod -R u+rwX tmp/pids/
$ chmod -R u+rwX tmp/sockets/
$ mkdir public/uploads
$ chmod -R u+rwX public/uploads
$ cp config/unicorn.rb.example config/unicorn.rb
※ サーバースペックに応じて config/unicorn.rb を修正
※ 参考)2GM以上のRAMがあれば、workerの数を3程度にする
GitLabユーザー用のGitの設定を行う
$ git config --global user.name "GitLab Username"
$ git config --global user.email "test@example.com"
$ git config --global core.autocrlf input
データベース用の設定
$ cp config/database.yml{.mysql,}
$ vi config/database.yml
※Gitlab用に用意したDBの値に修正
$ chmod o-rwx config/database.yml
Bundleインストール
# cd /home/git/gitlab/
# bundle install --deployment --without development test postgres puma aws
データベースの初期化
$ su - git
$ cd /home/git/gitlab
$ bundle exec rake gitlab:setup RAILS_ENV=production
起動スクリプトの設定
# wget -O /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn
# chmod +x /etc/init.d/gitlab
# chkconfig --add gitlab
# chkconfig gitlab on
現在の設定を確認
# su - git
$ cd gitlab/
$ bundle exec rake gitlab:env:info RAILS_ENV=production
------------------------
System information
System: CentOS release 6.5 (Final)
Current User: git
Using RVM: no
Ruby Version: 2.0.0p353
Gem Version: 2.0.14
Bundler Version:1.3.5
Rake Version: 10.1.0
GitLab information
Version: 6.3.1
Revision: 779b4dc
Directory: /home/git/gitlab
DB Adapter: mysql2
URL: http://gitlabのURL
HTTP Clone URL: http://gitlabのURL/some-project.git
SSH Clone URL: git@サーバー:some-project.git
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version: 1.7.4
Repositories: /home/git/repositories/
Hooks: /home/git/gitlab-shell/hooks/
Git: /usr/bin/git
------------------------
Gitlabを起動
再度ステータスを確認
# su - git
$ cd gitlab/
$ bundle exec rake gitlab:env:info RAILS_ENV=production
------------------------
System information
System: CentOS release 6.5 (Final)
Current User: git
Using RVM: no
Ruby Version: 2.0.0p353
Gem Version: 2.0.14
Bundler Version:1.3.5
Rake Version: 10.1.0
GitLab information
Version: 6.3.1
Revision: 779b4dc
Directory: /home/git/gitlab
DB Adapter: mysql2
URL: http://gitlabのURL
HTTP Clone URL: http://gitlabのURL/some-project.git
SSH Clone URL: git@サーバー:some-project.git
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version: 1.7.4
Repositories: /home/git/repositories/
Hooks: /home/git/gitlab-shell/hooks/
Git: /usr/bin/git
------------------------
Nginxの設定
自動起動を有効にしておく
設定ファイル用のディレクトリを作成
# mkdir /etc/nginx/sites-{available,enabled}
Gitlabからサンプルをとってきて、設定ファイルを作成
# wget -O /etc/nginx/sites-available/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/web-server/nginx/gitlab-ssl
# ln -sf /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
設定ファイルの修正
# vi /etc/nginx/nginx.conf
コメントアウト------------
#include /etc/nginx/conf.d/*.conf;
追記--------------
include /etc/nginx/sites-enabled/*;
-------------------
# vi /etc/nginx/sites-available/gitlab
git.example.com を GitlabのURL に置き換え
nginxのユーザーをgitグループに追加
# usermod -a -G git nginx
# chmod g+rx /home/git/
HTTPSで接続する予定なので、自己証明書を作成しておく。
# cd /etc/nginx
# openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
Nginxの起動
gitlab-shell の設定の修正
# vi /home/git/gitlab-shell/config.yml
--------------------
gitlab_url: "https://gitlabのURL" ← URLを修正
http_settings:
# user: someone
# password: somepass
ca_file: /etc/nginx/gitlab.crt ← 証明書のパス
ca_path: /etc/nginx ← 証明書のディレクトリ
self_signed_cert: true ← 自己認証証明書の場合True
接続
https://gitlabのURL/ に接続してGitlabを利用開始