2009年07月13日
Redmine を Apache2 + Passenger で動かす。
このたび社内のプロジェクト管理システムを Trac から Redmine に更新しました。実作業を行った北川先輩から、その時の作業メモをブログのネタとしていただきました。ありがとうございます。
北川さんが作業を行った際、ネット上にまとまった情報が無くて非常に苦労したそうです。この情報が誰かのお役に立てれば幸いです。
北川さんが作業を行った際、ネット上にまとまった情報が無くて非常に苦労したそうです。この情報が誰かのお役に立てれば幸いです。
○ サーバの環境
ホスト debian(lenny)
メモリ 512Mbyte
○ 参照サイト
http://redmine.jp/tech_note/install/
○ 必要なパッケージをインストール
# apt-get install make g++
○ Apacheのインストール
# apt-get install apache2
○ Rubyのインストール
# apt-get install ruby rdoc libopenssl-ruby1.8
○ RubyGemsのインストール
# wget "http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz"
# tar xvzf rubygems-1.3.1.tgz
# cd rubygems-1.3.1
# ruby ./setup.rb
# ln -s /usr/bin/gem1.8 /usr/bin/gem
# gem install rubygems-update
○ Ruby on Railsのインストール
# gem install rails
○ MySQLのインストール
# apt-get install mysql-server mysql-client
[MySQLのrootユーザに対するパスワードを設定]
MySQLRootPassword
- MySQLのデータベースの初期化
[redmineで使用するデータベースを作成する]
# mysql -u root -p
Enter password: MySQLRootPassword
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 33
Server version: 5.0.51a-24+lenny1 (Debian)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database redmine character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant select,insert,delete,update,create,drop,file,alter,index on *.* to redmine identified by 'redmine';
Query OK, 0 rows affected (0.00 sec)
mysql> SET PASSWORD FOR 'redmine' = PASSWORD('mypass');
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
Bye
○ Redmineのインストール
# wget http://rubyforge.org/frs/download.php/56909/redmine-0.8.4.tar.gz
# mv redmine-0.8.4.tar.gz /var/lib
# cd /var/lib
# tar xvzf redmine-0.8.4.tar.gz
# mv redmine-0.8.4 redmine
# rm -f redmine-0.8.4.tar.gz
# cd /var/lib/redmine
- データベースの設定
# cp config/database.yml.example config/database.yml
[パスワードとソケット、ユーザ名を指定]
# vi config/database.yml
production:
adapter: mysql
database: redmine
host: localhost
username: redmine
password: mypass
encoding: utf8
socket: /var/run/mysqld/mysqld.sock
[デフォルト言語変更]
# vi config/settings.yml
default_language:
default: ja
# rake db:migrate RAILS_ENV="production"
# rake load_default_data RAILS_ENV="production"
Select language: bg, ca, cs, da, de, en, es, fi, fr, he, hu, it, ja, ko, lt, nl, no, pl, pt, pt-br, ro, ru, sk, sr, sv, th, tr, uk, vn, zh, zh-tw [en] ja
○ Passengerのインストール
# apt-get install apache2-prefork-dev libaprutil1-dev libapr1-dev ruby1.8-dev
# gem install passenger
# passenger-install-apache2-module
Welcome to the Phusion Passenger Apache 2 module installer, v2.2.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.
[リターン入力]
--------------------------------------------
The Apache 2 module was successfully installed.
Please edit your Apache configuration file, and add these lines:
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.4/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.4
PassengerRuby /usr/bin/ruby1.8
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.
[リターン入力]
--------------------------------------------
Deploying a Ruby on Rails application: an example
Suppose you have a Ruby on Rails application in /somewhere. Add a virtual host
to your Apache configuration file, and set its DocumentRoot to
/somewhere/public, like this:
ServerName www.yourhost.com
DocumentRoot /somewhere/public # <-- be sure to point to 'public'!
And that's it! You may also want to check the Users Guide for security and
optimization tips and other useful information:
/usr/lib/ruby/gems/1.8/gems/passenger-2.2.4/doc/Users guide Apache.html
Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
http://www.modrails.com/
Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.
- Apacheの設定
[Passengerモジュールの設定]
# vi /etc/apache2/mods-available/passenger.load
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.4/ext/apache2/mod_passenger.so
# vi /etc/apache2/mods-available/passenger.conf
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.4
PassengerRuby /usr/bin/ruby1.8
[Passengerモジュールの許可]
# a2enmod passenger
# mkdir /var/www
# ln -s /var/lib/redmine/public /var/www/redmine
# chown -R www-data:www-data /var/www
# vi /etc/apache2/sites-available/redmine
RailsBaseURI /redmine
[Redmineサイトの許可]
# a2ensite redmine
[Railsの最大プロセス数の設定]
# vi /etc/apache2/site-available/default
RailsMaxPoolSize 4
[Apacheの再起動]
# /etc/init.d/apache2 reload
- redmineにアクセス
http://localhost/redmine
これで完了
○ はまったところ
プロジェクトのリポジトリにgitリポジトリを指定してリポジトリをブラウズすると結果が表示されるまでかなりの時間がかかってしまう。
[原因1]
topでプロセスを見てみるとredmineのgitアダプタがgitコマンドを発行していて、大きなリポジトリの場合、非常に時間がかかってしまう。
解決方法が以下のサイトにあった。
http://www.redmine.org/issues/1435
# cd /var/lib/redmine
# wget http://www.redmine.org/attachments/1164/git_log_from_db.patch
# patch -p0 < git_log_from_db.patch
# rm -f git_log_from_db.patch
[原因2]
gitリポジトリが更新された後、redmineからリポジトリをブラウズすると mysqld がCPUを100%使用して応答ができなくなってしまう。
原因はMySQLのコンフィグがデフォルトではインストールしたPCと合っていなかった。小規模用のコンフィグで問題解決。
# cp /usr/share/doc/mysql-server-5.0/examples/my-small.cnf /etc/mysql/my.cnf
# /etc/init.d/mysql reload