Raspbian StretchにRedmine

提供: オレッジベース
移動先: 案内検索

Rubyのインストール

RedmineはRubyで動いているらしい

$ sudo apt install -y ruby
$ ruby -v
ruby 2.3.3p222 (2016-11-21) [arm-linux-gnueabihf]

Railsのインストール

Railsというフレームワークを使っているらしい

$ sudo gem install rails

エラー発生

ERROR:  Error installing rails:
        ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/nokogiri-1.8.1/ext/nokogiri
/usr/bin/ruby2.3 -r ./siteconf20171226-14608-1mjalst.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

ruby-devをインストールすると解消されるらしい

$ sudo apt install -y ruby-dev
$ sudo gem install rails
$ rails -v
Rails 5.1.4

Bundlerのインストール

Redmineが使用するgemパッケージをインストールするのに使われるらしい

$ sudo gem install bundler --no-rdoc --no-ri
$ bundler -v
Bundler version 1.16.1

Apacheとヘッダファイルのインストール

$ sudo apt install -y apache2 apache2-dev libapr1-dev libaprutil1-dev

ImageMagickとヘッダファイル・日本語フォントのインストール

$ sudo apt install -y imagemagick libmagick++-dev fonts-takao-pgothic

エラー発生

E: パッケージ fonts-takao-pgothic が見つかりません

fonts-takao-pgothicはfonts-takao-gothicに含まれているっぽい

$ sudo apt install -y imagemagick libmagick++-dev fonts-takao-gothic
$ ls /usr/share/fonts/truetype/takao-gothic/
TakaoGothic.ttf  TakaoPGothic.ttf

Gitのインストール

$ sudo apt install -y git

DBの作成(MariaDB)

> CREATE DATABASE <DATABASE_NAME>;
> GRANT ALL PRIVILEGES ON <DATABASE_NAME>.* TO <USER_NAME>@<HOST>IDENTIFIED BY '<PASSWORD>';

Redmineのダウンロード

$ cd
$ wget http://www.redmine.org/releases/redmine-3.4.3.tar.gz
$ tar -zxvf redmine-3.4.3.tar.gz
$ sudo mkdir <PARENT_REDMINE_DIR>
$ sudo mv redmine-3.4.3 <PARENT_REDMINE_DIR>

データベースへの接続設定

$ cd <REDMINE_DIR>
$ cp config/database.yml.example config/database.yml
$ vim config/database.yml

以下を編集

production:
  adapter: mysql2
  database: <DATABASE_NAME>
  host: <HOST>
  username: <USER_NAME>
  password: "<PASSWORD>"
  encoding: utf8

他はコメントアウト

gemパッケージのインストール

$ bundle install --without development test

エラー発生

mysql client is missing. You may need to 'apt-get install libmysqlclient-dev' or 'yum install mysql-devel', and try
again.
...
An error occurred while installing mysql2 (0.4.10), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.4.10'` succeeds before bundling.
$ sudo apt install -y libmysqlclient-dev

エラー発生

E: パッケージ 'libmysqlclient-dev' にはインストール候補がありません

代わりにlibmariadbd-devをインストール

$ sudo apt install -y libmariadbd-dev

で、忘れそうになるけど、やりたかったのはこれ

$ bundle install --without development test

セッション改ざん防止用秘密鍵の作成

$ bundle exec rake generate_secret_token

バックアップデータをDBに流す

$ mysql -u <USER_NAME> -p<PASSWORD> -D <DATABASE_NAME> < <FILE_NAME>

Passengerのインストール

$ sudo gem install passenger --no-rdoc --no-ri

PassengerのApache用モジュールのインストール

$ sudo passenger-install-apache2-module --auto --languages ruby

エラー発生

...
 * Checking for Curl development headers with SSL support...
      Found: no
      Error: Cannot find the `curl-config` command.
...
 * Checking for OpenSSL development headers...
      Found: no
...
Installation instructions for required software

 * To install Curl development headers with SSL support:
   Please run apt-get install libcurl4-openssl-dev or libcurl4-gnutls-dev, whichever you prefer.

 * To install OpenSSL development headers:
   Please install it with apt-get install libssl-dev
...

libcurl4-openssl-devとlibssl-devをインストールすればいいらしい

$ sudo apt install -y libcurl4-openssl-dev libssl-dev

あらためて

$ sudo passenger-install-apache2-module --auto --languages ruby

Apache用設定内容の確認

$ passenger-install-apache2-module --snippet
LoadModule passenger_module /var/lib/gems/2.3.0/gems/passenger-5.1.12/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
  PassengerRoot /var/lib/gems/2.3.0/gems/passenger-5.1.12
  PassengerDefaultRuby /usr/bin/ruby2.3
</IfModule>

Apacheの設定

$ sudo vim /etc/apache2/conf-available/redmine.conf

以下の内容を記載

<Directory "<REDMINE_DIR>/public">
  Require all granted
</Directory>

LoadModule passenger_module /var/lib/gems/2.3.0/gems/passenger-5.1.12/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
  PassengerRoot /var/lib/gems/2.3.0/gems/passenger-5.1.12
  PassengerDefaultRuby /usr/bin/ruby2.3
</IfModule>

設定を反映

$ sudo a2enconf redmine

邪魔なconfをdisableに

$ sudo a2dissite 000-default.conf
$ sudo systemctl reload apache2
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/<CONF_FILE_NAME>.conf
$ sudo vim /etc/apache2/sites-available/<CONF_FILE_NAME>.conf

以下の内容を記載

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName <DOMAIN>
        ServerAdmin <MAIL_ADDRESS>
        DocumentRoot <REDMINE_DIR>/public

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

設定を反映

$ sudo a2ensite <CONF_FILE_NAME>
$ sudo systemctl reload apache2

プラグインの復旧

redmine_absolute_dates

日時表記を相対値から絶対値にするやつ

$ mv <PLUGIN_PATH> <REDMINE_DIR>/plugin/.
$ touch <REDMINE_DIR>/tmp/restart.txt

Redmineにアクセスすると再起動完了

$ rm <REDMINE_DIR>/tmp/restart.txt

redmine_issue_templates

チケット作成時にテンプレートを適用するやつ

$ mv <PLUGIN_PATH> <REDMINE_DIR>/plugin/.
$ touch <REDMINE_DIR>/tmp/restart.txt

Redmineにアクセスすると再起動完了

$ rm <REDMINE_DIR>/tmp/restart.txt

redmine_knowledgebase

ナレッジベース
新規に追加することはないだろうけど、過去に使ってたから一応

$ mv <PLUGIN_PATH> <REDMINE_DIR>/plugin/.
$ bundle install
$ touch <REDMINE_DIR>/tmp/restart.txt

Redmineにアクセスすると再起動完了

$ rm <REDMINE_DIR>/tmp/restart.txt

ディレクトリの所有者を変更してmigrate

$ sudo chown -R www-data:www-data <PARENT_REDMINE_DIR>
$ cd <REDMINE_DIR>
$ sudo -u www-data bundle install
$ sudo -u www-data RAILS_ENV=production bundle exec rake db:migrate
$ sudo systemctl reload apache2

メール通知の設定

$ sudo -u www-data cp <REDMINE_DIR>/config/configuration.yml.example <REDMINE_DIR>/config/configuration.yml
$ sudo vim <REDMINE_DIR>/config/configuration.yml

以下を記載
(outlook.comのサーバーを使用することを想定)

production:
  email_delivery:
    delivery_method: :smtp
    smtp_settings:
      enable_starttls_auto: true
      address: "<SMTP_SERVER>"
      port: 587
      domain: "<DOMAIN>"
      authentication: :login
      user_name: "<USER_NAME>"
      password: "<PASSWORD>"
$ sudo -u www-data touch <REDMINE_DIR>/tmp/restart.txt

Redmineにアクセスすると再起動完了

$ sudo -u www-data rm <REDMINE_DIR>/tmp/restart.txt