LoginSignup
40

More than 5 years have passed since last update.

CentOS 7 に Redmine 3.3 をインストールする

Last updated at Posted at 2017-04-26

CentOS への Redmine のインストール手順を解説する記事は Redmine.JP Blog の記事などがある1が、この記事ではなるべくパッケージを利用して Redmine をインストールする手順について解説する。

システム要件

RedmineInstall - Redmine

  • Ruby 1.9.3, 2.0.0, 2.1, 2.2, 2.3
  • MySQL 5.0 - 5.5
    • MySQL 5.6 以上と MariaDB には既知の問題がある
      • #19344 MySQL 5.6 / MariaDB 5.5 以降で IssueNestedSetConcurrencyTest#test_concurrency が失敗する
      • #25416 MySQL 8.0 で「個人設定(My account)」が表示されない
  • PostgreSQL 8.2 以上
  • Microsoft SQL Server 2012 以上

検証環境

  • VirtualBox 5.1.22
    • CentOS 7.3.1611 (minimal)
      • MySQL 5.7.18 (mysql57-community)
      • RHSCL 2.3 (centos-sclo-rh)
        • Ruby 2.3.1 (centos-sclo-rh)
        • Apache 2.4.18 (centos-sclo-rh)
        • Passenger 4.0.50 (centos-sclo-rh)
        • Git 2.9.3 (centos-sclo-rh)
      • Redmine 3.3.3 (GitHub)

インストール

アップデート

yum clean all && yum -y update && reboot

Red Hat Software Collections (RHSCL)

yum install -y centos-release-scl-rh

Ruby 2.3 をパッケージでインストールするために RHSCL 2.3 相当の centos-sclo-rh リポジトリを追加。
※ 4/5 に RHSCL 2.4 Beta がリリース2されて rh-ruby24 が追加されたので、そのうち centos-sclo-rh リポジトリでも使えるようになるかもしれない。

Ruby のインストール

yum -y install rh-ruby23 && source scl_source enable $_
echo -e '#!/bin/bash\nsource scl_source enable rh-ruby23' > /etc/profile.d/rh-ruby23.sh

centos-sclo-rh リポジトリで Ruby 2.3 が利用できる。
scl_source で rh-ruby23 コレクションを有効にする。3

MySQL 5.7 のインストール

yum -y install https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm && yum -y install mysql-community-server
echo -e '\ncharacter-set-server = utf8' >> /etc/my.cnf
systemctl start mysqld && systemctl enable $_
grep "temporary password" /var/log/mysqld.log | awk '{print $11}'
mysql_secure_installation --use-default

MySQL 5.6 や MariaDB 10.1 と比較して MySQL 5.7 のパフォーマンスがいいらしい。4 5

MySQL 5.6 以降および MariaDB にはデッドロック関連に問題があるらしい6ので、気になる場合は MySQL 5.5 か PostgreSQL を利用するといいかもしれない。

(rh-mysql57 の場合)

yum -y install rh-mysql57-mysql-server && source scl_source enable rh-mysql57
echo -e '#!/bin/bash\nsource scl_source enable rh-mysql57' > /etc/profile.d/rh-mysql57.sh
ln -s /{usr/lib/systemd/system/rh-mysql57-,etc/systemd/system/}mysqld.service
systemctl daemon-reload
echo -e "[server]\ncharacter-set-server = utf8" > /etc/opt/rh/rh-mysql57/my.cnf.d/server.cnf
echo -e "[client]\ndefault-character-set = utf8" > /etc/opt/rh/rh-mysql57/my.cnf.d/client.cnf
systemctl start mysqld && systemctl enable $_

mysql2 のビルドで発生する checking for rb_thread_blocking_region()... no のエラーが解消できず rh-mysql57 を利用したインストールを断念。

公式パッケージと異なり rh-mysql57 コレクションでは root パスワードは空で作成される。

/etc/my.cnf および /etc/my.cnf.d/ は postfix パッケージの依存関係で Anaconda によってインストールされている mariadb-libs によって作成されてしまっている。

(MariaDB 5.5 の場合)

yum install mariadb-server
sed -i 's/\[server\]/\[server\]\ncharacter-set-server = utf8/' /etc/my.cnf.d/server.cnf
sed -i 's/\[client\]/\[client\]\ndefault-character-set = utf8/' /etc/my.cnf.d/client.cnf
systemctl start mariadb && systemctl enable $_

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

mysqladmin create redmine -u root -p --default-character-set=utf8
cat << "_EOQ_" | mysql -u root -p
CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'P@ssw0rd';
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
_EOQ_

Apache HTTP Server のインストール

yum -y install httpd24 && source scl_source enable $_
echo -e '#!/bin/bash\nsource scl_source enable httpd24' > /etc/profile.d/httpd24.sh
ln -s {/opt/rh/httpd24/root,}/etc/httpd
ln -s {/opt/rh/httpd24/root,}/var/www
ln -s /{usr/lib/systemd/system/httpd24-,etc/systemd/system/}httpd.service
systemctl daemon-reload
systemctl start httpd && systemctl enable $_
firewall-cmd --zone=public --add-service=http{,s} --permanent && firewall-cmd --reload

Passenger 公式リポジトリおよび EPEL リポジトリの passenger パッケージは依存関係で base リポジトリの ruby パッケージ (Ruby 2.0) を要求し不整合が生じるので、RHSCL の rh-passenger40 パッケージを利用するために Apache も RHSCL の httpd24 パッケージを利用する。

scl_source で httpd24 コレクションを有効にする。3

設定ファイルなどがすべて /opt/rh/httpd24/root/ 配下のため、参照しやすいようにシンボリックリンクを張る。

また、サービス名が httpd24-httpd となっているので httpd.service としてシンボリックリンクを張る。

Phusion Passenger のインストール

ln -s /opt/rh/rh-ruby23/root/usr/lib64/libruby.so.2.3 /usr/lib64/
yum -y install rh-passenger40 rh-passenger40-mod_passenger && source scl_source enable rh-passenger40
echo -e '#!/bin/bash\nsource scl_source enable rh-passenger40' > /etc/profile.d/rh-passenger40.sh

rh-passenger40 は rh-ruby22 までしか対応していないが、rh-ruby22 だと bundle exec rake generate_secret_token を実行した際に何故か Could not find rake in any of the sources というエラーでこけるため、rh-ruby23 / rh-passenger40 の組合せ。

error while loading shared libraries: libruby.so.2.3: cannot open shared object file: No such file or directory というエラーが出てしまう 7 ので /usr/lib64/ にシンボリックリンクを張って回避。もっと適切方法はないだろうか。

Git

yum -y install rh-git29 && source scl_source enable $_
echo -e '#!/bin/bash\nsource scl_source enable rh-git29' > /etc/profile.d/rh-git29.sh

base リポジトリだと 1.8.3 がインストールされるため RHSCL の rh-git29 コレクションを利用する。

必要ライブラリのインストール

yum install -y rh-ruby23-{ruby-devel,rubygem-bundler}
yum install -y gcc {mysql-community,libxml2,libxslt,ImageMagick}-devel ipa-pgothic-fonts

nokogiri のビルドで libxml2 および libxslt が、mysql2 のビルドで mysql-community-devel (rh-mysql57 の場合は rh-mysql57-mysql-devel、 MariaDB の場合は mariadb-devel) が、rmagick のビルドで ImageMagick-devel が必要。

Redmine のインストール

cd /var/www && git clone https://github.com/redmine/redmine.git && cd redmine
git checkout `git tag | tail -n 1`
bundle config build.nokogiri --local --use-system-libraries
cat << "_EOF_" > config/database.yml
production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: root
  password: P@ssw0rd
  encoding: utf8
_EOF_
bundle install --jobs=4 --without development test
bundle exec rake generate_secret_token
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake redmine:load_default_data RAILS_ENV=production REDMINE_LANG=ja
chown -R apache. /var/www/redmine
chmod -R 755 files log tmp public/plugin_assets
setenforce 0 #TODO: SELinux Settings

そのままだと nokogiri のインストール時に An error occurred while installing nokogiri, and Bundler cannot continue. とエラーが出るので、--use-system-libraries オプションを事前に指定してやる。

rh-ror42-rubygem-bundler 以外にも rubygem パッケージがあるが、バージョンが足りないものやパッケージ化されていないものもあり、また検証した結果不具合が生じるのでパッケージ利用を断念。

bundle exec rails server webrick -e production -b 192.168.56.101 を実行すると簡易的に http://192.168.56.101:3000/ でアクセスできるようになるので、切り分けが必要なときなどに利用する。

Apache の VirtualHost 設定

cat << "_EOF_" > /etc/httpd/conf.d/redmine.conf
<VirtualHost *:80>
    ServerName example.com
    Header always unset "X-Powered-By"
    Header always unset "X-Runtime"
    PassengerRuby /opt/rh/rh-ruby23/root/usr/bin/ruby
    DocumentRoot /var/www/redmine/public
    <Directory /var/www/redmine/public>
        AllowOverride all
        Require all granted
        Options -MultiViews
    </Directory>
</VirtualHost>
_EOF_
systemctl restart httpd

テーマ

デフォルトのテーマはしなびた青色でテンションが下がるので、別のテーマをインストールして切り替える。

http://www.redmine.org/projects/redmine/wiki/Theme_List
http://www.redminethemes.org/

Flat theme

https://github.com/tsi/redmine-theme-flat
Flat theme for Redmine

git clone https://github.com/tsi/redmine-theme-flat.git /var/www/redmine/public/themes/flat

Minelab

https://github.com/hardpixel/minelab
Minelab

git clone https://github.com/hardpixel/minelab.git /var/www/redmine/public/themes/minelab

Basecamp-with-icon

https://github.com/lqez/redmine-theme-basecamp-with-icon
Basecamp-with-icon theme

git clone https://github.com/lqez/redmine-theme-basecamp-with-icon.git /var/www/redmine/public/themes/basecamp-with-icon

gitmike

https://github.com/makotokw/redmine-theme-gitmike
Redmine gitmike theme

git clone https://github.com/makotokw/redmine-theme-gitmike.git /var/www/redmine/public/themes/gitmike

Circle

https://www.redmineup.com/pages/themes/circle
Circle theme

プラグイン

redmine_absolute_datetime

https://github.com/syagawa/redmine_absolute_datetime
更新日の「…日前」などの相対的な表示を年月日と時間(YYYY/MM/DD hh:mm)で表示させるプラグイン。
redmine_absolute_dates のフォーク。

git clone git://github.com/syagawa/redmine_absolute_datetime.git /var/www/redmine/plugins/redmine_absolute_datetime
systemctl restart httpd

clipboard_image_paste

git clone https://github.com/peclik/clipboard_image_paste.git /var/www/redmine/plugins/clipboard_image_paste
systemctl restart httpd

Redmine Issue Templates Plugin

git clone https://github.com/akiko-pusu/redmine_issue_templates.git /var/www/redmine/plugins/redmine_issue_templates
systemctl restart httpd

Redmine Issue Badge Plugin

git clone https://github.com/akiko-pusu/redmine_issue_badge.git /var/www/redmine/plugins/redmine_issue_badge
cd /var/www/redmine && bundle exec rake redmine:plugins:migrate RAILS_ENV=production
systemctl restart httpd

Redmine Banner Plugin

git clone https://github.com/akiko-pusu/redmine_banner.git /var/www/redmine/plugins/redmine_banner
cd /var/www/redmine && bundle install --without development test
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
systemctl restart httpd

Redmine Editor Preview Tab

https://github.com/tleish/redmine_editor_preview_tab

git clone https://github.com/tleish/redmine_editor_preview_tab.git /var/www/redmine/plugins/redmine_editor_preview_tab
systemctl restart httpd

Redmine Issue History

git clone https://github.com/stpl/redmine_issue_history.git /var/www/redmine/plugins/redmine_issue_history
systemctl restart httpd

Hide Sidebar

git clone https://github.com/bdemirkir/sidebar_hide.git /var/www/redmine/plugins/sidebar_hide
systemctl restart httpd

Redmine Theme Changer plugin

curl -o redmine_theme_changer-0.2.0.tar.gz -L https://bitbucket.org/haru_iida/redmine_theme_changer/get/0.2.0.tar.gz
tar xf redmine_theme_changer-0.2.0.tar.gz
mv haru_iida-redmine_theme_changer-875b2d9d750b /var/www/redmine/plugins/redmine_theme_changer
cd /var/www/redmine && bundle exec rake redmine:plugins:migrate RAILS_ENV=production
systemctl restart httpd

Already Read Plugin

https://github.com/ameya86/redmine_already_read
チケットの既読/未読を管理し、チケット一覧に「既読」「読んだ日時」列を追加する。チケットを更新すると、そのチケットは未読チケットに戻る。

git clone https://github.com/ameya86/redmine_already_read.git /var/www/redmine/plugins/redmine_already_read
cd /var/www/redmine && bundle exec rake redmine:plugins:migrate RAILS_ENV=production
systemctl restart httpd

Redmine Checklists plugin

One click edits Integrated with issue history log

unzip redmine_checklists-3_1_5-light.zip
mv redmine_checklists /var/www/redmine/plugins/
cd /var/www/redmine && bundle exec rake redmine:plugins NAME=redmine_checklists RAILS_ENV=production
systemctl restart httpd

初期設定

初期ログインID/パスワードは admin / admin となっている。

必須設定変更

認証、公開の設定は変更しないとデフォルトで全公開されてしまうので要注意。

管理 → 設定 → 全般

  • 「テキストの書式」を「Markdown」に変更
  • 「ページごとの検索結果表示件数」に「30」を指定
  • 「プロトコル」を必要に応じて「HTTPS」に変更

管理 → 設定 → 表示

  • 「テーマ」を「Flat-theme」などに変更
  • 「ユーザー名の表示書式」を「Admin Redmine」(姓 名)に変更
  • 「添付ファイルのサムネイル画像を表示」をチェック

管理 → 設定 → 認証

  • 「認証が必要」をチェック
  • 「自動ログイン」を「30日」に変更

管理 → 設定 → プロジェクト

  • 「デフォルトで新しいプロジェクトは公開する」のチェックを外す
  • 「新規プロジェクトにおいてデフォルトで有効になるモジュール」の以下のチェックを外す
    • 文書
    • ファイル
    • フォーラム
  • 「新規プロジェクトにおいてデフォルトで有効になるトラッカー」のすべてをチェックする

管理 → 設定 → ファイル

  • 「添付ファイルとリポジトリのエンコーディング」に「UTF-8,CP932,EUC-JP」を指定

管理 → 設定 → リポジトリ

  • 「使用するバージョン管理システム」の不要なチェックを外す
  • 「参照用キーワード」に「refs,references,IssueID,*」を指定

管理 → ロールと権限 → 開発者

  • 「チケットトラッキング」の「子チケットの管理」のチェックを外す

管理 → ロールと権限 → 匿名ユーザー

  • 「すべてのチェックを外す」をクリックして保存

管理 → ロールと権限 → 非メンバー

  • 「すべてのチェックを外す」をクリックして保存

バックアップ

データベース

mysqldump -u redmine -p redmine | gzip > redmine_`date +%F`.sql.gz

ファイル

Redmine にアップロードしたファイルはすべて files/ ディレクトリに保存される。

tar cvf redmine_`date +%F`.tar.gz /var/www/redmine/{config,files,public/themes,plugins}

アップデート

手動アップデート

Yum パッケージ

yum update

Redmine 本体

cd /var/www/redmine
git branch
git checkout `git tag | tail -n 1`
bundle update
bundle install --without development test
bundle exec rake generate_secret_token
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
bundle exec rake tmp:cache:clear tmp:sessions:clear
chown -R apache. /var/www/redmine
chmod -R 755 files log tmp public/plugin_assets
systemctl restart httpd

TODO

  • メール設定例
  • プラグイン追記
  • 自動アップデート
  • SELinux 設定

Redmine 関連記事

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
40