さくらVPSにRedmine1.2.0をインストール

なにかと忘れっぽい自分のために、プロジェクト管理ツールのRedmine
インストールしたので、忘れないように残しておく。

環境は以下

OS CentOS 5.5
Redmine 1.2.0
MySQL 5.0.77
ホスト名 host(実際は異なる)

作業は以下のページを参考にした。
http://blog.redmine.jp/articles/redmine-1_1-installation_centos/

RedmineのためにCentOSの設定を行う

SELinuxを無効にする
/etc/sysconfig/selinux を開き内容確認

SELINUX=disabled

始めからdisableになっているので、変更なし。

一応コマンドで確認

[root@host ~]# getenforce
Disabled

disableなのでOK。

iptablesでHTTPを許可
iptablesファイルが見つからないので飛ばす。

必要なパッケージのインストール

●開発ツール(Cコンパイラ等):

yum groupinstall "Development Tools" 

RubyとPassengerのビルドに必要なヘッダファイルなど:

[root@host /]# yum install openssl-devel readline-devel zlib-devel curl-devel

MySQL

[root@host /]# yum install mysql-server mysql-devel

Apache

[root@host /]# yum install httpd httpd-devel

Rubyのインストール

1. Ruby Enterprise Editionのダウンロード

[root@host ~]# wget http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise-1.8.7-2011.03.tar.gz
--2011-06-11 23:18:42-- http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise-1.8.7-2011.03.tar.gz
Resolving rubyenterpriseedition.googlecode.com... 64.233.183.82
Connecting to rubyenterpriseedition.googlecode.com|64.233.183.82|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7898840 (7.5M) [application/x-gzip]
Saving to: `ruby-enterprise-1.8.7-2011.03.tar.gz'

100%[=============================>] 7,898,840 1.52M/s in 8.4s

2011-06-11 23:18:51 (922 KB/s) - `ruby-enterprise-1.8.7-2011.03.tar.gz' saved [7898840/7898840]

ダウンロードしたファイルを解凍

[root@host ~]# tar zxvf ruby-enterprise-1.8.7-2011.03.tar.gz 

2. インストーラ実行

[root@host ~]# ./ruby-enterprise-1.8.7-2011.03/installer --dont-install-useful-gems --no-dev-docs

Target directoryを指定する

Target directory

Where would you like to install Ruby Enterprise Edition to?
(All Ruby Enterprise Edition files will be put inside that directory.)

[/opt/ruby-enterprise-1.8.7-2011.03] : /usr/local/

●RubyGems1.4.2のインストール
RubyGemsを1.4.2にダウングレード

[root@host ~]# gem update --system 1.4.2 

バージョン確認

[root@host ~]# gem --version
1.4.2

●gemパッケージのインストール

Rack 1.0.1のインストール

[root@host ~]# gem install rack v=1.0.1

i18n 0.4.2のインストール

[root@host ~]# gem install i18n v=0.4.2

RubyMySQLドライバーのインストール

[root@host ~]# gem install mysql 

※エラーっぽいメッセージが多数出ていた
 ドキュメント関係?よく分からないので、ここでは無視する。

MySQLの設定

1. デフォルトキャラクタセットをutf8に設定

[root@host ~]# vi /etc/my.cnf 

----------------------------------------------------------------
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
Default to using old password format for compatibility with mysql 3.x
clients (those using the mysqlclient10 compatibility package).
old_passwords=1
Disabling symbolic-links is recommended to prevent assorted security risks;
to do so, uncomment this line:
symbolic-links=0
default-character-set=utf8 ←追加
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysql] ←追加
default-character-set=utf8 ←追加
----------------------------------------------------------------

3行追加した。

2. MySQLの起動および自動起動の設定

[root@host ~]# /etc/init.d/mysqld start

無事起動したので、自動起動を設定。

[root@host ~]# chkconfig mysqld on

3. /etc/my.cnf への設定が反映されていることの確認

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)

4. rootユーザーのパスワード変更・匿名ユーザー削除

rootユーザーのパスワード変更

mysql> set password for root@"localhost"=password('********');
Query OK, 0 rows affected (0.00 sec)
mysql> set password for root@"127.0.0.1"=password('********');
Query OK, 0 rows affected (0.00 sec)
mysql> set password for root@"host"=password('********');
Query OK, 0 rows affected (0.00 sec)

匿名ユーザー削除

mysql> drop user ''@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> drop user ''@'host';
Query OK, 0 rows affected (0.00 sec)

5. Redmine用データベースとユーザーの作成

mysql> create database db_redmine default character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on db_redmine.* to user_redmine identified by '********';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

Redmineのインストール

1. Redmineのダウンロード
Webの手引きはRedmine1.1.2の説明だったが、最新が1.2.0だったのでこちらをダウンロード

[root@host ~]# wget http://rubyforge.org/frs/download.php/74944/redmine-1.2.0.tar.gz

2. ダウンロードしたRedmineの展開と配置

ダウンロードしたファイルを解凍

[root@host ~]# tar zxvf redmine-1.2.0.tar.gz

Redmineの配置先のディレクトリを決定し、そこへ展開したファイルを移動

[root@host ~]# mv redmine-1.2.0 /var/lib/redmine

3. database.ymlの設定

Redmineを配置したディレクトリに移動します。

[root@host ~]# cd /var/lib/redmine/

database.yml.exampleからdatabase.ymlをコピーし、中身を編集

[root@host redmine]# cd config/ 
[root@host config]# cp database.yml.example database.yml 
[root@host config]# vi database.yml
----------------------------------------------------------------
MySQL (default setup).
production:
adapter: mysql
database: db_redmine
host: localhost
username: user_redmine
password: ********
encoding: utf8
----------------------------------------------------------------

4. email.ymlの設定

以下の内容でconfig/email.ymlファイルを作成します

[root@host config]# vi email.yml
----------------------------------------------------------------
production:
delivery_method: :smtp
smtp_settings:
address: localhost
port: 25
domain: host
----------------------------------------------------------------

5. Redmineの初期設定とデータベースのテーブル作成

セッションデータ暗号化用鍵の生成とテーブル作成を行う。

rakeが無いようなのでインストール

[root@host redmine]# gem install v=0.8.7 rake
Fetching: rake-0.8.7.gem (100%)
Successfully installed rake-0.8.7
1 gem installed
Installing ri documentation for rake-0.8.7...
Installing RDoc documentation for rake-0.8.7...
[root@host redmine]# 

コマンド実行

[root@host redmine]# rake generate_session_store
(in /var/lib/redmine)

コマンドを実行するとエラー発生

[root@host redmine]# rake db:migrate RAILS_ENV=production
(in /var/lib/redmine)
rake aborted!
RubyGem version error: rack(1.0.1 not ~> 1.1.0)

(See full trace by running task with --trace)
[root@host redmine]# 

rackのバージョンが「1.1.0」じゃないと言っているので、
1.0.1から1.1.0に変更する。

[root@host redmine]# gem install rack v=1.1.0
Fetching: rack-1.1.0.gem (100%)
Successfully installed rack-1.1.0
1 gem installed
Installing ri documentation for rack-1.1.0...
Installing RDoc documentation for rack-1.1.0...
[root@host redmine]# 

もう一度コマンドの実行

[root@host redmine]# rake db:migrate RAILS_ENV=production
(in /var/lib/redmine)
Setup: migrating ========================================================
...省略

コマンドは成功したようだ。

Passengerのインストール

Railsアプリケーションを実行するためのApacheモジュール「Passenger」をインストール。

[root@host redmine]# gem install passenger

●PassengerのApache用モジュールのインストール

[root@host redmine]# 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.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7
   PassengerRuby /usr/local/bin/ruby

LoadModule passenger_module
PassengerRoot
PassengerRuby
のパスが必要。

Apacheの設定

1. worker MPMに切り替える

※参考サイトの丸岡氏のコメントに
「また、worker MPMにするとPHPに処理が必要なためprefork MPMのままにしています。」
とあるので、ひとまず飛ばす。

2. Passengerの設定を追加

設定ファイルを新規作成

[root@host redmine]# vi /etc/httpd/conf.d/passenger.conf
----------------------------------------------------------------
# Passengerの基本設定。
# passenger-install-apache2-module --snippet を実行して表示される設定を使用。
# 環境によって設定値が異なりますので以下の3行はそのまま転記しないでください。
#
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7
PassengerRuby /usr/local/bin/ruby

# Passengerが追加するHTTPヘッダを削除するための設定。
#
Header always unset "X-Powered-By"
Header always unset "X-Rack-Cache"
Header always unset "X-Content-Digest"
Header always unset "X-Runtime"

# 必要に応じてPassengerのチューニングのための設定を追加。
#
PassengerMaxPoolSize 20
PassengerMaxInstancesPerApp 4
PassengerPoolIdleTime 3600
PassengerUseGlobalQueue on
PassengerHighPerformance on
PassengerStatThrottleRate 10
RailsSpawnMethod smart
RailsAppSpawnerIdleTime 86400
RailsFrameworkSpawnerIdleTime 0

3. Apacheの起動および自動起動の設定

[root@host redmine]# /etc/init.d/httpd start
Starting httpd: [ OK ]
[root@host redmine]# chkconfig httpd on

エラーなし。

Apache上のPassengerでRedmineを実行するための設定

オーナーを変更

[root@host redmine]# chown R apache:apache /var/lib/redmine/

パターン2: サブディレクトリでRedmineを実行
1. シンボリックリンクの作成

[root@host redmine]# ln s /var/lib/redmine/public/ /var/www/html/redmine

2. Apacheへの設定追加

[root@host redmine]# vi /etc/httpd/conf.d/passenger.conf
----------------------------------------------------------------
RailsBaseURI /redmine

以上で作業終了!
http://host/redmine/
にアクセスして画面が出ることを確認 ヽ( ・∀・)ノ