`

Linux 环境passenger多ruby版本共存部署

阅读更多

1.安装rvm

Ruby代码  收藏代码
  1. mkdir -p ~/.rvm/src/ && cd ~/.rvm/src && rm -rf ./rvm/   
  2. git clone git://github.com/wayneeseguin/rvm.git   
  3. cd rvm && ./install   

 2.修改用户配置文件.bashrc,添加一行代码:

Shell代码  收藏代码
  1. [[ -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设为默认

Ruby代码  收藏代码
  1. $ rvm --default use 1.9.2   #设置1.9.2为默认版本  
  2.   
  3. $ rvm default      #通过default可以快速回到默认版本  
  4. $ rvm list default     #查看当前版本设置信息  
  5. $ rvm reset     #恢复系统默认设置    

 

 

6.安装rails

6.1.安装rails2

Ruby代码  收藏代码
  1. $ rvm ree-1.8.7-2011.03  
  2. $ rvm gemset create rails2  
  3. $ rvm genset use rails2  
  4. $ gem install --no-ri --no-rdoc rails -v=2.3.12  

 6.2.安装rails3

Ruby代码  收藏代码
  1. $ rvm ruby-1.9.2-p180  
  2. $ rvm gemset create 'rails3'  
  3. $ rvm gemset use rails3  
  4. $ gem install rails  
  5. Successfully installed activesupport-3.0.9  
  6. Successfully installed builder-2.1.2  
  7. Successfully installed i18n-0.5.0  
  8. Successfully installed activemodel-3.0.9  
  9. Successfully installed rack-1.2.3  
  10. Successfully installed rack-test-0.5.7  
  11. Successfully installed rack-mount-0.6.14  
  12. Successfully installed tzinfo-0.3.28  
  13. Successfully installed abstract-1.0.0  
  14. Successfully installed erubis-2.6.6  
  15. Successfully installed actionpack-3.0.9  
  16. Successfully installed arel-2.0.10  
  17. Successfully installed activerecord-3.0.9  
  18. Successfully installed activeresource-3.0.9  
  19. Successfully installed mime-types-1.16  
  20. Successfully installed polyglot-0.3.1  
  21. Successfully installed treetop-1.4.9  
  22. Successfully installed mail-2.2.19  
  23. Successfully installed actionmailer-3.0.9  
  24. Successfully installed thor-0.14.6  
  25. Successfully installed rdoc-3.6.1  
  26. Successfully installed railties-3.0.9  
  27. Successfully installed bundler-1.0.15  
  28. Successfully installed rails-3.0.9  
  29. 24 gems installed  

 

7.创建别名

Ruby代码  收藏代码
  1. $ rvm alias create ree ree-1.8.7-2011.03 #为ree-187的Ruby版本创建一个别名叫:ree  
  2. $ rvm alias create ruby192 ruby-1.9.2-p180  
  3. $ rvm use ree #通过别名迅速切换  
  4. $ rvm delete ree #删除别名   
  5. $ rvm alias list # 查看所有的别名   

 

9.使用gemset

Ruby代码  收藏代码
  1. $ rvm use ree@rails2  
  2. $ rvm use ruby192@rails3 --default   #设置默认  

 

10.安装passenger

Ruby代码  收藏代码
  1. $ gem install passenger  
  2. $ rvm wrapper 1.9.2 passenger  
  3. $ passenger-install-nginx-module  
  4. # Passenger will help you install nginx, the folder is in /opt/nginx  
  5. Downloading Nginx...  
  6. # wget -O /tmp/root-passenger-12180/nginx.tar.gz http://sysoev.ru/nginx/nginx-1.0.0.tar.gz  
  7. --------------------------------------------  
  8.   
  9. Nginx with Passenger support was successfully installed.  
  10.   
  11. The Nginx configuration file (/opt/nginx/conf/nginx.conf)  
  12. must contain the correct configuration options in order for Phusion Passenger  
  13. to function correctly.  
  14.   
  15. This installer has already modified the configuration file for you! The  
  16. following configuration snippet was inserted:  
  17.   
  18.   http {  
  19.       ...  
  20.       passenger_root /usr/local/rvm/gems/ruby-1.9.2-p180@rails3/gems/passenger-3.0.7;  
  21.       passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.2-p180@rails3/ruby;  
  22.       ...  
  23.   }  
  24.   
  25. After you start Nginx, you are ready to deploy any number of Ruby on Rails  
  26. applications on Nginx.  
  27.   
  28. Press ENTER to continue.  
  29.   
  30. --------------------------------------------  
  31.   
  32. Deploying a Ruby on Rails application: an example  
  33.   
  34. Suppose you have a Ruby on Rails application in /somewhere. Add a server block  
  35. to your Nginx configuration file, set its root to /somewhere/public, and set  
  36. 'passenger_enabled on', like this:  
  37.   
  38.    server {  
  39.       listen 80;  
  40.       server_name www.yourhost.com;  
  41.       root /somewhere/public;   # <--- be sure to point to 'public'!  
  42.       passenger_enabled on;  
  43.    }    

 

11.设置IP和App

11.1.单个网卡eth1配置多个ip地址

Ruby代码  收藏代码
  1. ifconfig eth1:0 192.168.56.101 netmask 255.255.255.0 up  
  2. 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)

Ruby代码  收藏代码
  1. Downloading Nginx...  
  2. # wget -O /tmp/root-passenger-standalone-3917/nginx-1.0.0.tar.gz http://nginx.org/download/nginx-1.0.0.tar.gz  
  3. --15:40:02--  http://nginx.org/download/nginx-1.0.0.tar.gz  
  4. Resolving nginx.org... 81.19.68.137  
  5. Connecting to nginx.org|81.19.68.137|:80... connected.  
  6. HTTP request sent, awaiting response... 200 OK  
  7. Length: 654760 (639K) [application/octet-stream]  
  8. Saving to: `/tmp/root-passenger-standalone-3917/nginx-1.0.0.tar.gz'  
  9.   
  10. 100%[=======================================>] 654,760     56.7K/s   in 19s      
  11.   
  12. 15:40:21 (34.2 KB/s) - `/tmp/root-passenger-standalone-3917/nginx-1.0.0.tar.gz' saved [654760/654760]  
  13.   
  14. Installing Phusion Passenger Standalone...  
  15. [*********************************************] Copying files...                 
  16. All done!  
  17.   
  18. =============== Phusion Passenger Standalone web server started ===============  
  19. PID file: /opt/rails_apps/demo3/tmp/pids/passenger.3001.pid  
  20. Log file: /opt/rails_apps/demo3/log/passenger.3001.log  
  21. Environment: development  
  22. Accessible via: http://127.0.0.1:3001/  
  23.   
  24. Serving in the background as a daemon.  
  25. ===============================================================================  

 

 

12.配置nginx

Ruby代码  收藏代码
  1. http{  
  2.     ...  
  3.     passenger_root /usr/local/rvm/gems/ruby-1.9.2-p180@rails3/gems/passenger-3.0.7;  
  4.     passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.2-p180@rails3/ruby;   
  5.    
  6.     server {  
  7.         listen 80;  
  8.         server_name 192.168.56.101;   
  9.         root /opt/rails_apps/demo2/public;  
  10.         passenger_enabled on;  
  11.         rails_env development;  
  12.     }  
  13.       
  14.     server {  
  15.         listen 80;  
  16.         server_name 192.168.56.102;  
  17.         root /opt/rails_apps/demo3/public;  
  18.         location / {  
  19.           proxy_pass http://127.0.0.1:3001;  
  20.           proxy_set_header Host $host;  
  21.         }  
  22.     }  
  23. }  

 

启动:/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中添加:

Ruby代码  收藏代码
  1. 192.168.56.101 demo2  
  2. 192.168.56.102 demo3  

 

4
1
分享到:
评论
2 楼 shuaigelingfei 2013-04-26  
telephone999 写道

1 楼 telephone999 2013-04-25  

相关推荐

Global site tag (gtag.js) - Google Analytics