• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Deploying Rails Applications
 

Deploying Rails Applications

on

  • 1,537 views

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. ...

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

Statistics

Views

Total Views
1,537
Views on SlideShare
1,507
Embed Views
30

Actions

Likes
2
Downloads
0
Comments
0

2 Embeds 30

http://arrrrug.be 29
http://www.arrrrug.be 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Deploying Rails Applications Deploying Rails Applications Presentation Transcript

    • 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
    • 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 100% Compatible
    • 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
    • Installing Ruby Enterprise Edition 3. Compile & Install # cd ruby-enterprise-1.8.7-2011.02 # ./installer --auto=/opt/ree
    • 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
    • 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
    • Apache & Passenger
    • Apache & Passenger 1. Install more dependencies # apt-get install apache2 libcurl4-openssl-dev 2. Compile & Install Passenger # passenger-install-apache2-module
    • 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
    • Extra Stu
    • Extra Stu GIT # apt-get install git-core MySQL # apt-get install mysql-server # apt-get install libmysqlclient15-dev # gem install mysql
    • 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.debian.org/debian-backports lenny-backports main # MongoDB deb http://downloads.mongodb.org/distros/debian 5.0 10gen
    • 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. Get your code on the server# mkdir /webapps# cd /webapps# git clone git@github.com:user/app.git
    • 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
    • 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
    • Do Not Forget The Directories Where Your App Writes# chown -R www-data:www-data public/attachments# chmod -R 0770 public/attachments
    • 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>
    • Time To Deploy Your App!7. Activate The Virtual Host# a2ensite app8. Restart Apache# apache2ctl restart9. Visit http://app.com
    • Day to Day Maintenance
    • 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 }
    • 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
    • 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
    • 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
    • Day to Day Maintenance Long Running Processes http://god.rubyforge.org Sample configuration file available upon request :)
    • 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>
    • Useful LinksThis presentation and some useful code snippetshttp://bigup.be/lib/DeployingRailsApps.zip Reference Material http://rubyenterpriseedition.com/ http://modrails.com/
    • Q&A
    • Professional Hosting & Application DevelopmentSébastien Delneste Xavier Defrang Data Center Ops Software Craftsman seb@bigup.be xav@bigup.be @sebadel @xavierdefrang