9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Debian7.5にGitLab6.9をインストールしたメモ

Last updated at Posted at 2014-06-05

主に https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md を参考していますが、いろいろと引っ掛かるポイントが有ったので適宜メモの補足やカスタマイズを施してあります。あと、動作確認のノウハウなども。

なお、本メモにセキィリティの設定は含まれません。

要件

  • editorにvimは使わない(Debianのデフォルトのnanoのまま)
  • メール送信機能にはGmailを使う
  • データベースにはMySQLを使う
  • gemsはシステムにインストール
  • サブディレクトリで運用する
  • httpsを使う
  • Apacheのmod_proxyでunicornと連携する
  • アカウント管理にはローカルに立てたLDAPサーバを使う

インストール

インストールをほぼ自動化するために先にデフォルトのパスワードを変数に入れておく。

MYSQL_ROOT_PASSWORD="root"
MYSQL_GITLAB_PASSWORD="secure password"
#################################################################
# 1. Packages / Dependencies
#    - add: ruby-dev to install gems which require mkmf.
#    - add: libv8-dev and python to 'gem install libv8'
#    - add: sendmail
#    - add: apache2
#################################################################

aptitude update -y
aptitude upgrade -y

aptitude install sudo -y

aptitude install build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate ruby-dev libv8-dev python sendmail apache2 -y

aptitude install git-core -y

#################################################################
# 2. Ruby
#    - add: --no-ri --no-rdoc to /root/.gemrc
#    - add: rubygems-update
#################################################################

aptitude install ruby -y
echo 'gem: --no-ri --no-rdoc' >> /root/.gemrc
gem update
gem install rubygems-update
update_rubygems
gem install bundler

#################################################################
# 3. System Users
#################################################################

sudo adduser --disabled-login --gecos 'GitLab' git

#################################################################
# 4. Database
#    - select: MySQL
#    - use: $MYSQL_GITLAB_PASSWORD and $MYSQL_GITLAB_PASSWORD
#################################################################

aptitude install mysql-server mysql-client libmysqlclient-dev -y

mysql -u root -p$MYSQL_ROOT_PASSWORD << EOF
CREATE USER 'git'@'localhost' IDENTIFIED BY '$MYSQL_GITLAB_PASSWORD';
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 'git'@'localhost';
EOF

#################################################################
# 5. GitLab / 1. Initialization
#    - move: processes reuired editor are moved to the next step
#    - use: unicorn
#    - use: rack_attack
#    - use: mysql
#################################################################

# We'll install GitLab into home directory of the user "git"
cd /home/git

# Clone GitLab repository
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-9-stable gitlab

# Go to gitlab dir
cd /home/git/gitlab

# Copy the example GitLab config
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

# Make sure GitLab can write to the log/ and tmp/ directories
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX log/
sudo chmod -R u+rwX tmp/

# Create directory for satellites
sudo -u git -H mkdir /home/git/gitlab-satellites
sudo chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites

# Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories
sudo chmod -R u+rwX tmp/pids/
sudo chmod -R u+rwX tmp/sockets/

# Make sure GitLab can write to the public/uploads/ directory
sudo chmod -R u+rwX  public/uploads

# Copy the example Unicorn config
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

# Copy the example Rack attack config
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

# MySQL only:
sudo -u git cp config/database.yml.mysql config/database.yml

# PostgreSQL and MySQL:
# Make config/database.yml readable to git only
sudo -u git -H chmod o-rwx config/database.yml

#################################################################
# 5. GitLab / 2. Configuration
#    - use: $GITLAB_USER_NAME and $GITLAB_USER_EMAIL
#    - change: the ver. of spring is changed from 1.1.1 to 1.1.3
#              because it has a bug to run with rails s command.
#    - remove: --deployment option of 'bundle install' is removed
#              to install gems into system.
#    - add: 'yes' to 'rake gitlab:setup RAILS_ENV=production'
#################################################################

# Configure Git global settings for git user, useful when editing via web
# Edit user.email according to what is set in gitlab.yml

cd /home/git/gitlab
sudo -u git -H git config --global user.name  "GitLab"
sudo -u git -H git config --global user.email "example@example.com"
sudo -u git -H git config --global core.autocrlf input

# Install Gems
# Or if you use MySQL (note, the option says "without ... postgres")
bundle install --without development test postgres aws

# Install GitLab shell

# Go to the Gitlab installation folder:
cd /home/git/gitlab

# Run the installation task for gitlab-shell (replace `REDIS_URL` if needed):
sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.4] REDIS_URL=redis://localhost:6379 RAILS_ENV=production

# Initialize Database and Activate Advanced Features
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

# default admin account
# login.........admin@local.host
# password......5iveL!fe

# Install Init Script
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
sudo update-rc.d gitlab defaults 21

# Set up logrotate
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

# Check Application Status
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

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

動作確認

Rails Serverでの動作確認

とりあえず、Rails Serverをproduction環境で立ち上がるか確認する。デフォルトは3000番ポート。ブラウザでちょいとアクセスしてみる。

sudo -u git -H bundle exec rails s -e production

Unicornでの動作確認

次に、Unicornで立ち上がるか確認する。デフォルトの設定では127.0.0.1:8080でリッスンするので、外部から動作確認できるように、一時的に0.0.0.0:8080に変更する。ちなみに、1つ目のコメントアウトを忘れるとポート8080で二重でリッスンしようとして正しく起動しない。

config/unicorn.rb
# listen "127.0.0.1:8080", :tcp_nopush => true
listen "0.0.0.0:8080", :tcp_nopush => true

次に以下のコマンドを叩く。するとunicornsidekiqが立ち上がる。

/etc/init.d/gitlab start

デフォルトは8080番ポート。ブラウザでちょいとアクセスしてみる。

ちなみに、SidekiqはGitコマンドを叩いたりメール送信などに用いられているっぽい。Web画面 http://example.com:8080/admin/background_jobs からもジョブを確認できる。

ちなみにunicornsidekiqを叩くスクリプトの場所は以下のとおり。/etc/init.d/gitlabから叩かれる。

  • unicorn: script/web
  • sidekiq: script/background_jobs

以下のコマンドで各種設定項目のステータスをチェックできる。

cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

Sub URIへの変更

基本的にはconfig/application.rbの説明に従えばOK。

config/application.rb
    # Relative url support                                                                                                               
    # Uncomment and customize the last line to run in a non-root path                                                                    
    # WARNING: We recommend creating a FQDN to host GitLab in a root path instead of this.                                               
    # Note that following settings need to be changed for this to work.                                                                  
    # 1) In your application.rb file: config.relative_url_root = "/gitlab"                                                               
    # 2) In your gitlab.yml file: relative_url_root: /gitlab                                                                             
    # 3) In your unicorn.rb: ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"                                                                  
    # 4) In ../gitlab-shell/config.yml: gitlab_url: "http://127.0.0.1/gitlab"                                                            
    # 5) In lib/support/nginx/gitlab : do not use asset gzipping, remove block starting with "location ~ ^/(assets)/"                    
    #
    # To update the path, run: sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production                                    

ただし、以下のコマンドでassertsのプリコンパイルを行う必要があった。RAILS_RELATIVE_URL_ROOT/gitlabに指定してプリコンパイルする。その前にassets:cleantmp:cache:clearも忘れずに。ちなみに、プリコンパイルをしないと、assetsのコンパイルに時間がかかりすぎてタイムアウトする場合があるので、プリコンパイルは必要と思われる。

sudo -u git -H bundle exec rake assets:clean RAILS_ENV=production
sudo -u git -H bundle exec rake tmp:cache:clear RAILS_ENV=production
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production RAILS_RELATIVE_URL_ROOT=/gitlab

Apache2 + mod_proxy + Unicornでの動作確認

モジュールを有効化する。mod_headersはhttpsとhttpで受け渡しするのに必要。

a2enmod proxy
a2enmod proxy_http
a2enmod headers

Unicornの待ち受けポートに飛ばす。

ProxyRequests Off
ProxyPreserveHost On
RequestHeader set X_FORWARDED_PROTO 'https'
<Proxy *>
  Order deny,allow
  Allow from all
</Proxy>
ProxyPass /gitlab http://localhost:8080/gitlab
ProxyPassReverse /gitlab http://localhost:8080/gitlab

LDAP認証

LDAPサーバをローカルに立てているのでこんな感じに。uidにはログイン名につかう属性を指定するらしい。bind_dnpasswordは必要に応じて設定する。

config/gitlab.yml
ldap:
  enabled: true
  host: 'localhost'
  port: 389
  uid: 'uid'
  method: 'plain'
#  bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
#  password: '_the_password_of_the_bind_user'
  allow_username_or_email_login: true
  base: 'ou=people,dc=example,dc=net'
  user_filter: ''

LDAP認証をテストするには以下のコマンドを実行してユーザのDNがリストアップされればOK。

sudo -u git -H bundle exec rake gitlab:ldap:check RAILS_ENV=production
DN: uid=foo,ou=people,dc=example,dc=net uid: ["foo"]
DN: uid=bar,ou=people,dc=example,dc=net uid: ["bar"]
...

メール送信機能にGmailを使う

こんな感じで。

config/environments/production.rb
# config.action_mailer.delivery_method = :sendmail
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true 
config.action_mailer.smtp_settings = {
  :address => 'smtp.gmail.com',
  :port => 587,
  :authentication => :login,
  :user_name => 'username',
  :password => 'password'
}

タイムゾーンの設定

これをしておかないと、利用者へのメールによるアナウンス機能などの時間が見づらい。

config/application.rb
config.time_zone = 'Tokyo'

管理者ユーザの作成

  • LDAPで管理しているアカウントのどれかを管理者にしたい。
  • アカウント管理はLDAPだけで運用したい。
  1. 管理者にしたいLDAPのアカウントでログインしてログアウトする。するとGitLabにユーザとして登録される。
  2. デフォルトの管理者でログインして、1.でログインしたアカウントの設定画面で管理者のチェックボックスをオンにする。
  3. 以下の設定で、GitLabが独自に管理する新規アカウント作成機能&ログイン機能を停止する。
  4. 以降、LDAPで管理しているアカウントだけで運用する。
config/gitlab.yml
signup_enabled: false
signin_enabled: false

LDAPにトラブルが発生した状態でGitLab上でのメンテナンスが必要な場合は、上記設定を一時的に反転させて、GitLabが独自管理する管理者アカウントでログインして作業する。

再起動

service gitlab restart
service apache2 restart

更に細かい設定

  • config/database.yml
  • config/gitlab.yml
  • config/unicorn.rb
  • /home/git/gitlab-shell/config.yml

などなど。

9
9
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
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?