Redmine 2.3 をインストールします。データベース、Apache、Ruby のバージョンは下記の通りです。Apache に関してですが 2.4 では起動時に Passenger のエラーが発生するため 2.2 をインストールします。
データベース : MySQL 5.5.31
webサーバ : Apache 2.2.24(Railsの実行にはPassengerを使用)
Ruby 1.9.3
全体的な流れは次の通りです。
1. EC2 でインスタンス生成
2. gcc* のインストール
3. apr,apr-util,pcre のインストール
4. ssl 関連モジュールのインストール
5. httpd(Apache2.2.24) のインストール
6. MySQL等のインストール
7. Rubyのインストール
8. MySQLの設定
9. ReadMine のインストール
10.Passenger のインストール
11.ssl 証明書の発行と設定
12.ダイジェスト認証の設定
13.Apache の設定
14.Apache の起動と停止
尚、「4まで」と「11以降」に関しては以前書いた http://albatrosary.hateblo.jp/entry/2013/04/30/123019
を参照してください。
httpd(Apache2.2.24) のインストール
ダイジェスト認証を行いますので、あらかじめ --enable-auth_digest=shared を付加します。
$ wget http://ftp.riken.jp/net/apache/httpd/httpd-2.2.24.tar.gz $ tar xozf httpd-2.2.24.tar.gz $ cd httpd-2.2.24 $ ./configure --enable-rewrite --enable-shared=yes --enable-ssl --enable-auth_digest=shared $ make $ sudo su - root # cd /home/ec2-user/httpd-2.2.24 # make install # exit $ cd ~
インストール完了後、モジュールが組み込まれているか確認します
# /usr/local/apache2/bin/httpd -M
参考として httpd -l は、静的に組み込まれたもののみ表示します。動的に組み込まれたものも含めて全てのモジュール一覧を見るには -M オプションを利用します。
MySQL等のインストール
$ sudo su - root # yum install readline-devel zlib-devel curl-devel libyaml-devel # yum install mysql-server mysql-devel # yum install ImageMagick ImageMagick-devel # yum install httpd-devel # exit
Rubyのインストール
$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz $ tar zxvf ruby-1.9.3-p392.tar.gz $ cd ruby-1.9.3-p392 $ ./configure --disable-install-doc $ make $ sudo su - root # cd /home/ec2-user/ruby-1.9.3-p392 # make install # ruby -v ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux] # gem install bundler --no-rdoc --no-ri # exit $ cd ~
MySQLの設定
$ sudo su - root vi /etc/my.cnf
my.cnf には下記内容を記載します。
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 character-set-server=utf8 innodb_file_per_table query-cache-size=16M # 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 mysqld according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
MySQLの起動および自動起動の設定
# service mysqld start # chkconfig mysqld on
/etc/my.cnf への設定が反映されていることの確認
# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.5.31 MySQL Community Server (GPL) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> 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) mysql> exit
rootユーザーのパスワード変更・匿名ユーザー削除
# mysql -uroot mysql> use mysql; mysql> update user set password=password('hogehoge') where user = 'root'; mysql> delete from user where user = ''; mysql> flush privileges; mysql> exit;
Redmine用データベースとユーザーの作成
# mysql -uroot -p mysql> create database db_redmine default character set utf8; mysql> grant all on db_redmine.* to user_redmine identified by 'hogehoge'; mysql> flush privileges; mysql> exit; # exit $ cd ~
ReadMineのインストール
$ wget http://rubyforge.org/frs/download.php/76771/redmine-2.2.3.tar.gz $ tar zxvf redmine-2.2.3.tar.gz $ sudo su - root # cd /home/ec2-user/ # mv redmine-2.2.3/ /var/lib/redmine # chown -R apache:apache /var/lib/redmine/
データベースの設定
# cd /var/lib/redmine/config # cp database.yml.example database.yml # vi database.yml
database.yml の内容は下記の通り。
production: adapter: mysql2 database: db_redmine host: localhost username: root password: hogehoge encoding: utf8
Redmineの初期設定とデータベースのテーブル作成
Redmineのインストールディレクトリで以下のコマンドを実行してください。
# cd /var/lib/redmine # bundle install --without development test postgresql sqlite # bundle exec rake generate_secret_token # RAILS_ENV=production bundle exec rake db:migrate
Passengerのインストール
# gem install passenger --no-rdoc --no-ri
PassengerのApache用モジュールのインストール
# passenger-install-apache2-module The Apache 2 module was successfully installed. Please edit your Apache configuration file, and add these lines: LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/ext/apache2/mod_passenger.so PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.19 PassengerRuby /usr/local/bin/ruby After you restart Apache, you are ready to deploy any number of Ruby on Rails applications on Apache, without any further Ruby on Rails-specific configuration! Press ENTER to continue.
途中 passenger.conf への passenger_module の記載方法が表示されます。この内容を下記のように作成します。このファイルは httpd.conf から読み込ませます。
# vi /etc/httpd/conf.d/passenger.conf LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/ext/apache2/mod_passenger.so PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.19 PassengerRuby /usr/local/bin/ruby PassengerMaxPoolSize 20 PassengerMaxInstancesPerApp 4 PassengerPoolIdleTime 3600 PassengerHighPerformance on PassengerStatThrottleRate 10 PassengerSpawnMethod smart RailsAppSpawnerIdleTime 86400 RailsFrameworkSpawnerIdleTime 0
# cd /usr/local/apache2/conf # cp httpd.conf httpd.conf.ssl # vi httpd.conf Include /etc/httpd/conf.d/passenger.conf
DocumentRoot 関係も編集します。
DocumentRoot "/var/lib/redmine/public" <Document "/var/lib/redmine/public">