Quantcast
Channel: webプログラマーのメモ » ruby on rails
Viewing all articles
Browse latest Browse all 2

CentOS5.5 に redmine-1.0.2 をインストールする

$
0
0

CentOS5.5 に redmine-1.0.2 をインストールする

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

開発ツール(Cコンパイラ等):
$ sudo yum groupinstall "Development Tools"

Rubyのビルドに必要なライブラリのヘッダファイル:
$ sudo yum install openssl-devel readline-devel zlib-devel

MySQLとヘッダファイル:
$ sudo yum install mysql-server mysql-devel

Apacheとヘッダファイル:
$ sudo yum install httpd httpd-devel

▼RubyとPassengerのインストール

Passengerの開発元であるPhusionが開発している
Ruby Enterprise Editionをインストールします。

Ruby Enterprise EditionはRuby 1.8.7をベースに変更を加えたもので、
オリジナルのRubyと比較すると、Passenger上で
Ruby on Railsアプリケーションを実行する際に
メモリ使用量を減らせるというメリットがあるそうです。

また、インストール時にPassengerやRuby用 MySQLデータベースドライバなど
関係するパッケージも同時にインストールされて便利です。

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

$ cd ~/src/
$ wget http://rubyforge.org/frs/download.php/71096/ruby-enterprise-1.8.7-2010.02.tar.gz

http://www.rubyenterpriseedition.com/download.html

2. インストーラ実行

ダウンロードしたtarballを展開して installer を実行します。
以下のコマンド例においてinstallerが格納されているディレクトリは
Ruby Enterprise Editionのバージョンによって変わります。
適宜読み替えて実行してください。

$ tar zxvf ruby-enterprise-1.8.7-2010.02.tar.gz
$ sudo ./ruby-enterprise-1.8.7-2010.02/installer --no-dev-docs

インストーラを実行すると、Ruby Enterprise Editionを
ビルドするのに必要なソフトウェアがOSにインストールされているか
確認が行われます。

不足しているものがあるとエラーが表示され先に進めません。
前述の「必要なパッケージのインストール」を実行していれば、
エラーが発生することなく先に進めるはずです。

Checking for required software...

 * C compiler... found at /usr/bin/gcc
 * C++ compiler... found at /usr/bin/g++
 * The 'make' tool... found at /usr/bin/make
 * The 'patch' tool... found at /usr/bin/patch
 * Zlib development headers... found
 * OpenSSL development headers... found
 * GNU Readline development headers... found

必須ソフトウェアのチェックが終わると、
インストール先(Target Directory)の入力を求められます。

デフォルトのインストール先は
“/opt/ruby-enterprise-1.8.7-2009.10 /”などですが、
“/usr/local/”と入力すれば、オリジナルのRubyをビルドしたときと
同様に/usr/local以下にインストールされます。

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-2010.02] : /usr/local

本手順ではCentOS にSQLite やPostgreSQL関係のパッケージを
導入していないので途中gemパッケージ”sqlite3-ruby”と
“pg”のインストールに失敗して次のようなエラーが表示されます。
本手順では、MySQLを使う予定なので無視しても問題ありません。

The following gems could not be installed, probably because of an Internet
connection error:

 * sqlite3-ruby
 * pg

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

インストーラを実行し画面の指示に従って操作します。

$ sudo passenger-install-apache2-module

途中でApacheに設定すべき内容が表示されますので控えておきます。

▼Apacheの設定

1. Passengerの設定を追加

/etc/httpd/conf/httpd.confに直接追加してもよいですが、
管理しやすいようPassenger関係の設定は別ファイルにまとめます。

/etc/httpd/conf.d/passenger.conf:

# Passengerの基本設定。
# passenger-install-apache2-moduleインストール中に表示された内容を使用する。
#
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15
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のチューニングのための設定を追加
#
# 参考url:
# http://www.modrails.com/documentation/Users%20guide.html#_resource_control_and_optimization_options
#----------------------------------------------------------
# 同時に使用できる ROR あるいは Rack アプリケーションの最大数
PassengerMaxPoolSize 30

# 一つのアプリケーションに同時に使用できるアプリケーションインスタンス数の最大数
PassengerMaxInstancesPerApp 4

# アイドル状態のアプリケーションインスタンスが存在している最大秒数
PassengerPoolIdleTime 3600

# 空いているプロセスに対して、効率良くキューを割り振る設定
PassengerUseGlobalQueue on

# config/environment.rb等のファイルの存在をチェックする間隔(秒)
PassengerStatThrottleRate 10

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

$ sudo /etc/init.d/httpd start
$ sudo /sbin/chkconfig httpd on

▼MySQLの設定

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

/etc/my.cnfの [mysqld] セクション、 [mysqld_safe] セクション、
[mysql]セクション にそれぞれ /etc/my.cnfの [mysqld] セクション、
[mysqld_safe] セクション、 [mysql]セクション にそれぞれ
default-character-set=utf8 を追加してください。

/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
innodb_file_per_table
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
default-character-set=utf8

[mysql]
default-character-set=utf8

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

$ sudo /etc/init.d/mysqld start
$ sudo /sbin/chkconfig mysqld on

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

$ mysql -uroot
mysql> update user set password=password('********') where user = 'root';
mysql> use mysql;
mysql> delete from user where user = '';
mysql> flush privileges;
mysql> exit;

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

$ mysql -uroot -p
mysql> create database db_redmine default character set utf8;
mysql> grant all on db_redmine.* to user_redmine identified by '********';
mysql> flush privileges;
mysql> exit;

※ ******** の部分は任意のパスワードを設定してください。
このパスワードは後述のdatabase.ymlの設定で使用します。

▼Redmineのインストール

1. redmine-1.0.2 のダウンロード

下記URLからredmine-1.0.2 のtarball(.tar.gz)をダウンロードします。

$ cd ~/src/
$ wget http://rubyforge.org/frs/download.php/72627/redmine-1.0.2.tar.gz

http://rubyforge.org/frs/?group_id=1850

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

ダウンロードしたRedmineのtarballを展開します。
redmine-1.0.2というディレクトリが作成され、
その下にRedmineを構成するファイル群が作成されます。

$ tar zxvf redmine-1.0.2.tar.gz

Redmineの配置先のディレクトリを決定し、そこへ展開したファイルを移動します。
例えば、/var/www/redmine を配置先とする場合、以下のようにします。
あと、シンボリックリンクも作成しておきます。

$ sudo mv redmine-1.0.2 /var/www
$ sudo ln -s /var/www/redmine-1.0.2 /var/www/redmine

3. database.ymlの設定

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

$ cd /var/www/redmine

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

production:
  adapter: mysql
  database: db_redmine
  host: localhost
  username: user_redmine
  password: ********
  encoding: utf8

※ ******** 部分は、MySQL上に作成したRedmineユーザーのパスワードです。

4. email.ymlの設定

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

production:
  delivery_method: :smtp
  smtp_settings:
    address: localhost
    port: 25
    domain: host.example.jp

※host.example.jpの部分は、Redmineを実行するサーバのFQDNとしてください。

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

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

$ sudo rake generate_session_store
$ sudo rake db:migrate RAILS_ENV=production

ここで、以下のエラーが出た場合
rack のバージョンエラーのようなので、バージョンを指定して
rack をインストールします。

rake aborted!
RubyGem version error: rack(1.2.1 not ~> 1.0.1)

$ sudo gem install rack -v=1.0.1

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

まず、Redmineを配置したディレクト以下のファイルを、
Apacheを実行するユーザー・グループ(CentOSの場合はいずれも”apache”)で
読み書きできるよう、オーナーを変更します。

$ sudo chown -R apache:apache /var/www/redmine-1.0.2

以降、どのような形態(URL)でRedmineを利用するかによって設定が異なります。
今回はバーチャルホストでRedmineを実行とします。

▼バーチャルホストでRedmineを実行する

特定のバーチャルホストでRedmineを実行する設定です。Apacheに以下の設定を追加します。

NameVirtualHosts *:80

...

<VirtualHost *:80>
    ServerName www.example.jp
    DocumentRoot /var/www/redmine/public
</VirtualHost>

設定後、Apacheを再起動してください。

以上です。

関連する記事:

  1. 「ServersMan@VPS」にPHP5.3,MySQL5.1,PostgreSQL8 をインストールする
  2. CentOS5.5にPHP5.3 やMySQL5.1 などの最新版をyum でインストールする方法
  3. 「ServersMan@VPS」にsubversion をインストールする

Viewing all articles
Browse latest Browse all 2

Trending Articles