Setting up Speed: Cherokee, Railo and CouchDB on AWS

I am working on a little side project (ansble.com) which is going to require scalability, and a layered architecture that I just couldn't reasonably build in a physical environment. So I started toying with Amazon Web Services and realized that there wasn’t a lot of documentation on the server combination I was planning to use.

The whole architecture is fronted by Cherokee web server, a really fast web server that puts apache and even nginx to shame. It also has a beautiful admin site that makes configuration a breeze. Behind that the app server layer is Railo running on Apache Tomcat. Railo is fast, free, and fast. The DB layer is CouchDB, with a second Cherokee server handling load balancing between the Railo layer and the CouchDB layer. The other decision was to use the Amazon Linux AMI in order to take advantage of Amazon’s hard work and updates.

To get started let’s spin up four Amazon Linux AMI instances (go 64 bit, all the software we are dealing with supports it so no reason for 32 bit). Put all of them in the default security group and then create a security group for each layer of the architecture (One for web servers, application servers, load balancers, and database servers) and place one instance in each group. The instance that will be your web server instance should be in the default security group and the web servers security group. This is important because you can’t change security groups after you spin up your instances.

That done, let’s setup the Railo server first so we can configure the web server as soon as we install it. SSH into your app server instance (something like ssh -i mykeyIcreated ec2-user@myec2instance.amazon.com on linux, or os x) and follow these steps:

  1. execute sudo yum upgrade to upgrade and update the server instance. When I wrote this there were about 121 MB worth of updates as soon as I spun up the instance.
  2. Create a directory to store the railo installer, I went with railoInstaller. (mkdir railoInstaller)
  3. cd ~/railoInstaller and then wget http://www.getrailo.org/down.cfm?item=/railo/remote/download/3.2.3.000/tomcat/linux/railo-3.2.3.000-pl0-linux-x64-installer.run to download the installer.
  4. Change the permissions on the file you just downloaded so it will execute (chmod 744 railo-3.2.3.000-pl0-linux-x64-installer.run)
  5. Execute the installer and walk through the install directions (sudo ./railo-3.2.3.000-pl0-linux-x64-installer.run). Make sure you create a user for railo and tomcat when it asks what user to run it under.
  6. Once the install is done move up one directory (cd ..) and delete the railoInstall folder (rm -r railoInstall)
  7. Railo is now running on port 8888 on the server. This will be accessible to the web server (if you put them both in the default group) but you will need to tinker with the security group’s firewall to be able to access it right now. Do it and go to the admin panels (server and web) and set passwords right away. Close the port once you are done with that.

That’s all there is to getting a basic Railo server up and running on AWS. You will still need to put files on it and setup the contexts but this gets the box up and running and brings us to... the Cherokee web server! SSH into your web server instance and follow these steps:

  1. Add a couple of other RPM repositories to address dependencies by running the following:
    1. sudo rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
    2. sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
    3. sudo rpm -Uvh http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/ius-release-1.0-8.ius.el5.noarch.rpm
  2. Now let’s execute sudo yum upgrade to upgrade and update the server instance.
  3. Time to do the install: sudo yum install cherokee
  4. Server is now installed but not running, no worries we’ll spin it up from the admin panel. Open port 9090 on your web servers security group to your IP and then execute sudo cherokee-admin -b
  5. Open a browser up and go to your web server’s public DNS (it’s on the AWS dashboard) on port 9090. You will be prompted for a username and password. Username is admin and the password is in the terminal window where you just started the cherokee admin. It changes every time so you will have to repeat this process every time you need to access the admin panel.
  6. Go to the information sources tab (top right with a gear on it) and create a new information source for Railo. Name it something that makes sense (appserver-1 maybe...) and for hostname and port enter the local DNS name (also on the AWS dashboard) for your Railo server and 8888 for the port (somethingrandom.amazon.com:8888).
  7. Switch to vServers and click on the behaviours tab, then click the “default” link. We want to setup the default behavior to pass everything on to the application server.
  8. If you aren’t already on the handler tab go there and change the handler select box to ‘http reverse proxy.’ Scroll to the bottom to pick the round robin type to use (ip hash, or round robin) in the selection box for balancer.
  9. Pick the type you want and wait. The screen will flicker and you will be back at the top. Scroll back to the bottom and select the information source you just created from the drop down.
  10. Save it (button or link in the very top right corner of the page, next to the Advanced cog) and head back to the home page.
  11. Start the Cherokee server and check in your browser that you are getting the Railo welcome page.
  12. Back in your terminal window close the cherokee-admin by ctrl+c -ing it. Done with Cherokee!

Now that we have an App Server Layer and a Web Server layer we can turn our attention to the DB Layer and the load balancer for it.

We’ll start with CouchDB since we already know how to setup Cherokee. This is the most complicated install of the three servers but it’s not that bad really.

  1. Add dependencies repositories:
    1. sudo rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
    2. sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
    3. sudo rpm -Uvh http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/ius-release-1.0-6.ius.el5.noarch.rpm
  2. Upgrade and update the server: sudo yum upgrade
  3. Time to install some dependencies. We are going to be using build-couchDB because it simplifies things so we will add git for simplicity. The command you want to run is: sudo yum install gcc gcc-c++ libtool zlib-devel openssl-devel rubygem-rake make git
  4. Now we’ll clone the build-couchDB repo git clone https://github.com/iriscouch/build-couchdb.git
  5. We need to setup the submodules now so everything will work correctly
    1. cd into build-couchdb
    2. git submodule init
    3. git submodule update
  6. Run rake
  7. Wait a long long time... go get a drink, have a snack. Seriously, go watch a movie... Takes about 2 hrs for couchDB to build from source on the micro Amazon AMI.
  8. Now that it’s done building we need to edit the bind port in the local.ini file to 0.0.0.0 so that it will answer something other than localhost (build-couchdb/build/etc/couchdb/local.ini)
  9. Start couchdb couchdb-build/build/bin/couchdb -b and you’re done with CouchDB setup.

That brings us to the last server. The Cherokee load balancer that will sit in front of our CouchDB layer. It’s the same exact process we used for Cherokee before but I’ll repeat it so you don’t have to scroll back up there to read it.

  1. Need to add some RPM repositories to address some dependencies:
    1. sudo rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
    2. sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
    3. sudo rpm -Uvh http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/ius-release-1.0-6.ius.el5.noarch.rpm
  2. Execute sudo yum upgrade to upgrade and update the server instance.
  3. Do the install: sudo yum install cherokee
  4. Server is now installed but not running. We’ll spin it up from the admin panel to make things simple. Open ports 80 and 9090 on the load balancer security group to your IP and then do sudo cherokee-admin -bdecimal
  5. Open a browser up and go to your server’s public DNS (it’s on the AWS dashboard) on port 9090. You wil be prompted for a username and password. Username is admin and the password is in the terminal window where you just started the cherokee admin.
  6. Go to the information sources tab (top right with gears on it) and create a new information source for CouchDB. Name it something that makes sense (couchDB-1 maybe...) and for hostname and port enter the local DNS name for your couchDB server and 5984 for the port (somethingrandom.amazon.com:5984). 5984 is the default port that CouchDB runs on.
  7. Switch to vServers and click on the behaviors tab, then click “default”. We want to setup the default behavior to pass everything on to the CouchDB server.
  8. If you aren’t already on the handler tab go there and change the handler select box to ‘http reverse proxy.’ Scroll to the bottom and pick the round robin type to use (ip hash, or round robin) in the selection box for balancer.
  9. The screen will flicker and you will be back at the top. Scroll back to the bottom and select the information source you just created from the drop down.
  10. Save it (button or link in the very top right corner of the page, next to the Advanced cog) and head back to the home page.
  11. Start the Cherokee server and check in your browser that you are getting the couchDB JSON object when you go to cherokee’s public dns.

With that done you now have a very flexible architecture that will allow you to scale out any layer that presents performance issues. My tests withblitz.io show that this basic setup should be able to handle as up to 12.5 million requests per day with no performance enhancements to the servers. It’s fast. As always if you have questions, thoughts, criticism shoot me an email or @ reply me on twitter. Good luck out there!

PS: if you sign up for blitz.io and use this link I'll get some additional concurrency to test things even better!

Published: 13 Sep 2011 | Tags: ansble , servers , cherokee , aws , railo , couchdb , cfml