Passengerメモ
提供: Astarisk Works Wiki
PassengerはRuby on Railsを動作させるためのApache HTTP Serverのモジュール。
Mongrelに変わってRailsアプリの稼働環境として広まりつつある。
目次 |
インストール
gemを使ってインストールした後、コマンドを作ってモジュールをビルドし、Apacheのhttpd.confに設定を行う必要がある。
> sudo gem install passnger > passenger-install-apache2-module
パッケージを使ってApacheをインストールした場合、apxsがなかったりするので、その場合は次のようにインストールする
> sodu apt-get install apache2-threaded-dev <- aptの場合
> sudo yum install httpd-devel <- yumの場合
実行例
ubuntuの場合、なぜかpassenger-install-apache2-moduleにパスが通らないのでフルパス( /var/lib/gems/1.8/bin/passenger-install-apache2-module)実行する必要がある模様。
以下はpassenger-install-apache2-module のAmazon EC2での実行後のメッセージ。
> sudo passenger-install-apache2-module Welcome to the Phusion Passenger Apache 2 module installer, v3.0.7. 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. -------------------------------------------- Checking for required software... * GNU C++ compiler... found at /usr/bin/g++ * Curl development headers with SSL support... found * OpenSSL development headers... found * Zlib development headers... found * Ruby development headers... found * OpenSSL support for Ruby... found * RubyGems... found * Rake... found at /usr/bin/rake * rack... found * 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 (APU) development headers... found at /usr/bin/apu-1-config -------------------------------------------- Compiling and installing Apache 2 module... バラバラっとコンパイル状況が出力される -------------------------------------------- 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-3.0.7/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7 PassengerRuby /usr/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. -------------------------------------------- Deploying a Ruby on Rails application: an example Suppose you have a Rails application in /somewhere. Add a virtual host to your Apache configuration file and set its DocumentRoot to /somewhere/public: <VirtualHost *:80> ServerName www.yourhost.com DocumentRoot /somewhere/public # <-- be sure to point to 'public'! <Directory /somewhere/public> AllowOverride all # <-- relax Apache security settings Options -MultiViews # <-- MultiViews must be turned off </Directory> </VirtualHost> And that's it! You may also want to check the Users Guide for security and optimization tips, troubleshooting and other useful information: /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7/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.
sub-uriを使う
1台のサーバにいくつものRailsアプリを動かしたい場合がある。その場合にはsub-uriを使う。 手順は次の通り
- 公開したいRailsアプリのpublicディレクトリのシンボリックリンクをwebサーバで公開されているディレクトリに作る
- 作成したシンボリックリンクの名前を RailsBaseURI で設定する
Passenger の状態を見る
passenger-statusを使うと、稼働しているアプリの場所等が確認できる。
> sudo passenger-status *** Cleaning stale folder /tmp/passenger.1.0.31893 ----------- General information ----------- max = 6 count = 1 active = 0 inactive = 1 Waiting on global queue: 0 ----------- Application groups ----------- /usr/local/myapps/myapps-20110817195228: App root: /usr/local/myapps/myapps-20110817195228 * PID: 11954 Sessions: 0 Processed: 14 Uptime: 2h 19m 13s
さらにpassenger-memory-stats コマンドを使うとPassengerとwebサーバのプロセス数、それぞれのプロセスの消費メモリ等が参照できる。
> sudo passenger-memory-stats --------- Apache processes --------- PID PPID VMSize Private Name ------------------------------------ 7769 1 117.9 MB 0.5 MB /usr/sbin/httpd 7787 7769 118.1 MB 0.3 MB /usr/sbin/httpd 7788 7769 118.1 MB 0.3 MB /usr/sbin/httpd 7789 7769 118.1 MB 0.3 MB /usr/sbin/httpd 7790 7769 118.1 MB 0.3 MB /usr/sbin/httpd 9583 7769 118.1 MB 0.3 MB /usr/sbin/httpd ### Processes: 6 ### Total private dirty RSS: 1.90 MB -------- Nginx processes -------- ### Processes: 0 ### Total private dirty RSS: 0.00 MB ----- Passenger processes ----- PID VMSize Private Name ------------------------------- 7771 16.7 MB 0.2 MB PassengerWatchdog 7774 27.8 MB 0.5 MB PassengerHelperAgent 7776 35.7 MB 8.3 MB Passenger spawn server 7779 50.6 MB 0.4 MB PassengerLoggingAgent 11954 154.7 MB 67.4 MB Rails: /usr/local/myapps/myapps-20110817195228 ### Processes: 5 ### Total private dirty RSS: 76.72 MB