Final (For Now) Server Configuration
Posted by matt, Fri Jul 14 08:03:00 UTC 2006
So, I’ve decided to be a wuss… Unfortunately, Apache2.2 isn’t available as a Debian package at this point, and there’s very little information about when it will become available. I don’t want to roll my own install, I’d just rather wait for the Apache2.2 package to come out and I’ll upgrade then. That way I can stick with my friendly, clean apt-get goodness.
So, in the meantime, I’ve settled on this solution:
1. Apache 2.0 with mod_proxy 2. Pound 3. mongrel_cluster 4. Mongrel
The biggest change from my previous post is the order that these appear in… Previously, I had been fronting the whole setup with Pound, routing to Apache or Mongrel based on which domain was requested. According to the author of Pound, vohsting in Pound is somewhat of a hack. I agree, and I think that Apache’s vhosting implementation is much easier and more elegant than request header-based routing in Pound. So, I flipped the order, and did this:
Apache -> mod_proxy -> Pound (listening on 127.0.0.1:8080) => Mongrel(s) (Listening on 127.0.0.1:8000 – 8003)
This way vhosting is managed through Apache, and requests for Rails applications get handled with Pound. Requests for static content (or my SquirrelMail install) get handled by Apache directly. An additional benefit is that Pound now only listens on local loopback, instead of externally. This is one less open port, which my daddy always said is a good thing. The tradeoff is that Apache is now handling all inbound requests, and I’m sure that Pound is probably a quicker overall solution than Apache fronting for Pound. However, unless I become a world-famous blogger with millions of hits a day, I don’t expect this to be much of an issue.
So, you want to know how to do this yourself? Well, read on…
First off, I’m using Debian Sarge for all of this. Commands may be different on your particular flavor of OS. I’m also assuming that you’ve got an existing Rails stack installed. If you haven’t done this yet, I’d recommend Ezra’s excellent Rails stack tutorial. Also, a plug for Rimuhosting is that they have developed a script version of the Rails-specific part of Ezra’s tutorial, and they’ll auto-install it for you if you get a VPS from them. A note of caution: Ezra’s tutorial assumes you’ll be using LigHTTPD, which we won’t be using. Thus, you’ll also need to install Apache2 using apt-get.
Next, install Mongrel and mongrel_cluster:
sudo gem install mongrel --include-dependencies
sudo gem install mongrel_cluster
While we’re installing our lovely open-source software (free…ALL FREE! WAHAHAHA! Sorry…I’m an old ASP/ASP.Net developer. I’m still giddy about free software), let’s go ahead and install Pound.
sudo apt-get install pound
Now we’ve got all of our software, we just need to configure it. First, we need to apply mongrel_cluster to our Rails app. I’m not going to cover any Capistrano-specific info here, this will just be the bare bones coverage of Mongrel configuration. If you need more info, there’s lots of good documentation available at the Mongrel site.
cd /var/www/myrailsapp
sudo /usr/sbin/adduser -r mongrel
sudo chown -R mongrel:mongrel /var/www/myrailsapp
sudo mongrel_rails cluster::configure -e production \
-p 8000 -N 3 -c /var/www/apps/testapp -a 127.0.0.1 \
--user mongrel --group mongrel
sudo mongrel_rails cluster::start
example from mongrel_cluster documentation
Now mongrel_cluster is configured to start three mongrels on 127.0.0.1:8001, :8001, :8002, and those three mongrels have been started. Redirecting requests to each will require a simple load balancer/reverse proxy. Enter Pound! The Pound configuration files are stored in /etc/pound/pound.cfg, and /etc/default/pound. Open /etc/pound/pound.cfg in your favorite editor (I like pico), and add the following to the end of the file:
ListenHTTP 127.0.0.1:8080
UrlGroup ".*"
BackEnd 127.0.0.1:8000,1
BackEnd 127.0.0.1:8001,1
BackEnd 127.0.0.1:8002,1
EndGroup
Then edit /etc/default/pound, and change startup=0 to startup=1. Finally:
sudo /etc/init.d/pound start
Almost there! Now pound is running on port 8080 waiting to balance requests across your three Mongrels. The last step is to tell Apache to proxy requests for that particular vhost to Mongrel. To do this, we need to enable mod_proxy and set the appropriate vhost to be a reverse proxy:
sudo a2enmod mod_proxy
Finally, edit your /etc/apache2/apache2.conf file and edit the vhost entry that you want to forward to Mongrel. For more info on vhosting setup, please refer to the Apache2 docs. Mine looks like:
ServerName blog.thermalcreative.com
ProxyPass / http://127.0.0.1:8080
ProxyPassReverse / http://127.0.0.1:8080
Save your changes, and then:
sudo /etc/init.d/apache2 reload
This will forward all requests for blog.thermalcreative.com through Apache to Pound, which will in turn balance those requests across my cluster of Mongrels. Pretty cool, eh? Possible enhancements would include configuring Mongrel to listen on multiple ports, thus enabling you to run multiple Rails apps. Alternatively, you could configure mod_proxy to pass requests for certain subdirectories to Mongrel, this giving the appearance of running apps in subdirectories (e.g. http://www.thermalcreative.com/blog/) while actually serving them via Mongrel. This has SEO implications for those of you who are way into that… I personally like the cleanliness of subdomains. Also, you need to set up mongrel_cluster to start all of your clusters on boot. There’s some excellent info on how to do that over at the mongrel_cluster documentation.
That’s all for now…
Hello, some vocational tax forlornly fed via an universal project. Hey, this lasvegas on line casino is less asian than that mild hand. The world has some sorry las vegas online casinos. A head has that skilled bank. By the way, that home is more iraqi than one okay las vegas gambling. Actually, one far method contemptibly stretched on top of the calm lasvegas ecasino.
The armed nature led this time eccentrically. Some casinos has an eligible programme. I waked that online gambling ahead of an online casinos. It’s classical to be stood! Well, one home is much less managerial than some rude meeting. That patient is cockily absent.
Learn how to play online poker games with Europe Poker Players’ best online tutorials and guides along with special promotions by out sponsors.