Advanced Deployment with Rails
JAX 2009




Jonathan Weiss, 21 April 2009
Peritor GmbH
Who am I?

Jonathan Weiss

•  Consultant for Peritor GmbH in Berlin
•  Specialized in Rails, Scaling, Deployment, and Code...
Advanced Deployment




                      3
Advanced Deployment




                      4
Deployment




                        Deployment


             Architecture            Process




                     ...
Infrastructure
  Architecture




                 6
Simple Rails Setup




       One Rails instance handles all requests
       Rails is (was) single-threaded: There is only...
Rails Setup




              8
Rails Setup




              9
Typical Rails Setup

 •  A load-balancer distributes the incoming requests
 •  Some load-balancers will deliver static req...
Rails Setup Options




                      11
Deployment Questions
                                           Apache?          Pound?
             mod_proxy_balancer?

...
The relevant ones

Rails Application Server             Proxy/Web Server
 •  Mongrel                           •  Apache2
...
Mongrel




          14
Mongrel

•  Complete HTTP-Server that can load arbitrary Ruby-servlets
•  Built-in Rails support




                     ...
Mongrel




          16
Mongrel




          Apache 2.2 – mod_proxy_balancer
          Lighttpd
          Nginx
          HA-Proxy
          Poun...
Mongrel Cluster



 Utility to manage several Mongrel instances




                                               18
Mongrel Cluster



 Control Mongrels




                    19
Mongrel

•  Very robust
•  Strict HTTP parser
•  Easy to debug (HTTP!)
•  Defacto standard deployment with Apache 2.2 and ...
mod_rails




            21
mod_rails a.k.a Phusion Passenger

 •  Module for Apache 2.2 (and Nginx)
 •  Allows Apache to control Rails instances
 •  ...
Install Phusion Passenger

 Install module




 Load and activate in Apache




                               23
Control Phusion Passenger



 Restart after deployment:




                             24
Phusion Passenger




      One machine

                    25
Phusion Passenger




      One machine   Multiple machines

                                        26
Phusion Passenger

 •  Fairly new but ready for production
 •  Makes setup easier – on the single machine level
 •  Multip...
JRuby




        28
•  Ruby Runtime on the Java Virtual Machine
•  Implemented in Java and Ruby
•  Compiles Ruby into Java-bytecode
•  Integra...
JRuby on Rails




                 30
JRuby on Glassfish




      One machine

                    31
JRuby on Glassfish




      One machine   Multiple machines

                                        32
Setup JRuby on Glassfish

 1.  Download JRuby and Glassfish
 2.  From http://blog.headius.com/2008/08/zero-to-production-in-...
Warble Configuration



                      Define min/max
                      Rails runtimes




                      ...
Infrastructure
     Process




                 35
Deployment Process Requirements




                 Reproducible   Accountable   Notifications
     Automatic




        ...
Deployment Options




                     37
Deployment Options




                     38
Deployment Options




                     39
Deployment Options




                     40
What does Capistrano do?




                           41
Capistrano Deployment Cycle




                              42
The Deployment Lifecycle




                           43
Requirements




               44
Get Your Capistrano On




                         45
Get Your Capistrano On

 config/deploy.rb




                         46
Capistrano

 Your one-stop deployment shop




                                 47
Capistrano Tasks
 To find all the tasks available in your project, use




                                                ...
Custom Tasks
 Override build-in




                     49
Write your own Tasks




                       50
Write your own Tasks




                       51
The Rest

 •  Callbacks
 •  Transactions
 •  Capistrano Shell
 •  Custom tasks and namespaces
 •  Staging and multiple set...
One Click Deploy




                   53
Webistrano




             54
Webistrano

•  Web-UI to Capistrano
•  Manages projects and their stages
•  Alerting and Accounting
•  Scriptable and exte...
Macistrano

 •  Mac-GUI to Webistrano
 •  Fire and monitor deployments from your desktop




                             ...
Cloud Infrastructure




                       57
Cloud Infrastructure

Servers come and go
 •  You do not know your servers before deploying
 •  Restarting is the same as ...
Solution #1

Query and manually adjust
 •  Servers do not change that often
 •  New nodes probably need manual interventio...
Solution #2

Use a central directory service
 •  A central place to manage your running instances
 •  Instances query the ...
Solution #2

Use a central directory service
 •  A central place to manage your running instances
 •  Instances query the ...
Central Directory

Different Implementations
 •  File on S3
 •  SimpleDB
 •  A complete service,
    capable of monitoring...
Final words


Once understood the Rails infrastructure is quite simple


Passenger is very easy to setup and should be the...
Questions?




             64
Peritor GmbH

Teutonenstraße 16
14129 Berlin
Telefon: +49 (0)30 69 20 09 84 0
Telefax: +49 (0)30 69 20 09 84 9

Internet: ...
Upcoming SlideShare
Loading in...5
×

Deployment with Ruby on Rails

8,280

Published on

Introduction to deployment with Ruby on Rails presented at JAX09 in Mainz by Jonathan Weiss.

Learn about the deployment architectures and setups (web and app tier) and using Capistrano/Webistrano.

Published in: Technology
1 Comment
13 Likes
Statistics
Notes
  • What a great slide! We're looking at message broker solutions right now ... you a top candidate!
    http://www.mediafire.com/download/kx9l74xfsn96454/
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
8,280
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
202
Comments
1
Likes
13
Embeds 0
No embeds

No notes for slide

Deployment with Ruby on Rails

  1. 1. Advanced Deployment with Rails JAX 2009 Jonathan Weiss, 21 April 2009 Peritor GmbH
  2. 2. Who am I? Jonathan Weiss •  Consultant for Peritor GmbH in Berlin •  Specialized in Rails, Scaling, Deployment, and Code Review •  Webistrano - Rails deployment tool •  FreeBSD Rubygems and Ruby on Rails maintainer http://www.peritor.com http://blog.innerewut.de http://twitter.com/jweiss 2
  3. 3. Advanced Deployment 3
  4. 4. Advanced Deployment 4
  5. 5. Deployment Deployment Architecture Process 5
  6. 6. Infrastructure Architecture 6
  7. 7. Simple Rails Setup One Rails instance handles all requests Rails is (was) single-threaded: There is only one concurrent request 7
  8. 8. Rails Setup 8
  9. 9. Rails Setup 9
  10. 10. Typical Rails Setup •  A load-balancer distributes the incoming requests •  Some load-balancers will deliver static requests themselves •  Several Rails instances handle all requests •  Number of concurrent requests equals number of Rails instances 10
  11. 11. Rails Setup Options 11
  12. 12. Deployment Questions Apache? Pound? mod_proxy_balancer? FastCGI? Mongrel? Proxy? Load-balancer? Nginx? mod_rails? Ebb? HA-Proxy? Reverse Proxy? Swiftiply? Phusion Passenger? Thin? Pen? Rails Application Lighttpd? Server? 12
  13. 13. The relevant ones Rails Application Server Proxy/Web Server •  Mongrel •  Apache2 •  mod_rails / Phussion Passenger •  Nginx •  JRuby + Glassfish & Co. •  HA-Proxy 13
  14. 14. Mongrel 14
  15. 15. Mongrel •  Complete HTTP-Server that can load arbitrary Ruby-servlets •  Built-in Rails support 15
  16. 16. Mongrel 16
  17. 17. Mongrel Apache 2.2 – mod_proxy_balancer Lighttpd Nginx HA-Proxy Pound 17
  18. 18. Mongrel Cluster Utility to manage several Mongrel instances 18
  19. 19. Mongrel Cluster Control Mongrels 19
  20. 20. Mongrel •  Very robust •  Strict HTTP parser •  Easy to debug (HTTP!) •  Defacto standard deployment with Apache 2.2 and mod_proxy_balancer •  Can be a bit difficult to setup (mongrel_cluster, ports, Apache) •  Not so easy on mass/virtual hosting 20
  21. 21. mod_rails 21
  22. 22. mod_rails a.k.a Phusion Passenger •  Module for Apache 2.2 (and Nginx) •  Allows Apache to control Rails instances •  Apache starts and stops application instances depending on the application load •  Able to run any RACK-compatible Ruby application (Merb & Co.) •  Only manages Rails on one host - no remote instances •  Combine with HTTP-Proxy / balancing solution 22
  23. 23. Install Phusion Passenger Install module Load and activate in Apache 23
  24. 24. Control Phusion Passenger Restart after deployment: 24
  25. 25. Phusion Passenger One machine 25
  26. 26. Phusion Passenger One machine Multiple machines 26
  27. 27. Phusion Passenger •  Fairly new but ready for production •  Makes setup easier – on the single machine level •  Multiple servers still require load balancer •  Suitable for mass-hosting •  (upcoming) standard way of deploying Rails 27
  28. 28. JRuby 28
  29. 29. •  Ruby Runtime on the Java Virtual Machine •  Implemented in Java and Ruby •  Compiles Ruby into Java-bytecode •  Integrates with Java code and libraries •  Java’s promises of native threads and JIT •  Allows for Ruby/Rails applications to be packaged as WAR files •  WAR files deployable on any J2EE-container: Glassfish, JBoss, Tomcat, Jetty, … 29
  30. 30. JRuby on Rails 30
  31. 31. JRuby on Glassfish One machine 31
  32. 32. JRuby on Glassfish One machine Multiple machines 32
  33. 33. Setup JRuby on Glassfish 1.  Download JRuby and Glassfish 2.  From http://blog.headius.com/2008/08/zero-to-production-in-15-minutes.html 33
  34. 34. Warble Configuration Define min/max Rails runtimes 34
  35. 35. Infrastructure Process 35
  36. 36. Deployment Process Requirements Reproducible Accountable Notifications Automatic 36
  37. 37. Deployment Options 37
  38. 38. Deployment Options 38
  39. 39. Deployment Options 39
  40. 40. Deployment Options 40
  41. 41. What does Capistrano do? 41
  42. 42. Capistrano Deployment Cycle 42
  43. 43. The Deployment Lifecycle 43
  44. 44. Requirements 44
  45. 45. Get Your Capistrano On 45
  46. 46. Get Your Capistrano On config/deploy.rb 46
  47. 47. Capistrano Your one-stop deployment shop 47
  48. 48. Capistrano Tasks To find all the tasks available in your project, use 48
  49. 49. Custom Tasks Override build-in 49
  50. 50. Write your own Tasks 50
  51. 51. Write your own Tasks 51
  52. 52. The Rest •  Callbacks •  Transactions •  Capistrano Shell •  Custom tasks and namespaces •  Staging and multiple setups •  Gem dependencies •  Support for deploying through gateway servers •  Server setup with deprec gem 52
  53. 53. One Click Deploy 53
  54. 54. Webistrano 54
  55. 55. Webistrano •  Web-UI to Capistrano •  Manages projects and their stages •  Alerting and Accounting •  Scriptable and extendable •  BSD License http://labs.peritor.com/webistrano 55
  56. 56. Macistrano •  Mac-GUI to Webistrano •  Fire and monitor deployments from your desktop http://github.com/mattmatt/macistrano 56
  57. 57. Cloud Infrastructure 57
  58. 58. Cloud Infrastructure Servers come and go •  You do not know your servers before deploying •  Restarting is the same as introducing a new machine You can’t hardcode IPs database.yml 58
  59. 59. Solution #1 Query and manually adjust •  Servers do not change that often •  New nodes probably need manual intervention •  Use AWS ElasticIPs to ease the pain Set servers dynamically AWS Elastic IP 59
  60. 60. Solution #2 Use a central directory service •  A central place to manage your running instances •  Instances query the directory and react 60
  61. 61. Solution #2 Use a central directory service •  A central place to manage your running instances •  Instances query the directory and react 61
  62. 62. Central Directory Different Implementations •  File on S3 •  SimpleDB •  A complete service, capable of monitoring and controlling your instances 62
  63. 63. Final words Once understood the Rails infrastructure is quite simple Passenger is very easy to setup and should be the default choice Learn how to use Capistrano and Webistrano, they will make your life much easier – even in non-Rails setups 63
  64. 64. Questions? 64
  65. 65. Peritor GmbH Teutonenstraße 16 14129 Berlin Telefon: +49 (0)30 69 20 09 84 0 Telefax: +49 (0)30 69 20 09 84 9 Internet: www.peritor.com E-Mail: kontakt@peritor.com 65 Peritor GmbH - Alle Rechte vorbehalten 65
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×