Deploying Rails Apps   ArrrrUG: Belgian Ruby User Group Meeting - March 8, 2011 Sébastien Delneste                        ...
We Have Come a Long Way 2005          2006         2008FastCGI       Mongrel     Passenger
But Wait...
A Few Assumptions
The Stack Your Application  Data Storage   Web ServerApplication Server Ruby Interpreter
Ruby Enterprise Edition
Ruby Enterprise Edition        Friendly Fork of MRI 1.8.7       Improved Memory Allocator       Improved Garbage Collector...
Installing Ruby Enterprise Edition      1. Install dependencies       # apt-get install gcc g++ zlib1g-dev libssl-dev     ...
Installing Ruby Enterprise Edition      3. Compile & Install      # cd ruby-enterprise-1.8.7-2011.02      # ./installer --...
Installing Ruby Enterprise Edition      4. Update and Reload your ~/.bashrc      export PATH=/opt/ree/bin:$PATH      # sou...
Get rid of any existing           Debian Ruby packages# apt-get remove rubygems1.8 libdaemons-ruby1.8 irb1.8              ...
Apache & Passenger
Apache & Passenger  1. Install more dependencies  # apt-get install apache2 libcurl4-openssl-dev  2. Compile & Install Pas...
Apache & Passenger  3. Create /etc/apache2/conf.d/passenger  LoadModule passenger_module /opt/ree/lib/ruby/gems/1.8/gems/ ...
Extra Stu
Extra Stu  GIT  # apt-get install git-core  MySQL  # apt-get install mysql-server  # apt-get install libmysqlclient15-dev ...
Extra Stu  Image Processing   # apt-get install imagemagick  XML Libraries   # apt-get install libxml2-dev libxslt1-dev
Very Conservative Package Management                   /etc/apt/sources.list # Required for SQLite3 deb http://backports.d...
Time To Deploy Your App!
Time To Deploy Your App!1. Setup your deployment keys on GitHub# ssh-keygen -t dsa ~/.ssh/id_dsa# cat ~/.ssh/id_dsa.pub2. ...
Time To Deploy Your App!3. Install your dependencies# gem install bundler# cd app# bundle install4. Configure your database...
Time To Deploy Your App!4. Get the database in shape # rake db:setup RAILS_ENV=production5. Let Apache write to some direc...
Do Not Forget The Directories       Where Your App Writes# chown -R www-data:www-data public/attachments# chmod -R 0770 pu...
Time To Deploy Your App!6. Configure The Virtual Host/etc/apache2/sites-available/app<VirtualHost *:80>  ServerName app.com...
Time To Deploy Your App!7. Activate The Virtual Host# a2ensite app8. Restart Apache# apache2ctl restart9. Visit http://app...
Day to Day Maintenance
Day to Day Maintenance      Rotate the application log files      # vi /etc/logrotate.d/app      /webapps/app/log/*.log {  ...
Day to Day MaintenanceEasy Database Backups# rake db:backup RAILS_ENV=productionCreated backup: db/backup/2011-03-07_09-40...
Day to Day Maintenance      Incremental O site Backups      #!/bin/bash      SOURCE_DIRECTORY="<source directory>"      DE...
Day to Day Maintenance                 Keep your clock on time with NTP                 1. Install and bootstrap          ...
Day to Day Maintenance       Long Running Processes       http://god.rubyforge.org       Sample configuration file availab...
One Last Tip  Deflate all text assets  /etc/apache2/mods-enabled/deflate.conf  <IfModule mod_deflate.c>         AddOutputFi...
Useful LinksThis presentation and some useful code snippetshttp://bigup.be/lib/DeployingRailsApps.zip               Refere...
Q&A
Professional Hosting & Application DevelopmentSébastien Delneste               Xavier Defrang Data Center Ops             ...
Upcoming SlideShare
Loading in …5
×

Deploying Rails Applications

1,853 views

Published on

A quick walkthrough showing how to install a complete Ruby on Rails stack on a Debian Linux server, including some tips for day to day maintenance.

Slides and code snippets can be downloaded here: http://bigup.be/lib/DeployingRailsApps.zip

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,853
On SlideShare
0
From Embeds
0
Number of Embeds
32
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Deploying Rails Applications

  1. 1. Deploying Rails Apps ArrrrUG: Belgian Ruby User Group Meeting - March 8, 2011 Sébastien Delneste Xavier Defrang Data Center Ops Software Craftsman seb@bigup.be xav@bigup.be @sebadel @xavierdefrang
  2. 2. We Have Come a Long Way 2005 2006 2008FastCGI Mongrel Passenger
  3. 3. But Wait...
  4. 4. A Few Assumptions
  5. 5. The Stack Your Application Data Storage Web ServerApplication Server Ruby Interpreter
  6. 6. Ruby Enterprise Edition
  7. 7. Ruby Enterprise Edition Friendly Fork of MRI 1.8.7 Improved Memory Allocator Improved Garbage Collector 100% Compatible
  8. 8. Installing Ruby Enterprise Edition 1. Install dependencies # apt-get install gcc g++ zlib1g-dev libssl-dev libreadline5-dev make apache2-threaded-dev 2. Download & decompress the archive http://www.rubyenterpriseedition.com/download.html # wget ’http://rubyenterpriseedition.googlecode.com/ files/ruby-enterprise-1.8.7-2011.03.tar.gz’ # tar xzf ruby-enterprise-1.8.7-2011.03.tar.gz
  9. 9. Installing Ruby Enterprise Edition 3. Compile & Install # cd ruby-enterprise-1.8.7-2011.02 # ./installer --auto=/opt/ree
  10. 10. Installing Ruby Enterprise Edition 4. Update and Reload your ~/.bashrc export PATH=/opt/ree/bin:$PATH # source .bashrc 6. Enjoy! # which ruby /opt/ree/bin/ruby # which rake /opt/ree/bin/rake # which gem /opt/ree/bin/gem
  11. 11. Get rid of any existing Debian Ruby packages# apt-get remove rubygems1.8 libdaemons-ruby1.8 irb1.8 libdaemons-ruby rdoc1.8 libreadline-ruby1.8
  12. 12. Apache & Passenger
  13. 13. Apache & Passenger 1. Install more dependencies # apt-get install apache2 libcurl4-openssl-dev 2. Compile & Install Passenger # passenger-install-apache2-module
  14. 14. Apache & Passenger 3. Create /etc/apache2/conf.d/passenger LoadModule passenger_module /opt/ree/lib/ruby/gems/1.8/gems/ passenger-3.0.4/ext/apache2/mod_passenger.so PassengerRoot /opt/ree/lib/ruby/gems/1.8/gems/passenger-3.0.4 PassengerRuby /opt/ree/bin/ruby PassengerDefaultUser www-data 4. Sanity Check # apache2ctl configtest Syntax OK
  15. 15. Extra Stu
  16. 16. Extra Stu GIT # apt-get install git-core MySQL # apt-get install mysql-server # apt-get install libmysqlclient15-dev # gem install mysql
  17. 17. Extra Stu Image Processing # apt-get install imagemagick XML Libraries # apt-get install libxml2-dev libxslt1-dev
  18. 18. Very Conservative Package Management /etc/apt/sources.list # Required for SQLite3 deb http://backports.debian.org/debian-backports lenny-backports main # MongoDB deb http://downloads.mongodb.org/distros/debian 5.0 10gen
  19. 19. Time To Deploy Your App!
  20. 20. Time To Deploy Your App!1. Setup your deployment keys on GitHub# ssh-keygen -t dsa ~/.ssh/id_dsa# cat ~/.ssh/id_dsa.pub2. Get your code on the server# mkdir /webapps# cd /webapps# git clone git@github.com:user/app.git
  21. 21. Time To Deploy Your App!3. Install your dependencies# gem install bundler# cd app# bundle install4. Configure your database connection# cp config/database.yml.sample config/database.yml# vi config/database.yml5. Edit any other app specific configuration
  22. 22. Time To Deploy Your App!4. Get the database in shape # rake db:setup RAILS_ENV=production5. Let Apache write to some directories # chown -R www-data:www-data log tmp # chmod -R 0770 log tmp
  23. 23. Do Not Forget The Directories Where Your App Writes# chown -R www-data:www-data public/attachments# chmod -R 0770 public/attachments
  24. 24. Time To Deploy Your App!6. Configure The Virtual Host/etc/apache2/sites-available/app<VirtualHost *:80> ServerName app.com ServerAlias www.app.com ServerAdmin admin@app.com DocumentRoot /webapps/app/public <Directory "/webapps/app/public"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> LogLevel warn ErrorLog /var/log/apache2/app-error.log CustomLog /var/log/apache2/app-access.log combined</VirtualHost>
  25. 25. Time To Deploy Your App!7. Activate The Virtual Host# a2ensite app8. Restart Apache# apache2ctl restart9. Visit http://app.com
  26. 26. Day to Day Maintenance
  27. 27. Day to Day Maintenance Rotate the application log files # vi /etc/logrotate.d/app /webapps/app/log/*.log { daily missingok rotate 30 compress delaycompress sharedscripts postrotate touch /webapps/app/tmp/restart.txt endscript }
  28. 28. Day to Day MaintenanceEasy Database Backups# rake db:backup RAILS_ENV=productionCreated backup: db/backup/2011-03-07_09-40-05/production_dump.sql.gzDeleted 0 backups, 1 backups available http://blog.craigambrose.com/articles/2007/03/01/a-rake-task-for-database-backups
  29. 29. Day to Day Maintenance Incremental O site Backups #!/bin/bash SOURCE_DIRECTORY="<source directory>" DESTINATION_HOST="<target hostname>" DESTINATION_USER="<username>" DESTINATION_DIRECTORY="/backup" BACKUP_DIRECTORY="$DESTINATION_DIRECTORY/`date +%Y%m%d%`" RSYNC_OPTIONS="--archive -b --backup-dir $BACKUP_DIRECTORY -e ssh" RSYNC_TEST_OPTIONS="--stats -n" RSYNC_COMMAND="/usr/bin/rsync $RSYNC_OPTIONS" set -x $RSYNC_COMMAND $SOURCE_DIRECTORY $DESTINATION_USER@$DESTINATION_HOST:$DESTINATION_DIRECTORY/current http://seb.delneste.be/2010/03/16/poor-man-time-machine
  30. 30. Day to Day Maintenance Keep your clock on time with NTP 1. Install and bootstrap # apt-get install ntpdate # /usr/sbin/ntpdate -u ntp.belnet.be 2. Sync clock in a cron job0 * * * * root /usr/sbin/ntpdate -u ntp.belnet.be >> /dev/null 2>&1; /sbin/hwclock -w
  31. 31. Day to Day Maintenance Long Running Processes http://god.rubyforge.org Sample configuration file available upon request :)
  32. 32. One Last Tip Deflate all text assets /etc/apache2/mods-enabled/deflate.conf <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html text/ plain text/xml text/css application/javascript </IfModule>
  33. 33. Useful LinksThis presentation and some useful code snippetshttp://bigup.be/lib/DeployingRailsApps.zip Reference Material http://rubyenterpriseedition.com/ http://modrails.com/
  34. 34. Q&A
  35. 35. Professional Hosting & Application DevelopmentSébastien Delneste Xavier Defrang Data Center Ops Software Craftsman seb@bigup.be xav@bigup.be @sebadel @xavierdefrang

×