Last-modified: 2014-08-17 (日) 20:13:04
Redmine/Debianへのインストール

概要

Debianのリポジトリは古いので、Redmineをソースから導入します。
Redmine公式サイトの手順を少しだけ参考にします。
https、サブディレクトリ、MariaDB、basic認証、Unicorn環境を構築します。
ここでは、以下のサンプルURLを使用します。
https://hoge.paburica.com/redmine
先にこちらを見たほうが、全体像が掴めるかもしれません。
Nginx/Gitlab,Redmine,Jenkinsサブディレクトリ構成の設定

手順

  1. 前準備
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    
    -
    !
     
     
    -
    !
     
    -
    !
     
    -
    !
     
     
    -
    !
     
    -
    !
    -
    !
    -
    !
     
    -
    !
    -
    |
    !
     
    -
    |
    !
     
     
     
     
     
    -
    !
     
     
     
     
     
     
     
     
    -
    !
    -
    !
     
    -
    !
    -
    !
     
    -
    !
     
     
     
     
     
     
     
     
    -
    !
    -
    !
     
     
     
    -
    !
     
     
    -
    -
    |
    |
    |
    |
    |
    -
    !
    -
    !
    -
    !
    -
    |
    |
    |
    |
    |
    |
    |
    |
    !
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    -
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    |
    -
    !
    |
    -
    !
    
    # 最新の状態にする
    apt-get update -y
    apt-get upgrade -y
     
    # image-magicのインストール
    apt-get install imagemagick libmagickcore-dev libmagickwand-dev
     
    # システムユーザー(redmine)作成
    sudo adduser --disabled-login --gecos 'Redmine' redmine
     
    # redmine取得
    sudo -u redmine -H git clone https://github.com/redmine/redmine.git -b 2.5-stable redmine
    cd redmine
     
    # .bundle/config編集
    vi .bundle/config
    BUNDLE_PATH: vendor/bundle
    # システムにインストールしたgemは使わない
    BUNDLE_DISABLE_SHARED_GEMS: '1'
    # ここまで(.bundle/config)
     
    # Gemfile.local作成
    sudo -u redmine vi Gemfile.local
    gem 'unicorn'
    # ここまで(Gemfile.local)
     
    # gemインストール
    # -j<CPUコア数>で並列実行するので早く終わる
    sudo -u redmine -H bundle install -j3 --without development test postgresql sqlite
     
    # DBはMariaDBが入っているのでインストールスキップ
    # DBセットアップ
    mysql -u root -p
    create database redmine character set utf8;
    create user 'redmine'@'localhost' identified by '<パスワード>';
    grant all privileges on redmine.* to 'redmine'@'localhost';g
    quit
     
    # database.yml編集
    sudo -u redmine cp config/database.yml.example config/database.yml
    vi config/database.yml
    production:
      adapter: mysql2
      database: redmine
      host: localhost
      username: redmine
      password: "<MariaDBのredmineユーザーパスワード>"
      encoding: utf8
    # ここまで(database.yml)
     
    # セッションストア秘密鍵を生成
    sudo -u redmine bundle exec rake generate_secret_token
     
    # DB初期化
    sudo -u redmine bundle exec rake db:migrate RAILS_ENV=production
    # jaと入力
    sudo -u redmine bundle exec rake redmine:load_default_data RAILS_ENV=production
     
    # Unicorn設定
    sudo -u redmine wget -O config/unicorn.rb https://raw.github.com/defunkt/unicorn/master/examples/unicorn.conf.rb
    vi config/unicorn.rb
    worker_processes 1   # 環境に合わせる
    working_directory "/home/redmine/redmine" # available in 0.94.0+
    listen "/home/redmine/redmine/tmp/sockets/redmine.socket", :backlog => 64
    listen 8084, :tcp_nopush => true   # 他と被らないポート番号にする
    pid "/home/redmine/redmine/tmp/pids/unicorn.pid"
    stderr_path "/home/redmine/redmine/log/unicorn.stderr.log"
    stdout_path "/home/redmine/redmine/log/unicorn.stdout.log"
    # ここまで(config/unicorn.rb)
     
    # ディレクトリ調整
    sudo -u redmine mkdir -p tmp/sockets tmp/pids public/plugin_assets 
    sudo -u redmine chown -R redmine:redmine files log tmp public/plugin_assets
    sudo -u redmine chmod -R 755 files log tmp public/plugin_assets
     
    # config.ru編集
    vi /var/lib/redmine/config.ru
    require ::File.expand_path('../config/environment',  __FILE__)
     
    if ENV['RAILS_RELATIVE_URL_ROOT']
      map ENV['RAILS_RELATIVE_URL_ROOT'] do
        run RedmineApp::Application
      end
    else
      run RedmineApp::Application
    end
    # ここまで(config.ru)
     
    # /etc/init.d/redmine作成
    vi /etc/init.d/redmine
    #!/bin/sh
     
    ### BEGIN INIT INFO
    # Provides:           redmine
    # Required-Start:
    # Required-Stop:
    # Default-Start:      2 3 4 5
    # Default-Stop:       0 1 6
    # Short-Description:
    # Description:
    ### END INIT INFO
     
    set -u
    set -e
     
    APP_USER=redmine
    APP_NAME=redmine
    APP_ROOT="/home/redmine/$APP_NAME"
    CONFIGS="$APP_ROOT/config/unicorn.rb"
    PID="$APP_ROOT/tmp/pids/unicorn.pid"
    ENV=production
     
    UNICORN_OPTS="-D -E $ENV -c $CONFIGS --path /redmine"
     
    old_pid="$PID.oldbin"
     
    cd $APP_ROOT || exit 1
     
    sig(){
      test -s "$PID" && kill -$1 `cat $PID`
    }
     
    oldsig(){
      test -s $old_pid && kill -$1 `cat $old_pid`
    }
     
    case $1 in
    start)
      sig 0 && echo >&2 "Already running" && exit 0
      cd $APP_ROOT ; sudo -u $APP_USER bundle exec unicorn_rails $UNICORN_OPTS
      ;;
    stop)
      sig QUIT && exit 0
      echo >&2 "Not running"
      ;;
    force-stop)
      sig TERM && exit 0
      echo >&2 "Not running."
      ;;
    restart|reload)
      sig HUP && echo reloaded OK && exit 0
      echo >&2 "Couldn't reload, starting instead"
      sudo -u $APP_USER bundle exec unicorn_rails $UNICORN_OPTS
      ;;
    upgrade)
      sig USR2 && exit 0
      echo >&2 "Couldn't upgrade, starting instead"
      sudo -u $APP_USER bundle exec unicorn_rails $UNICORN_OPTS
      ;;
    rotate)
      sig USR1 && echo rotated logs OK && exit 0
      echo >&2 "Couldn't rotate logs" && exit 1
      ;;
    *)
      echo >&2 "Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>"
      exit 1
      ;;
    esac
    # ここまで(/etc/init.d/redmine)
    update-rc.d -f redmine defaults
     
    # 起動
    service redmine restart
  2. Nginxのサイト設定を行います。
    Nginx/Gitlab,Redmine,Jenkinsサブディレクトリ構成の設定

補足1

ログローテートの設定もしてください。
redmine自体にも機能があるらしいですが、私はlogrotateで行うようにしました。

検証時の環境