Dabits

サーバサイドから運営まで何でもやるエンジニア系DJ

CentOSでmod_rails(Passenger)のインストール

仕事先でmod_railsを使う機会があったのでインストールしてみました。 mod_railsは何かというと、ruby on railsapacheのモジュールとして起動する事により 効率を大幅に上げよう、というものです。 また、特定数秒(デフォでは120秒)アクセスがないと、自動的にプロセスが終了したり、 アクセスが多いと増加するので、単純にmongrelをたくさん起動しておくよりも効率的です。 以前はApache+mongrel_railsでしたが、明らかにレスポンスが向上しました。 では早速インストールの記録を。

1.passengerのインストール gemを使ってpassengerをインストールします。 なんか下にwarning出たけど問題ありませんでした。

[root@rails-dev ~]# gem install passenger Building native extensions. This could take a while... Successfully installed rack-0.9.1 Successfully installed passenger-2.0.6 2 gems installed Installing ri documentation for rack-0.9.1... Installing ri documentation for passenger-2.0.6... Installing RDoc documentation for rack-0.9.1... Installing RDoc documentation for passenger-2.0.6... ./doc/template/horo.rb:17: warning: already initialized constant FONTS ./doc/template/horo.rb:19: warning: already initialized constant STYLE ./doc/template/horo.rb:213: warning: already initialized constant XHTML_PREAMBLE ./doc/template/horo.rb:221: warning: already initialized constant HEADER ./doc/template/horo.rb:272: warning: already initialized constant FILE_PAGE ./doc/template/horo.rb:300: warning: already initialized constant CLASS_PAGE ./doc/template/horo.rb:338: warning: already initialized constant METHOD_LIST ./doc/template/horo.rb:486: warning: already initialized constant FOOTER ./doc/template/horo.rb:491: warning: already initialized constant BODY ./doc/template/horo.rb:503: warning: already initialized constant SRC_PAGE ./doc/template/horo.rb:531: warning: already initialized constant FR_INDEX_BODY ./doc/template/horo.rb:535: warning: already initialized constant FILE_INDEX ./doc/template/horo.rb:583: warning: already initialized constant CLASS_INDEX ./doc/template/horo.rb:584: warning: already initialized constant METHOD_INDEX ./doc/template/horo.rb:586: warning: already initialized constant INDEX

2.http-develのインストール mod_railsを生成するにはapacheモジュールとしてのコンパイルが必要です。 事前にyumで開発キットをインストールしておきます。 (その前にgcc,gppなどをあらかじめインストールしておいてください。)

[root@rails-dev ~]# yum -y install httpd-devel base 100% |=========================| 1.1 kB 00:00 updates 100% |=========================| 951 B 00:00 primary.xml.gz 100% |=========================| 369 kB 00:00 updates : ################################################## 796/796 addons 100% |=========================| 951 B 00:00 extras 100% |=========================| 1.1 kB 00:00 Setting up Install Process ・ ・ ・ Installed: httpd-devel.i386 0:2.2.3-11.el5_2.centos.4 Dependency Installed: apr-devel.i386 0:1.2.7-11 apr-util-devel.i386 0:1.2.7-7.el 5 Updated: httpd.i386 0:2.2.3-11.el5_2.centos.4 Dependency Updated: httpd-manual.i386 0:2.2.3-11.el5_2.centos.4 mod_ssl.i386 1:2 .2.3-11.el5_2.centos.4 Complete!

3.passengerの設定 passengerを設定し、モジュールを作成します。

[root@rails-dev insoshi]# passenger-install-apache2-module Welcome to the Phusion Passenger Apache 2 module installer, v2.0.6. 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. 1 Checking for required software... * GNU C++ compiler... found at /usr/bin/g++ * Ruby development headers... found * OpenSSL support for Ruby... found * RubyGems... found * Rake... found at /usr/bin/rake * Apache 2... found at /usr/sbin/httpd * Apache 2 development headers... found at /usr/sbin/apxs * Apache Portable Runtime (APR) development headers... found at /usr/bin/apr-1- config * Apache Portable Runtime Utility (APR) development headers... found at /usr/bi n/apu-1-config * fastthread... found * rack... found -------------------------------------------- -------------------------------------------- Compiling and installing Apache 2 module... cd /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6 /usr/bin/ruby -S rake clean apache2 (in /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6) ・・・コンパイルが始まる・・・ -------------------------------------------- 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.0.6/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6 PassengerRuby /usr/bin/ruby ↑以上がapacheの設定に書き込む部分になるので、コピーしておきます。 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 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.0.6/doc/Users guide.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.

4.apacheの設定をする 先ほどコピーした内容を貼り付け、さらに具体的に使用するrailsアプリケーションの指定をします。 今回はinsoshiというrailsアプリケーションを使いました。

[root@rails-dev ~]# vi /etc/httpd/conf.d/mod_rails.conf LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6 PassengerRuby /usr/bin/ruby ↑先ほどコピーした部分をそのまま貼り付け DocumentRoot /var/shared/insoshi/public Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order allow,deny Allow from all ↑DocumentRootにはpublicを指定

5.apacheのリロード apacheの設定をリロードさせて、設定を適用します。

[root@rails-dev ~]#service httpd reload

これで対象のサーバにアクセスすると、無事起動する事ができました。 *参考サイト Passenger (mod_rails for Apache) を使ってRedmineを動かしてみたよ! - RX-7乗りの適当な日々 Passenger (mod_rails for apache)での色んな設定値について調べてみた Apache上でRuby on Railsアプリケーションを動かす/Passenger(mod_rails for Apache)の利用