Successfully reported this slideshow.

Hosting a Rails App

2

Share

Upcoming SlideShare
Media big3
Media big3
Loading in …3
×
1 of 21
1 of 21

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

Hosting a Rails App

  1. 1. 06.04.2013 Hosting A Rails App
  2. 2. Why am I presenting this? • Level Seven • Support a bunch of production rails apps • Biggest has between 20- 30 boxes of various types • Still learning
  3. 3. We’re Hiring! • Ya i know, who isn’t? • Full time ruby on rails • Happy to help someone pick up their first real rails gig • Also we like contractors and independents
  4. 4. Hosting Options • Heroku • Great for new/young projects • Easy to manage • Gets expensive quick • Pretty inflexible, very little control • AWS • More complicated setup • Can also get expensive but easier to control (YMMV) • Awesome set of tools that all play well together • You need to know or be a sysadmin
  5. 5. 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 load balancer plus a bunch of other stuff • http://aws.amazon.com/free/ • Any code / scripts will be on github and these slides will be on slideshare. I’ll tweet their location after the talk. • I have a bunch of hidden slides that screenshot the amazon setup process too
  6. 6. 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, heroku and rackspace (a little) so if you have questions I’m happy to try and help. • You should setup an elastic IP on your server right away for easy of use, but I’ll talk about it later on.
  7. 7. 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 server Host ClerbDemo HostName 107.20.194.126 IdentityFile ~/.ssh/AWSJosh.pem ForwardAgent yes • That last line will be important later
  8. 8. Step 1 - Dependencies • Install the various libraries and dev tools you’ll need to install the rest of the server > sudo apt-get -y update #update apt to the latest packages > sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev curl git-core python- software-properties libxslt-dev libxml2-dev imagemagick pdftk openjdk-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
  9. 9. 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
  10. 10. 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 my defaults 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
  11. 11. 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
  12. 12. 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 we have 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
  13. 13. Step 4 - Database • Tons of options, popular ones include Postgres, MySQL for RDBMS or 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-key add - > 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 the postgres config to allow remote connections
  14. 14. 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
  15. 15. 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 want the code
  16. 16. 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 the server in the proper place • cap deploy • cap deploy:migrations to deploy and run all migrations
  17. 17. Deployment • You need a custom cap task for running asset pipeline generation • You can support multiple environments using capistrano/ext/multistage • I like to build a cap task to copy the real db config into my project post-deploy and not store production un/pw info in git
  18. 18. 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
  19. 19. 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...
  20. 20. 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
  21. 21. Questions & Contact • @JoshReedSchramm • josh.schramm@gmail.com or josh.schramm@lvlsvn.com

×