NOTE: This is pretty old and references Rails 2. Rails 3 beta setup guide here – http://www.cowboycoded.com/2010/07/07/setting-up-rails-3-on-rackspace-cloud-servers/
I have been using Rackspace Cloud for several months and I am loving it. It is similar to Amazon’s cloud offering, but a bit easier to use with more pricing options (although Amazon may have more features). Rackspace has always had great customer service, but I always thought the pricing was ridiculous compared to similar options. Not anymore.. with the Cloud you can get a cheap, flexible and scalable solution (I’m still keeping an eye on reliability.. time will tell). Currently I have 9 servers running on the cloud, but I am still waiting to move my flagship site to the cloud.. reliability and performance seem great so far, but I want to give it a few more months before I commit my highest traffic site to it. Its pretty easy to get a Rails stack running on the cloud using a simple shell script. Here is what I am currently using. Note that some of the versions may be outdated when you read this article, so you may need to update the script. Once you have this server loaded, you can create a backup and then create more servers based on that backup. You can literally have a working dedicated Rails server in less than 5 minutes. I am using a CentOS 5.4 server on the cloud
Server setup shell script: setup.sh
############## # SETUP.SH # ############## #--------------------------------------------------------------------------------------------------------- # INSTALL SOFTWARE AND DEPENDENCIES WITH YUM #--------------------------------------------------------------------------------------------------------- rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm yum -y install mysql mysql-server mysql-devel gcc make zlib zlib-devel openssl openssl-devel git expect pcre pcre-devel readline-devel libxml2-devel libxslt-devel #--------------------------------------------------------------------------------------------------------- # CREATE A DIRECTORY FOR DOWNLOADED FILES AND INSTALL RUBY #--------------------------------------------------------------------------------------------------------- mkdir /home/Downloads cd /home/Downloads wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p174.tar.gz tar -xvf ruby-1.8.7-p174.tar.gz cd ruby-1.8.7-p174 ./configure make make install #--------------------------------------------------------- # INSTALL RUBYGEMS #--------------------------------------------------------- cd .. wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz tar -xvf rubygems-1.3.5.tgz cd rubygems-1.3.5 ruby setup.rb cd / #--------------------------------------------------------------------------------------------------------- # INSTALL GEMS - YOU WILL NEED RAILS, MONGREL AND PROBABLY MYSQL. # THE OTHERS ARE JUST SOME COMMON ONES I USE. #--------------------------------------------------------------------------------------------------------- gem install --no-rdoc --no-ri rails -v=2.3.2 gem install --no-rdoc --no-ri mime-types gem install --no-rdoc --no-ri mysql -- --with-mysql-lib=/usr/lib64/mysql gem install --no-rdoc --no-ri fastercsv gem install --no-rdoc --no-ri mongrel mongrel_cluster gem install --no-rdoc --no-ri json gem install --no-rdoc --no-ri mechanize #--------------------------------------------------------------------------------------------------------- # CHANGE MYSQL TO STARTUP SCRIPT AND START SERVER #--------------------------------------------------------------------------------------------------------- mv /etc/rc3.d/K36mysqld /etc/rc3.d/S36mysqld /etc/init.d/mysqld start #--------------------------------------------------------------------------------------------------------- # INSTALL NGINX WEB SERVER & copy a working config file (you create this) to the config dir #--------------------------------------------------------------------------------------------------------- wget http://sysoev.ru/nginx/nginx-0.7.64.tar.gz tar -xvf nginx-0.7.64.tar.gz cd nginx-0.7.64 ./configure --sbin-path=/sbin/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-md5=auto/lib/md5 --with-sha1=auto/lib/sha1 make make install # THIS IS A DEFAULT NGINX CONFIG THAT I UPLOAD TO THE SERVER. COPY NGINX CONFIG TO THE APPROPRIATE DIR & RESTART cp /root/nginx.conf /usr/local/nginx/nginx.conf /sbin/nginx #--------------------------------------------------------------------------------------------------------- # OPEN UP SECURITY FOR MONGREL #--------------------------------------------------------------------------------------------------------- echo 1 >/selinux/enforce /usr/sbin/setsebool -P httpd_can_network_connect=1 #--------------------------------------------------------------------------------------------------------- # OPTIONAL - SECURITY - THIS IS A DEFAULT IPTABLES SCRIPT I UPLOAD TO THE SERVER. COPY IPTABLES SCRIPT OVER #--------------------------------------------------------------------------------------------------------- cp /root/iptables_config /etc/sysconfig/iptables /etc/init.d/iptables restart #******************************************************************************************************* # NOTE: THE REST OF THIS SCRIPT IS USED TO AUTOMATE PULLING YOUR APP CODE FROM GITHUB, # RAKING THE DB, AND ADDING STARTUP SCRIPTS FOR MONGREL, AND STARTING MONGREL INSIDE # YOUR RAILS APP DIR. IF YOU ARE USING CAPISTRANO, SOME OF THIS IS PROBABLY NOT NECCESSARY, BUT I # HAVE BEEN TOO LAZY TO LEARN CAP.. THIS METHOD WORKS FINE FOR WHAT I DO #******************************************************************************************************* #--------------------------------------------------------------------------------------------------------- # OPTIONAL - CREATE RAILS DIR.. I ALWAYS USE THIS DIRECTORY.. MODIFY TO YOUR TASTE-> /RAILS_APPS #--------------------------------------------------------------------------------------------------------- mkdir rails_apps #--------------------------------------------------------------------------------------------------------- # OPTIONAL - IF YOU ARE USING GITHUB, YOU WILL WANT TO COPY YOUR SSH KEYS. # I JUST FTP THE KEY FILES TO MY SERVER ALONG WITH THE SETUP SCRIPT. # I PLACE ALL THE FILES I AM USING IN /ROOT/ #--------------------------------------------------------------------------------------------------------- mkdir /root/.ssh cp /root/id_rsa.pub /root/.ssh/id_rsa.pub cp /root/id_rsa /root/.ssh/id_rsa cp /root/known_hosts /root/.ssh/known_hosts chmod 700 /root/.ssh/* #--------------------------------------------------------------------------------------------------------- # OPTIONAL - GET THE APP FROM GITHUB #--------------------------------------------------------------------------------------------------------- cd /rails_apps git clone git@github.com:yourusername/yourproject.git mkdir /rails_apps/yourproject/log mkdir /rails_apps/yourproject/tmp/pids #--------------------------------------------------------------------------------------------------------- # OPTIONAL - RAKE THE DB #--------------------------------------------------------------------------------------------------------- cd /rails_apps/yourapp rake db:migrate #--------------------------------------------------------------------------------------------------------- # OPTIONAL - ADD MONGREL STARTUP SCRIPT AND PUT IN RC.LOCAL AND START MONGREL #--------------------------------------------------------------------------------------------------------- cp /root/server_start.sh /rails_apps/server_start.sh chmod 700 /rails_apps/*.sh echo "/rails_apps/start_server.sh" >> /etc/rc.local /rails_apps/server_start.sh
This worked for me last time I tried it. YMMV




#1 by Ashtin on June 13, 2010 - 1:39 pm
Quote
Would I need to change this for other packages like Debian?
Really appreciate the article!
#2 by admin on June 13, 2010 - 4:04 pm
Quote
I am not a Debian user, so I can’t say for sure, but I suspect that the script would work for the most part since Debian has yum. Everything else is compiled so I don’t see why it wouldnt work on another flavor of linux. Give it a try on a 256 Rackspace instance.. it will only cost you a few cents to test it out! Let me know if Debian needs any modifications if you get it figured out and I will post the Debian script here too.
BTW, another cool thing about the RS cloud is you can create new servers from backup images, so I have a 256 instance sitting there for the sole purpose of using its backup as a starter image. When I want a new rails server I just create a new server from that image and I dont even have to run this sh script.
#3 by ankarada oto kiralama on April 23, 2011 - 3:02 pm
Quote
I would say that you have answered my question thanks