• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Hosting a Rails App
 

Hosting a Rails App

on

  • 600 views

Presentation for CleRB 06-05-2013

Presentation for CleRB 06-05-2013

Statistics

Views

Total Views
600
Views on SlideShare
600
Embed Views
0

Actions

Likes
1
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

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

    Hosting a Rails App Hosting a Rails App Presentation Transcript

    • 06.04.2013Hosting A Rails App
    • Why am I presenting this?• Level Seven• Support a bunch ofproduction rails apps• Biggest has between 20-30 boxes of various types• Still learning
    • We’re Hiring!• Ya i know, who isn’t?• Full time ruby on rails• Happy to help someone pickup their first real rails gig• Also we like contractors andindependents
    • Hosting Options• Heroku• Great for new/youngprojects• Easy to manage• Gets expensive quick• Pretty inflexible, very littlecontrol• AWS• More complicated setup• Can also get expensive buteasier to control (YMMV)• Awesome set of tools that allplay well together• You need to know or be asysadmin
    • Free Micro Instance• Everything in this presentation you can try out for yourself for free• Amazon Free Tier• Free Micro EC2 Instance, 1 static IP, 30 gig EBS space and a loadbalancer plus a bunch of other stuff• http://aws.amazon.com/free/• Any code / scripts will be on github and these slides will be onslideshare. I’ll tweet their location after the talk.• I have a bunch of hidden slides that screenshot the amazon setupprocess too
    • Step 0: Assumptions & Spinup• We’ll be using an Ubuntu 12.01 instance. It’s a default in AWS.• This guide is really Amazon stack heavy. I’ve worked with it, herokuand rackspace (a little) so if you have questions I’m happy to try andhelp.• You should setup an elastic IP on your server right away for easy ofuse, but I’ll talk about it later on.
    • Step 0: Assumptions & Spinup• First spinup a new instance on EC2 using Ubuntu 13.04• Ideally add a 2nd EBS volume with additional storage space• Associate an Elastic IP with that box• Setup a new Host record in ~/.ssh/config for the new serverHost ClerbDemoHostName 107.20.194.126IdentityFile ~/.ssh/AWSJosh.pemForwardAgent yes• That last line will be important later
    • Step 1 - Dependencies• Install the various libraries and dev tools you’ll need to install the restof the server> sudo apt-get -y update #update apt to the latest packages> sudo apt-get -y install build-essential zlib1g-dev libssl-devlibreadline-dev libyaml-dev libcurl4-openssl-dev curl git-core python-software-properties libxslt-dev libxml2-dev imagemagick pdftkopenjdk-7-jre-headless• Install NodeJS for Asset Pipeline> sudo apt-add-repository -y ppa:chris-lea/node.js> sudo apt-get -y update> sudo apt-get -y install nodejs
    • Step 1 - Dependencies• Make your life better by disabling rdoc and ri installation for gems> sudo echo “gem: --no-ri --no-rdoc” >> ~/.gemrc> echo “gem: --no-ri --no-rdoc” >> ~/.gemrc• Set your timezone (optional, maybe you want UTC)>sudo dpkg-reconfigure tzdata #We use America/New York
    • Step 2 - Ruby• 2 Ways to install, from source or via a system-wide RVM install• RVM is really only useful if you plan on having multiple rubies• Passenger 4 supports this and may result in me changing mydefaults pretty soon• For now we’ll go with source> wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz> tar -xzvf ruby-2.0.0-p0.tar.gz> cd ruby-2.0.0-p0> ./configure> make> sudo make install• dd
    • Step 3 - Web Server• Lots of choices. Apache or Nginx w/ Passenger, Thin, Unicorn, etc.• We’ll go with Apache w/ Passenger• I REALLY like nginx but I haven’t used it enough yet> sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev> sudo gem install passenger> sudo passenger-install-apache2-module# Follow instructions on screen
    • Step 3 - Web Server• Setup the modules you’ll need> sudo a2enmod ssl> sudo a2enmod rewrite> sudo a2enmod headers> sudo a2enmod expires> sudo a2enmod passenger• We’ll need a virtual host for the site but we’ll do that later once wehave the code out there for the first time• I like to setup the folder paths now though> sudo mkdir /srv/www> sudo chown ubuntu /srv/www> sudo chgrp ubuntu /srv/www
    • Step 4 - Database• Tons of options, popular ones include Postgres, MySQL for RDBMSor MongoDB as NoSQL Alternative• If you like MySQL you could use Amazon’s RDS Service• We’ll go with PSQL for now> sudo touch /etc/apt/sources.list.d/pgdg.list> sudo sh -c echo "deb http://apt.postgresql.org/pub/repos/apt/precise-pgdg main" >> /etc/apt/sources.list.d/pgdg.list>wget --quiet -O -http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-keyadd -> sudo apt-get -y update> sudo apt-get -y install postgresql-9.2• If your using a different DB and App server you have to modify thepostgres config to allow remote connections
    • Step 5 - DNS & IP Addresses• For AWS your server will need an elastic IP• You’ll need to setup that address in DNS, lots of options here:• I recommend either Amazon’s Route 53 or DNSimple• Both have great APIs, allow a lot of flexibility and aren’t Godaddy• Setup an A Record to point to the IP address you got from amazon
    • Deployment• Most rails apps on custom servers use capistrano• https://help.github.com/articles/deploying-with-capistrano• In short add capistano to your gemfile, bundle install, then:> capify .• Update the config/deploy.rb with your server info and path you wantthe code
    • Deployment• cap deploy:setup to create folder structure• cap deploy:check to verify• At this point you should make sure you database.yml file is on theserver in the proper place• cap deploy• cap deploy:migrations to deploy and run all migrations
    • Deployment• You need a custom cap task for running asset pipeline generation• You can support multiple environments usingcapistrano/ext/multistage• I like to build a cap task to copy the real db config into my projectpost-deploy and not store production un/pw info in git
    • Stuff I Forgot Earlier• You need to create a vhost in /etc/apache2/sites-available• Also make sure your security group allows traffic on port 80
    • Stuff I didn’t cover• Failover including load balancing• Caching solutions like Varnish or advanced nginx caching• Proxy server configurations• Database replication or failover• Backup• Lots of other stuff...
    • References• My Demo App• https://github.com/JoshReedSchramm/HostingRailsDemoApp• The Server Setup Script• https://github.com/JoshReedSchramm/HostingRailsDemoApp/blob/master/doc/setupscript.txt• These Slides• Some crazy slideshare url
    • Questions & Contact• @JoshReedSchramm• josh.schramm@gmail.comorjosh.schramm@lvlsvn.com