Redmineの構築に携わったので、その際の手順を備忘録として投稿します。
初Markdownなので見辛いかも。。。
概要
CentOS7.4にRedmine3.4.3+PostgreSQL9.2.23をインストールするまでの設定手順を記載します。
(インストール自体はhttp://blog.redmine.jp/articles/3_4/install/centos/ の通りに実施してます。)
CentOSの設定
SELinuxの無効化
誤って SELINUXTYPE=targeted を変更しないように注意。
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
OS再起動し、SELinuxが無効になっていることを確認する。
$ restart
$ getenforce
Disabled
と出力されればOK
Firewallの設定
httpを許可
$ firewall-cmd --add-service=http --permanent
プロキシの設定
社内ネットワーク等に設置する場合はプロキシの設定が必要。
PROXY='プロキシアドレス:ポート番号'
export http_proxy=$PROXY
export HTTP_PROXY=$PROXY
export https_proxy=$PROXY
export HTTPS_PROXY=$PROXY
export no_proxy='localhost,127.0.0.1'
export NO_PROXY="$no_proxy"
$ source /etc/profileで反映させます。
yumのプロキシ設定
proxy=http://プロキシアドレス:ポート番号
を追記
Redmineのインストール
必要なパッケージのインストール
$ yum -y install httpd httpd-devel
$ systemctl start httpd.service
$ systemctl enable httpd.service
$ yum -y groupinstall "Development Tools"
$ yum -y install openssl-devel readline-devel zlib-devel curl-devel libyaml-devel libffi-devel
$ yum -y install postgresql-server postgresql-devel
$ yum -y install ImageMagick ImageMagick-devel ipa-pgothic-fonts
Rubyのインストール
Rubyのソースコードをダウンロードしてきます。
curl -O https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.2.tar.gz
Rubyをビルドしていきます。
$ tar xvf ruby-2.4.2.tar.gz
$ cd ruby-2.4.2
$ ./configure --disable-install-doc
$ make
$ make install
$ ruby -v
Rubyのバージョンが表示されればインストール完了
bundlerが必要なのでインストールします。
$ gem install bundler --no-rdoc --no-ri
PostgreSQLの設定
Redmineで利用するPostgresSQLの設定を行います。
データベースクラスタの新規作成
# postgresql-setup initdb
RedmineからPostgreSQLに接続するための設定を追加
# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "host" records. In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
host redmine redmine 127.0.0.1/32 md5
host redmine redmine ::1/128 md5
PostgreSQLの起動および自動起動の設定
$ systemctl start postgresql.service
$ systemctl enable postgresql.service
Redmine用SQLユーザーの作成
$ cd /var/lib/pgsql
$ sudo -u postgres createuser -P redmine
Redmine用データベースの作成
$ sudo -u postgres createdb -E UTF-8 -l ja_JP.UTF-8 -O redmine -T template0 redmine
Redmineのインストールと設定
RedmineをDLする
$ svn co https://svn.redmine.org/redmine/branches/3.4-stable /var/lib/redmine
/var/lib/redmineがインストール先なので、必要であれば変更する。
データベースへの接続設定
設定ファイルを新規作成する。
production:
adapter: postgresql
database: redmine
host: localhost
username: redmine
password: "データベースのパスワード"
encoding: utf8
メール送信の設定をします。
設定ファイルを新規作成する。
production:
email_delivery:
delivery_method: :smtp
smtp_settings:
address: メールサーバのIPアドレス
port: 25
domain: ドメイン名
rmagick_font_path: /usr/share/fonts/ipa-pgothic/ipagp.ttf
gemパッケージのインストール
$ cd /var/lib/redmine
$ bundle install --without development test --path vendor/bundle
セッション改ざん防止用秘密鍵の作成
$ bundle exec rake generate_secret_token
データベースのテーブル作成
$ RAILS_ENV=production bundle exec rake db:migrate
デフォルトデータの登録
$ RAILS_ENV=production REDMINE_LANG=ja bundle exec rake redmine:load_default_data
Passengerのインストール
gem install passenger --no-rdoc --no-ri -p http://プロキシアドレス:ポート番号
-pはプロキシを指定する。プロキシ環境下でないのであれば-pは指定不要
PassengerのApache用モジュールのインストール
$ passenger-install-apache2-module --auto --languages ruby
Apache用設定内容の確認
$ passenger-install-apache2-module --snippet
出力された内容をメモしておく
Apacheの設定
Apacheの設定をしていく
Redmine以外のWebアプリは動作させないため、ドキュメントルートはRedmineにしておく。
#DocumentRoot "/var/www/html"
DocumentRoot "/var/lib/redmine/public"
redmine用の設定ファイルを作成する
前項でメモした内容を使用する。
# Redmineの画像ファイル・CSSファイル等へのアクセスを許可する設定。
# Apache 2.4のデフォルトではサーバ上の全ファイルへのアクセスが禁止されている。
<Directory "/var/lib/redmine/public">
Require all granted
</Directory>
# Passengerの基本設定。
# passenger-install-apache2-module --snippet で表示された設定を記述。
# 環境によって設定値が異なるため以下の5行はそのまま転記せず、必ず
# passenger-install-apache2-module --snippet で表示されたものを使用すること。
#
LoadModule passenger_module /usr/local/lib/ruby/gems/2.4.0/gems/passenger-5.1.11/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/lib/ruby/gems/2.4.0/gems/passenger-5.1.11
PassengerDefaultRuby /usr/local/bin/ruby
</IfModule>
# 必要に応じてPassengerのチューニングのための設定を追加(任意)。
# 詳しくはPhusion Passenger users guide(https://www.phusionpassenger.com/library/config/apache/reference/)参照。
PassengerMaxPoolSize 60
PassengerMaxInstancesPerApp 4
PassengerPoolIdleTime 864000
PassengerStatThrottleRate 10
Header always unset "X-Powered-By"
Header always unset "X-Runtime"
Apacheの起動および自動起動の設定
$ systemctl start httpd.service
$ systemctl enable httpd.service
Apache上のPassengerでRedmineを実行するための設定
$ chown -R apache:apache /var/lib/redmine
apache再起動
$ service httpd configtest
$ systemctl restart httpd.service
以上