linux passenger多ruby版本共存
1,安装rvm
复制代码 代码示例:
mkdir -p ~/.rvm/src/ && cd ~/.rvm/src && rm -rf ./rvm/
git clone git://github.com/wayneeseguin/rvm.git
cd rvm && ./install
2.修改用户配置文件.bashrc,添加一行代码:
复制代码 代码示例:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
3.重启Terminal.
查询当前版本: rvm info
列出版本: rvm list
更多命令,访问 http://rvm.beginrescueend.com/rvm/
4.安装 ruby
4.1.安装REE
rvm install ree
4.2.安装 ruby- 1.9 . 2
复制代码 代码示例:
rvm install ruby-1.9.2-p180
小技巧:用工具下载好ruby-enterprise-1.8.7-2011.03.tar.gz,ruby-1.9.2-p180.tar.bz2,yaml-0.1.3.tar.gz,然后手工放到~/.rvm/archives 目录下,再运行安装 命令,可以直接解压安装。
5.将某一个版本的ruby设为默认
复制代码 代码示例:
$ rvm --default use 1.9.2 #设置1.9.2为默认版本
$ rvm default #通过default可以快速回到默认版本
$ rvm list default #查看当前版本设置信息
$ rvm reset #恢复系统默认设置
6.安装rails
6.1.安装rails2
复制代码 代码示例:
$ rvm ree-1.8.7-2011.03
$ rvm gemset create rails2
$ rvm genset use rails2
$ gem install --no-ri --no-rdoc rails -v=2.3.12
6.2.安装rails3
复制代码 代码示例:
$ rvm ruby-1.9.2-p180
$ rvm gemset create 'rails3'
$ rvm gemset use rails3
$ gem install rails
Successfully installed activesupport-3.0.9
Successfully installed builder-2.1.2
Successfully installed i18n-0.5.0
Successfully installed activemodel-3.0.9
Successfully installed rack-1.2.3
Successfully installed rack-test-0.5.7
Successfully installed rack-
mount-0.6.14
Successfully installed tzinfo-0.3.28
Successfully installed abstract-1.0.0
Successfully installed erubis-2.6.6
Successfully installed actionpack-3.0.9
Successfully installed arel-2.0.10
Successfully installed activerecord-3.0.9
Successfully installed activeresource-3.0.9
Successfully installed mime-types-1.16
Successfully installed polyglot-0.3.1
Successfully installed treetop-1.4.9
Successfully installed mail-2.2.19
Successfully installed actionmailer-3.0.9
Successfully installed thor-0.14.6
Successfully installed rdoc-3.6.1
Successfully installed railties-3.0.9
Successfully installed bundler-1.0.15
Successfully installed rails-3.0.9
24 gems installed
7.创建别名
复制代码 代码示例:
$ rvm
alias create ree ree-1.8.7-2011.03 #为ree-187的Ruby版本创建一个别名叫:ree
$ rvm alias create ruby192 ruby-1.9.2-p180
$ rvm use ree #通过别名迅速切换
$ rvm delete ree #删除别名
$ rvm alias list # 查看所有的别名
9.使用gemset
复制代码 代码示例:
$ rvm use ree@rails2
$ rvm use ruby192@rails3 --default #设置默认
10.安装passenger
复制代码 代码示例:
$ gem install passenger
$ rvm wrapper 1.9.2 passenger
$ passenger-install-
nginx-module
# Passenger will help you install nginx, the folder is in /opt/nginx
Downloading Nginx...
# wget -O /tmp/root-passenger-12180/nginx.tar.gz http://sysoev.ru/nginx/nginx-1.0.0.tar.gz
--------------------------------------------
Nginx with Passenger support was successfully installed.
The Nginx configuration file (/opt/nginx/conf/nginx.conf)
must contain the correct configuration options in order for Phusion Passenger
to function correctly.
This installer has already modified the configuration file for you! The
following configuration snippet was inserted:
http {
...
passenger_root /usr/local/rvm/gems/ruby-1.9.2-p180@rails3/gems/passenger-3.0.7;
passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.2-p180@rails3/ruby;
...
}
After you start Nginx, you are ready to deploy any number of Ruby on Rails
applications on Nginx.
Press ENTER to
continue.
--------------------------------------------
Deploying a Ruby on Rails application: an example
Suppose you have a Ruby on Rails application in /somewhere. Add a server block
to your Nginx configuration file, set its root to /somewhere/public, and set
'passenger_enabled on', like this:
server {
listen 80;
server_name www.yourhost.com;
root /somewhere/public; # <--- be sure to point to 'public'!
passenger_enabled on;
}
11.设置IP和App
11.1.单个网卡eth1配置多个IP地址
复制代码 代码示例:
ifconfig eth1:0 192.168.56.101 netmask 255.255.255.0 up
ifconfig eth1:1 192.168.56.102 netmask 255.255.255.0 up
11.1.设置demo2(ree@rails2)
复制代码 代码示例:
cd /opt/rails_apps/
rails demo2
cd demo2
11.2.设置demo3(ruby192@rails3)
复制代码 代码示例:
cd /opt/rails_apps/
rails new demo3
cd rails3
passenger start -a 127.0.0.1 -p 3001 -d
(此命令执行俩次,详细信息见passenger.zip)
Downloading Nginx...
# wget -O /tmp/root-passenger-standalone-3917/nginx-1.0.0.tar.gz http://nginx.org/download/nginx-1.0.0.tar.gz
--15:40:02-- http://nginx.org/download/nginx-1.0.0.tar.gz
Resolving nginx.org... 81.19.68.137
Connecting to nginx.org|81.19.68.137|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 654760 (639K) [application/octet-stream]
Saving to: `/tmp/root-passenger-standalone-3917/nginx-1.0.0.tar.gz'
100%[=======================================>] 654,760 56.7K/s in 19s
15:40:21 (34.2 KB/s) - `/tmp/root-passenger-standalone-3917/nginx-1.0.0.tar.gz' saved [654760/654760]
Installing Phusion Passenger Standalone...
[*********************************************] Copying files...
All done!
=============== Phusion Passenger Standalone web server started ===============
PID file: /opt/rails_apps/demo3/tmp/pids/passenger.3001.pid
Log file: /opt/rails_apps/demo3/log/passenger.3001.log
Environment: development
Accessible via: http://127.0.0.1:3001/
Serving in the background as a daemon.
12.配置nginx
复制代码 代码示例:
http{
...
passenger_root /usr/local/rvm/gems/ruby-1.9.2-p180@rails3/gems/passenger-3.0.7;
passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.2-p180@rails3/ruby;
server {
listen 80;
server_name 192.168.56.101;
root /opt/rails_apps/demo2/public;
passenger_enabled on;
rails_env development;
}
server {
listen 80;
server_name 192.168.56.102;
root /opt/rails_apps/demo3/public;
location / {
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host $host;
}
}
}
启动:/opt/nginx/sbin/nginx
停止:/opt/nginx/sbin/nginx -s stop
访问:
rails2:http://192.168.56.101/
rails3:http://192.168.56.102/
13.直接通过项目名称访问,在/etc/hosts中添加:
复制代码 代码示例:
192.168.56.101 demo2
192.168.56.102 demo3