Redmine3.0をCentOS7へインストールする
「Redmine3.0をCentOS7にインストールする手順」に従ってインストールを実施します。
最終的には、Windows環境からの移行も含めて整理していきます。
企業等でproxyを経由する必要がある場合は、環境変数へ設定しておいた方が作業が楽かもしれません。(Proxyを経由できるよう設定する)
CentOSの設定
SELinuxを無効にする
エディタで「/etc/sysconfig/selinux」ファイルにあるSELINUXの値をdisabledに編集します。
SELINUX=enforcing
↓
SELINUX=disabled
修正が完了したら、CentOSを再起動します。
# reboot
再起動後、getenforceコマンドを実行してSELinuxが無効になったことを確認します。
Disabledと表示されればSELinuxは無効になっています。
# getenforce
Disabled
firewalldでHTTPを許可する
RedmineはWebベースのシステムの為、クライアントからhttp通信にて接続されます。
クライアントのWebブラウザからアクセスできるようファイアウォールの設定を変更します。
デフォルトのソーンにhttpを許可するよう設定を追加します。
firewall-cmd --zone=public --add-service=http --permanent
おまけ:デフォルトのゾーンを確認するには、次のコマンドを実行します。
# firewall-cmd --get-default-zone
public
追加した設定を反映させます。
# firewall-cmd --reload
httpでのアクセスが許可されたかどうかを確認します。
# firewall-cmd --zone=public --list-services
dhcpv6-client http ssh
httpと出力されていることを確認します。
必要なパッケージのインストール
Redmineを稼働させるために必要なパッケージをインストールします。
開発ツール(Cコンパイラ等)のインストール
# yum -y groupinstall "Development Tools"
RubyとPassengerのビルドに必要なヘッダファイルなどのインストール
# yum -y install openssl-devel readline-devel zlib-devel curl-devel libyaml-devel
MariaDBとヘッダファイルのインストール
# yum -y install mariadb-server mariadb-devel
Apacheとヘッダファイルのインストール
# yum -y install httpd httpd-devel
ImageMagickとヘッダファイル・日本語フォントのインストール
# yum -y install ImageMagick ImageMagick-devel ipa-pgothic-fonts
Rubyのインストール
ソースコードのダウンロード
RubyのサイトからRuby2.1の最新のソースコードをダウンロードします。
# cd /usr/local/src
# curl -O http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz
Rubyのビルド
ダウンロードしたRubyのtarballを展開し、Rubyのビルドとインストールを行います。
# tar xvf ruby-2.2.2.tar.gz
# cd ruby-2.2.2
# ./configure --disable-install-doc
# make
# make install
# cd ..
インストール後、ruby -vを実行し、Rubyが実行できることを確認します。
# ruby -v
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
bundlerのインストール
Gemパッケージのバージョン管理などを行ってくれるツール(bundler)をインストールします。
# gem install bundler --no-rdoc --no-ri
Proxyを経由する必要がある場合、次のオプションを追加します。
# gem install bundler --no-rdoc --no-ri -r -p http://proxy.example.com:8080
MariaDBの設定
デフォルトキャラクタセットをutf8に設定
エディタで/etc/my.cnf を開き、[mysqld]セクションにcharacter-set-server=utf8と[mysql]セクションにdefault-character-set=utf8を追加します。
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
character-set-server=utf8
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[mysql]
default-character-set=utf8
MariaDBの起動および自動起動の設定
MariaDBの起動と再起動後の自動起動を設定しておきます。
service mariadb start
systemctl enable mariadb
character-setの確認
/etc/my.cnfへ設定したcharacter-setが反映されているか確認します。
MariaDBのシステム変数character_set_* のうち、character_set_filesystemとcharacter_sets_dir以外の値がすべてutf8になっていることを確認します。
# mysql -uroot
MariaDB [(none)]> show variables like 'character_set%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
MariaDB [(none)]> exit
MariaDBの初期設定
MariaDBのセキュリティ向上のため、mysql_secure_installationを実行してrootパスワードの設定や不要なデータベースの削除を行います。
# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): (そのままEnterキーを押す)
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password: (MariaDBのrootユーザーに新たに設定するパスワードを入力)
Re-enter new password: (新パスワードを再入力)
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y (匿名ユーザーを削除)
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y (rootユーザーの接続元をlocalhostに限定)
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y (testデータベースを削除)
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y (権限関係の変更を直ちに適用)
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
データベースとユーザの作成
Redmaineのデータを保管するデータベースを作成します。
mysql -uroot -p
MariaDB [(none)]< create database db_redmine default character set utf8;
MariaDB [(none)]< grant all on db_redmine.* to user_redmine@localhost identified by 'パスワード';
MariaDB [(none)]< flush privileges;
MariaDB [(none)]< exit;
Redmineのインストール
下記のページからRedmine 3.0のtarball(.tar.gz)をダウンロードします。
ここでは、/usr/local/srcへダウンロードします。
http://www.redmine.org/projects/redmine/wiki/Download
# cd /usr/local/src
# curl -O http://www.redmine.org/releases/redmine-3.0.0.tar.gz
Redmineの展開と配置
ダウンロードしたRedmineのtarballを展開します。
# tar xvf redmine-3.0.0.tar.gz
Redmineの配置先のディレクトリを決定し、そこへ展開したファイルを移動します。
ここでは、インストール手順例に合わせ、/var/lib/redmineを配置先とします。
# mv redmine-3.0.0 /var/lib/redmine
Redmineのデータベース接続設定
Redmineからデータベースへ接続するための設定ファイルを作成します。
以下の内容でRedmineのインストールディレクトリ(例: /var/lib/redmine)以下にconfig/database.ymlを作成します。
configディレクトリには、設定例のdatabase.yml.exampleファイルがあるのでこのファイルを修正します。
# cp database.yml.example database.yml
production:
adapter: mysql2
database: db_redmine
host: localhost
username: user_redmine
password: ""
encoding: utf8
私の環境では、この後の設定(bundle exec rake db:migrate)でエラーが発生したため、database.ymlファイルにdevelopmentとtestを同じように追加することでインストールすることができました。
production:
adapter: mysql2
database: db_redmine
host: localhost
username: user_redmine
password: ""
encoding: utf8
development:
adapter: mysql2
database: db_redmine
host: localhost
username: user_redmine
password: ""
encoding: utf8
test:
adapter: mysql2
database: db_redmine
host: localhost
username: user_redmine
password: ""
encoding: utf8
Redmineの設定
Redmineからメールサーバへ接続するための設定や日本語フォントファイルのパスを記述した設定ファイルを作成します。
以下の内容でRedmineのインストールディレクトリ(例: /var/lib/redmine)以下にconfig/configuration.ymlを作成します。
configディレクトリには、設定例のconfiguration.yml.exampleファイルがあるのでこのファイルを修正します。
# cp configuration.yml.example configuration.yml
production:
email_delivery:
delivery_method: :smtp
smtp_settings:
address: "localhost"
port: 25
domain: "example.com"
rmagick_font_path: /usr/share/fonts/ipa-pgothic/ipagp.ttf
Gemパッケージのインストール
bundlerを使用してRedmineで使用するGemをインストールします。
Redmineのインストールディレクトリ(例:/var/lib/redmine)で以下のコマンドを実行します。
# bundle install --without development test --path vendor/bundle
Redmineの初期設定とデータベースのテーブル作成
セッションデータ改竄防止用鍵の生成とテーブル作成を行います。
Redmineのインストールディレクトリ(例:/var/lib/redmine)で以下のコマンドを実行します。
# bundle exec rake generate_secret_token
# RAILS_ENV=production bundle exec rake db:migrate
私の環境では、bundle exec rake db:migrateで次のエラーが発生しました。
Mysql2::Error: Access denied for user 'user_redmine'@'localhost' (using password: YES)
パスワードに記号を使用しているとダメなようで、英数字のみに変更することで対応できました。
初期データの登録
作成したデータベースへ初期データを追加します。
# RAILS_ENV=production REDMINE_LANG=ja bundle exec rake redmine:load_default_data
Passengerのインストール
Apache上でRailsアプリケーションを実行するためPassengerをインストールします。
# gem install passenger --no-rdoc --no-ri
PassengerのApache用モジュールのインストール
インストーラを実行し画面の指示に従って操作します。
# passenger-install-apache2-module
Welcome to the Phusion Passenger Apache 2 module installer, v5.0.4.
This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.
Here's what you can expect from the installation process:
1.The Apache 2 module will be installed for you.
2.You'll learn how to configure Apache.
3.You'll learn how to deploy a Ruby on Rails application.
Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.
Press Enter to continue, or Ctrl-C to abort. Enter入力
------------------------------------------------
Which languages are you interested in?
Use <space> to select.
If the menu doesn't display correctly,press '!'
■■Ruby (言語を選択します。メニューがうまく表示されない場合は、'!'を押します。)
■Python
■Node.js
■Meteor
・・・いろいろなチェックが実行されます。・・・
・・・・・
---------------------------------
Almost there!
Please edit your Apache configuration file, and add these lines:
LoadModule passenger_module /usr/local/lib/ruby/gems/2.2.0/gems/passenger-5.0.4/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/lib/ruby/gems/2.2.0/gems/passenger-5.0.4
PassengerDefaultRuby /usr/local/bin/ruby
</IfModule>
After you restart Apache, you are ready to deploy any number of web
application on Apache, with a minimum amount of configuration!
Press ENTER to continue. Enterを入力
インストールの最後にApacheに設定する内容が表示されるので控えておきます。 表示される設定情報は、passenger-install-apache2-module –snippetを実行して後で参照することもできます。
Please edit your Apache configuration file, and add these lines:
LoadModule passenger_module /usr/local/lib/ruby/gems/2.2.0/gems/passenger-5.0.4/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/lib/ruby/gems/2.2.0/gems/passenger-5.0.4
PassengerDefaultRuby /usr/local/bin/ruby
</IfModule>
After you restart Apache, you are ready to deploy any number of web
application on Apache, with a minimum amount of configuration!
Press ENTER to continue. Enterを入力
Apacheの設定
Passengerの設定を追加
Passengerの設定をApacheに追加します。「PassengerのApache用モジュールのインストール」で控えた内容を /etc/httpd/conf.d/redmine.conf に作成します。
LoadModule passenger_module /usr/local/lib/ruby/gems/2.0.0/gems/passenger-5.0.4/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/lib/ruby/gems/2.0.0/gems/passenger-5.0.4
PassengerDefaultRuby /usr/local/bin/ruby
</IfModule>
RedmineのCSSや画像へのアクセスを許可
Apache 2.4のデフォルト設定ではサーバ上の全ファイルへのアクセスが禁止されてるため、Redmineの画像,CSS,JavaScript等をブラウザで読み込むことができません。
先ほど作成した /etc/httpd/conf.d/redmine.conf に以下の内容を追記して、ファイルが格納されているディレクトリへのアクセスを許可します。
<Directory "/var/lib/redmine/public">
Require all granted
</Directory>
Apacheの起動および自動起動の設定
# service httpd start
# systemctl enable httpd