「インストール - Redmine」の版間の差分

提供:MochiuWiki - SUSE, Electronic Circuit, PCB
ナビゲーションに移動 検索に移動
162行目: 162行目:
<u>WEBrickは開発時に使用すものであり、通常の運用には適していないため、動作確認以外には使用しないこと。</u><br>
<u>WEBrickは開発時に使用すものであり、通常の運用には適していないため、動作確認以外には使用しないこと。</u><br>
<u>本番運用においては、Passenger(mod_rails)、FCGI、Rackサーバ(Unicorn, Thin, Puma,hellip等)の使用を推奨する。</u><br>
<u>本番運用においては、Passenger(mod_rails)、FCGI、Rackサーバ(Unicorn, Thin, Puma,hellip等)の使用を推奨する。</u><br>
<br><br>
== NginXとの連携 ==
==== NginXのインストール ====
NginXのビルドに必要なライブラリをインストールする。<br>
sudo zypper install libxslt-devel pcre2-devel gd-devel
                    libcurl-devel              # Passengerを使用する場合
                    kernel-source kernel-devel  # AIOを使用する場合
<br>
必要ならば、[https://www.openssl.org/source/ OpenSSLの公式Webサイト]にアクセスして、OpenSSL(1.X.Y)のソースコードをダウンロードする。<br>
ダウンロードしたファイルを解凍する。<br>
tar xf openssl-<バージョン>
<br>
* Digest認証モジュールを使用する場合
*: NginXのソースコードと一緒に配布されていないため、別途インストールする必要がある。<br>
*: [https://github.com/atomx/nginx-http-auth-digest Digest認証モジュールのGithub]にアクセスして、ソースコードをダウンロードする。<br>
*: ダウンロードしたファイルを解凍する。<br>
*: <code>tar xf nginx-http-auth-digest-<バージョン>.tar.gz</code>
*: <br>
*: または、<code>git clone</code>コマンドを実行して、ソースコードをダウンロードする。<br>
*: <code>git clone https://github.com/atomx/nginx-http-auth-digest.git</code>
<br>
[https://nginx.org/en/download.html NginXの公式Webサイト]にアクセスして、NginXのソースコードをダウンロードする。<br>
ダウンロードしたファイルを解凍する。<br>
tar xf nginx-<バージョン>.tar.xz
<br>
NginXおよびNginX向けPassangerをビルドおよびインストールする。<br>
passenger-install-nginx-module
<br>
手順が表示されるので、[Enter]キーを押下して次へ進む。<br>
ビルド環境の選択では、[Ruby]を選択して、[Enter]キーを押下する。<br>
<br>
NginXのソースコードがあるディレクトリを入力して、[Enter]キーを押下する。<br>
次に、NginXのインストールディレクトリを入力して、[Enter]キーを押下する。<br>
<br>
最後に、<code>configure</code>スクリプトのオプションを、以下に示すように指定する。<br>
改行文字(<code>\</code>)が使用できないことに注意する。<br>
--sbin-path=/<NginXのインストールディレクトリ>/sbin/nginx --conf-path=/<NginXのインストールディレクトリ>/etc/nginx.conf --pid-path=/<NginXのインストールディレクトリ>/nginx.pid --modules-path=/<NginXのインストールディレクトリ>/modules/ --error-log-path=/<NginXのインストールディレクトリ>/log/error.log --http-log-path=/<NginXのインストールディレクトリ>/log/access.log --lock-path=/<NginXのインストールディレクトリ>/nginx.lock --http-client-body-temp-path=/<NginXのインストールディレクトリ>/tmp --http-proxy-temp-path=/<NginXのインストールディレクトリ>/proxy --http-fastcgi-temp-path=/<NginXのインストールディレクトリ>/fastcgi --http-uwsgi-temp-path=/<NginXのインストールディレクトリ>/uwsgi --http-scgi-temp-path=/<NginXのインストールディレクトリ>/scgi --with-perl_modules_path=/<NginXのインストールディレクトリ>/Perl --with-threads --with-file-aio --with-pcre --with-pcre-jit --with-http_v2_module --with-http_ssl_module --with-http_addition_module --with-http_realip_module --with-http_flv_module --with-http_random_index_module --with-http_degradation_module --with-http_slice_module  --with-http_dav_module --with-http_mp4_module --with-http_xslt_module --with-http_xslt_module=dynamic --with-http_image_filter_module --with-http_image_filter_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_secure_link_module --with-http_stub_status_module --with-http_sub_module --with-http_perl_module --with-http_perl_module=dynamic --with-mail --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module --with-compat --user=<任意のユーザ名  例. nginx> --group=<任意のグループ名  例. nginx> --add-module=<Digest認証モジュールのソースコードがあるディレクトリ>
<br>
Passengerのビルドが開始する。<br>
ビルドに成功した時、<u>Passengerを組み込まれた</u>nginx.confの設定が表示される。<br>
<syntaxhighlight lang="nginx">
http {
  # ...略
  passenger_root /<NginX向けPassangerのインストールディレクトリ>/passenger-6.0.17;
  passenger_ruby /<Rubyのインストールディレクトリ>/bin/ruby-3_0;
  # ...略
}
</syntaxhighlight>
<br><br>
<br><br>



2023年2月9日 (木) 17:35時点における版

概要



Rubyのインストール

Rubyのビルドに必要なライブラリをインストールする。

sudo zypper install gcc gcc-c++ autoconf bison gperf libopenssl-devel libopenssl-1_1-devel libyaml-devel zlib-devel \
                    readline-devel libedit-devel gmp-devel libffi-devel rust cargo ruby2.5-devel


RubyのGithubにアクセスして、ソースコードをダウンロードする。
ダウンロードしたファイルを解凍する。

tar xf ruby-<バージョン>.tar.gz
cd ruby-<バージョン>


Rubyをビルドおよびインストールする。

./autogen.sh

mkdir build && cd build

../configure --prefix=<Rubyのインストールディレクトリ> --program-suffix=<サフィックス> --disable-install-doc
make -j $(nproc)
make install



Redmineのインストール

一般的に、最新のRedmineをインストールする。
Redmineは、6ヶ月ごとに新しいバージョンがリリースされており、実用的でかつ安定している。
リポジトリのtrunkからチェックアウトした開発版は、Ruby on Railsに精通し、かつ最新の開発に追従する必要がない限りは非推奨である。

また、trunkは正常に動作しないこともあるため、注意が必要である。

Redmineのインストール

Redmineの公式Webサイトにアクセスして、Redmineをダウンロードする。
ダウンロードしたファイルを展開して、任意のディレクトリに配置する。

空のデータベースとユーザの作成

  • MySQLの場合
CREATE DATABASE redmine CHARACTER SET utf8mb4;
CREATE USER 'redmine'@'localhost' IDENTIFIED BY '<パスワード>';
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';

※ MySQL 5.5.2以前の場合、utf8mb4ではなくutf8を指定すること。


  • PostgreSQLの場合
CREATE ROLE redmine LOGIN ENCRYPTED PASSWORD '<パスワード>' NOINHERIT VALID UNTIL 'infinity';
CREATE DATABASE redmine WITH ENCODING='UTF8' OWNER=redmine;


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

Redmineのインストールディレクトリにあるconfig/database.example.ymlファイルをコピーして、config/database.ymlファイルを作成する。
次に、config/database.ymlファイルを編集して、"production"環境用のデータベースの設定を行う。

  • MySQLの場合
production:
  adapter: mysql2
  database: <上記で作成したデータベース名  例. redmine>
  host: <上記で指定したホスト名  例. localhost>
  port: <ポート番号  例. 3306>
  username: <上記で作成したユーザ名  例. redmine>
  password: "<MySQLにおけるredmineユーザのパスワード>"
  encoding: utf8mb4
  pool: 5
  schema_search_path: public
  socket: <MySQLのソケットファイルのフルパス>


  • PostgreSQLの場合
production:
  adapter: postgresql
  database: <上記で作成したデータベース名  例. redmine>
  host: <上記で指定したホスト名  例. localhost>
  username: <上記で作成したユーザ名  例. redmine>
  password: "<PostgreSQLにおけるredmineユーザのパスワード>"
  encoding: utf8
  schema_search_path: <データベーススキーマ (デフォルト: public)>
  socket: <PostgreSQLのソケットファイルのフルパス>


Redmineに依存するソフトウェアのインストール

MySQL等を使用する場合、mysql2をインストールするために、~/.profileファイル等へMySQLへの環境変数PATHを追記する必要がある。

vi ~/.profile


# ~/.profileファイル

export PATH="/<MySQLのインストールディレクトリ>/bin"


Redmineは、RubyGemの依存関係を管理するために、Bundlerを使用している。
そのため、まず、Bundlerをインストールする。

gem install bundler
または
sudo gem install bundler


Redmineのインストールディレクトリに移動して、Redmineの実行に必要な全てのgemをインストールする。

bundle config set --local without 'development test'
bundle install
または
sudo bundle config set --local without 'development test'
sudo bundle install


データベースアダプタ

Redmineは、データベースの設定ファイルであるconfig/database.ymlファイルを読み取り、必要なデータベースアダプタを自動的にインストールする。
(例. mysql2のみを使用するように設定した場合は、mysql2 gemのみがインストールされる)
もし、config/database.ymlファイルを編集してデータベースアダプタの追加や削除を行った後は、必ず、bundle install --without development test ...略を実行する。

独自の依存関係の設定 (Gemfile.local)

もし、Redmine本体が使用しないgem(例. puma、fcgi)もロードする場合は、Gemfile.localファイルをRedmineのインストールディレクトリに作成する。
これは、bundle installコマンド実行時にインストールされる。

# Gemfile.localファイル

gem 'puma'


セッションストア秘密鍵の生成

Railsはセッションハイジャックを防ぐため、セッション情報を格納するcookieをエンコードしている。
この処理で使用されるランダムなキーを生成する。

bundle exec rake generate_secret_token


また、秘密鍵は、config/secrets.ymlファイルに格納することもできる。

データベースのテーブル等の作成

データベースに、Redmineに必要なテーブルを作成する。

Redmineのインストールディレクトリに移動して、以下に示すコマンドを実行する。
これにより、マイグレーションが1つずつ実行およびテーブルが作成されて、更に権限のデータ一式と管理者アカウント(admin)が作成される。

RAILS_ENV=production bundle exec rake db:migrate


デフォルトデータ

デフォルトデータをデータベースに追加する。

RAILS_ENV=production bundle exec rake redmine:load_default_data


各言語のデフォルトデータにおいて、言語の選択が求められる。
なお、上記のコマンドにおいて、REDMINE_LANGオプションを指定する場合、言語の選択を求められることなく自動的に処理が進められる。

RAILS_ENV=production REDMINE_LANG=en bundle exec rake redmine:load_default_data


ディレクトリおよびファイルのパーミッション

Redmineを実行するOSのユーザーは、以下に示すディレクトリの書き込み権限が必要である。

  • files (添付ファイルの保存ディレクトリ)
  • log (Redmineのログファイル @production.log@)
  • tmp (これらのディレクトリが無ければ作成すること)
  • tmp/pdf (これらのディレクトリが無ければ作成すること)
  • public/plugin_assets (プラグインが使用する画像やCSS)


例. redmineユーザとしてソフトウェアを実行する場合
mkdir -p tmp tmp/pdf public/plugin_assets
chown -R redmine:redmine files log tmp public/plugin_assets
chmod -R 755 files log tmp public/plugin_assets

※注意
これらのディレクトリが既に存在する場合(バックアップからリストアした場合等)、ファイルに実行権限が不可されていないことを確認する。
find files log tmp public/plugin_assets -type f -exec chmod -x {} +


Redmineの起動

WEBrickを使用してRedmineを起動する。

bundle exec rails server -e production


WEBrickが正常に起動した後、Webブラウザから http://localhost:3000/ にアクセスする。

デフォルトのシステム管理者アカウントは、以下の通りである。

  • ログインID
    admin
  • パスワード
    admin


※注意
WEBrickは開発時に使用すものであり、通常の運用には適していないため、動作確認以外には使用しないこと。
本番運用においては、Passenger(mod_rails)、FCGI、Rackサーバ(Unicorn, Thin, Puma,hellip等)の使用を推奨する。


NginXとの連携

NginXのインストール

NginXのビルドに必要なライブラリをインストールする。

sudo zypper install libxslt-devel pcre2-devel gd-devel
                    libcurl-devel               # Passengerを使用する場合
                    kernel-source kernel-devel  # AIOを使用する場合


必要ならば、OpenSSLの公式Webサイトにアクセスして、OpenSSL(1.X.Y)のソースコードをダウンロードする。
ダウンロードしたファイルを解凍する。

tar xf openssl-<バージョン>


  • Digest認証モジュールを使用する場合
    NginXのソースコードと一緒に配布されていないため、別途インストールする必要がある。
    Digest認証モジュールのGithubにアクセスして、ソースコードをダウンロードする。
    ダウンロードしたファイルを解凍する。
    tar xf nginx-http-auth-digest-<バージョン>.tar.gz

    または、git cloneコマンドを実行して、ソースコードをダウンロードする。
    git clone https://github.com/atomx/nginx-http-auth-digest.git


NginXの公式Webサイトにアクセスして、NginXのソースコードをダウンロードする。
ダウンロードしたファイルを解凍する。

tar xf nginx-<バージョン>.tar.xz


NginXおよびNginX向けPassangerをビルドおよびインストールする。

passenger-install-nginx-module


手順が表示されるので、[Enter]キーを押下して次へ進む。
ビルド環境の選択では、[Ruby]を選択して、[Enter]キーを押下する。

NginXのソースコードがあるディレクトリを入力して、[Enter]キーを押下する。
次に、NginXのインストールディレクトリを入力して、[Enter]キーを押下する。

最後に、configureスクリプトのオプションを、以下に示すように指定する。
改行文字(\)が使用できないことに注意する。

--sbin-path=/<NginXのインストールディレクトリ>/sbin/nginx --conf-path=/<NginXのインストールディレクトリ>/etc/nginx.conf --pid-path=/<NginXのインストールディレクトリ>/nginx.pid --modules-path=/<NginXのインストールディレクトリ>/modules/ --error-log-path=/<NginXのインストールディレクトリ>/log/error.log --http-log-path=/<NginXのインストールディレクトリ>/log/access.log --lock-path=/<NginXのインストールディレクトリ>/nginx.lock --http-client-body-temp-path=/<NginXのインストールディレクトリ>/tmp --http-proxy-temp-path=/<NginXのインストールディレクトリ>/proxy --http-fastcgi-temp-path=/<NginXのインストールディレクトリ>/fastcgi --http-uwsgi-temp-path=/<NginXのインストールディレクトリ>/uwsgi --http-scgi-temp-path=/<NginXのインストールディレクトリ>/scgi --with-perl_modules_path=/<NginXのインストールディレクトリ>/Perl --with-threads --with-file-aio --with-pcre --with-pcre-jit --with-http_v2_module --with-http_ssl_module --with-http_addition_module --with-http_realip_module --with-http_flv_module --with-http_random_index_module --with-http_degradation_module --with-http_slice_module  --with-http_dav_module --with-http_mp4_module --with-http_xslt_module --with-http_xslt_module=dynamic --with-http_image_filter_module --with-http_image_filter_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_secure_link_module --with-http_stub_status_module --with-http_sub_module --with-http_perl_module --with-http_perl_module=dynamic --with-mail --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module --with-compat --user=<任意のユーザ名  例. nginx> --group=<任意のグループ名  例. nginx> --add-module=<Digest認証モジュールのソースコードがあるディレクトリ>


Passengerのビルドが開始する。
ビルドに成功した時、Passengerを組み込まれたnginx.confの設定が表示される。

 http {
   # ...略
 
   passenger_root /<NginX向けPassangerのインストールディレクトリ>/passenger-6.0.17;
   passenger_ruby /<Rubyのインストールディレクトリ>/bin/ruby-3_0;
 
   # ...略
 }



Apache2との連携

Phusion Passengerとは

Railsシステムを実行するためのApacheモジュールである。

メリット

Redmine等のRuby on RailsシステムをPhusion Passenger(mod_rails for Apache)を使用して、Apache上で稼働させる。
これにより、運用の簡素化、複数インスタンスを並列稼働させることによるレスポンスの改善が期待できる。

特徴

  • Apache2を起動するだけでRailsシステムが使用できる。
    Apache2のモジュールとして実装されており、別途デーモンを起動する必要が無い。
    Railsシステム用の起動スクリプトは不要である。
  • TCPポートを消費しない。
  • Railsシステムのデプロイが簡素化される。(PHPのように、ファイルのアップロードのみで出来る)
  • サーバのメモリが節約できる。
    Railsインスタンスは必要なタイミングで生成する。
    また、一定時間アクセスがなければ、インスタンスを終了させる。


手順

インストール手順は、次の通りである。

  • ビルドに必要なライブラリをインストールする。
  • Ruby向けにPassengerをインストールする。
  • Apache2向けのPassangerモジュールをビルドする。
  • httpd.confを変更する。
  • 仮想ホストとして構築する場合は、仮想ホストファイルを作成する。


ビルドに必要なライブラリのインストール

sudo zypper install libcurl-devel


Ruby向けPassengerのインストール

gem install passenger


Apache2向けPassangerモジュールのビルド

Apache2をソースコードからビルドおよびインストールしている場合、環境変数APXS2および環境変数PATHを手動で設定する必要がある。
これにより、Apache2のヘッダファイル、APRを探索してインストールすることができる。

# ~/.profileファイル

export APXS2=/<Apache2のインストールディレクトリ>/bin/apxs
export PATH=/<Apache2のインストールディレクトリ>/bin:$PATH


Apache2向けのPassangerモジュールをビルドする。

passenger-install-apache2-module


手順が表示されるので、[Enter]キーを押下して次へ進む。
ビルド環境の選択では、[Ruby]を選択して、[Enter]キーを押下する。
Passengerのビルドが開始する。

ビルドに成功した時、Passengerを組み込むためのhttpd.confの設定が表示される。

# 出力例

LoadModule passenger_module /<Rubyのインストールディレクトリ>/lib64/ruby/gems/<Rubyのバージョン>/gems/passenger-<Passengerのバージョン>/buildout/apache2/mod_passenger.so  
<IfModule mod_passenger.c>                                                                                                                          
  PassengerRoot /<Rubyのインストールディレクトリ>/lib64/ruby/gems/<Rubyのバージョン>/gems/passenger-<Passengerのバージョン>
  PassengerDefaultRuby /<Rubyのインストールディレクトリ>/bin/ruby
</IfModule>


Apache2の設定 (httpd.confファイルの変更)

Apache2の設定ファイル(httpd.conf)において、上記セクションに記述したPassengerを組み込むための設定を追記する。

 # httpd.confファイル (設定例)
 
 # ...略
 
  LoadModule passenger_module /<Rubyのインストールディレクトリ>/lib64/ruby/gems/<Rubyのバージョン>/gems/passenger-<Passengerのバージョン>/buildout/apache2/mod_passenger.so  
 <IfModule mod_passenger.c>                                                                                                                          
   PassengerRoot /<Rubyのインストールディレクトリ>/lib64/ruby/gems/<Rubyのバージョン>/gems/passenger-<Passengerのバージョン>
   PassengerDefaultRuby /<Rubyのインストールディレクトリ>/bin/ruby
 </IfModule>


仮想ホストとして構築する場合

 # vhost-redmine.confファイル (設定例)
 
 <VirtualHost *:80>
    ServerName  redmine
 
    # DocumentRoot: The directory out of which you will serve your
    # documents. By default, all requests are taken from this directory, but
    # symbolic links and aliases may be used to point to other locations.
    DocumentRoot /<Redmineのインストールディレクトリ>/public
 
    # if not specified, the global error log is used
    ErrorLog  /<Redmineのインストールディレクトリ>/log/redmine-error_log
    CustomLog /<Redmineのインストールディレクトリ>/log/redmine-access_log combined
 
    # don't loose time with IP address lookups
    HostnameLookups Off
 
    # needed for named virtual hosts
    UseCanonicalName Off
 
    # configures the footer on server-generated documents
    ServerSignature On
 
    # Redmineの画像ファイルおよびCSSファイル等へのアクセスを許可する設定
    # Apache 2.4のデフォルトではサーバ上の全ファイルへのアクセスが禁止されている
    <Directory "/<Redmineのインストールディレクトリ>/public">
        # Possible values for the Options directive are "None", "All",
        # or any combination of:
        #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
        # Note that "MultiViews" must be named *explicitly* --- "Options All"
        # doesn't give it to you.
        #
        # The Options directive is both complicated and important.  Please see
        # http://httpd.apache.org/docs/2.4/mod/core.html#options
        # for more information.
        Options Indexes FollowSymLinks
 
        # AllowOverride controls what directives may be placed in .htaccess files.
        # It can be "All", "None", or any combination of the keywords:
        #   Options FileInfo AuthConfig Limit
        AllowOverride None
 
        # Controls who can get stuff from this server.
        Require all granted
    </Directory>
 </VirtualHost>