Blog Migration Aftermath
Here's the results of the blog move from my point of view:
- I used to receive at least one problem report from FeedBurner a day. Nothing since the move. There was one problem report on the morning after the move, but it was move related.
- Learned a few things about Apache HTTPD, Mongrel and Pound. Enjoyed the puns attached to having a pack of mongrels at the pound.
- Enjoyed how Typo's architecture made it easier to migrate than I feared.
The most important lesson for me is the importance of having some control over your infrastructure. Shared hosting is a fine start. I still use it to host my pictures and my email. The price of shared hosting is a loss of control over your applications. You can't be trusted to have root access since you may impact other customer's applications. You can't have access to some utilities that help you troubleshoot your problems because you may expose someone else's application's internals.
The nice thing with using a VPS hosting provider such as Slicehost is that you do gain most of that control back. You still have to share the server's resources with the other users on the system, but you do have full root access in you slice. You can reinstall the OS, install the latest and greatest release of the software and manage what gets exposed to the internet and what remains internal. The console and the option of reinstalling the software is right there in the management console.
Tweaking My Blog Config
I really don't expect to get too much traffic on my blog. FeedBurner tells me that I do have a few subscribers, and a handful of visitors a day. My pride does suffer a little because my wife's blog gets more traffic than I do. She does have a much better voice than I do when it comes to blogging. She also says that my content is, well, boring.
Still, I wanted to play a bit with using a pack of mongrels to run typo and to have Apache's httpd serve the static content directly. Application servers are great at generating content based on Ruby on Rails views or a Java Server Page. They don't do as well when it comes down to serving static files from the file system. Apache httpd allows you to configure aliases for different URIs. Thankfully, there were a few well defined URIs that are used to request static content. All I needed to do to offload the static file serving to httpd was to add the following line to my configuration file:
AliasMatch ^/(images|files|stylesheets|javascripts)/ "/home/fjean/sites/typo/public/$1/"
This will help keep the mongrels focus on generating the dynamic content rather than serving static files. Another advantage is that httpd handles the If-Modified headers correctly. As a result, the browsers can ask for a file only if it was modified after a certain time. If the server responds with a 304 response code, the browser knows to use the cached copy of the file. This does save on bandwidth.
I still had a single instance of mongrel running the blog at that point. A single mongrel should be sufficient with my current traffic. I still wanted more though. There was a slight problem though. Apache httpd 2.0.54 (which is installed by default on Ubuntu Dapper) doesn't have the proxy_balancer module. I did try to get it to compile and run on the server earlier without success. I did have another option. Pound is a software based load balancer that is able to balance traffic across multiple mongrel instances. I installed it by running "aptitude install pound". I then had pound installed.
The next step was to configure Typo to run on a pack of mongrels. I was in luck since I used the typo gem to install Typo. I used the following command to configure typo:
typo config ~/sites/typo bind-address=localhost port-number=4532 web-server=mongrel_cluster threads=3
(You should really stop Typo first btw...). I was then able to start the pack by issuing the "typo start ~/sites/typo" command. I did tell Typo to bind the mongrels to the localhost address. The reason is that I didn't want the mongrel processes exposed to the internet. There is really no point unless something is wrong and I need to troubleshoot the pack.
The next step was to configure Pound. The configuration file is found under /etc/pound/pound.cfg. I configured pound to bind to localhost:8888 and to forward content to the pack of mongrels. The important configuration bits are:
ListenHTTP 127.0.0.1,8888
##
UrlGroup ".*"
BackEnd 127.0.0.1,4532,1
BackEnd 127.0.0.1,4533,1
BackEnd 127.0.0.1,4534,1
EndGroup
Here again, there was no point in exposing Pound to the internet. Apache httpd will simply proxy traffic to Pound, which will then distribute it. I then had to enable pound by editing /etc/default/pound and set startup to 1. This was a signal to pound that it was configured. I started it by running /etc/init.d/pound start. The last configuration change was in the apache configuration file. I changed the proxying RewriteRule to send traffic to Pound rather than the first mongrel:
RewriteRule ^/(.*)$ http://localhost:8888/$1 [P,QSA,L]
I then restarted Apache and had a fully functional Typo installation that delegates serving static files to Apache httpd and is run by a pack of mongrels in a pound.
Now, if only I could do this with the servers at work...
Getting Apache, Mongrel and FeedBurner to Play Nice
I moved my blog from Textdrive to a Slicehost slice on Sunday. For the most part, the migration went well. Once I had Typo up and running on the slice, I just had to copy my theme, a few resource files and use a dump of the database to rebuild the content.
I had a little more trouble getting Apache to proxy requests to Mongrel and redirect all feed requests to FeedBurner (except for FeedBurner's of course...). I finally got mod_rewrite and mod_proxy to cooperate.
The first thing to remember is that the normal proxy approach will prevent the rewrite rules from working. Instead of using ProxyPass statements, I had to use RewriteRule. You'll need to enable the proxy, proxy_http and rewrite modules. Next, you'll need the following rules:
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule ^/xml/(atom|rss|rss20)/feed.xml$ http://feeds.feedburner.com/fredjean/outofmymind [R=301,L]
RewriteRule ^/(.*)$ http://localhost:3000/$1 [P]
The Proxy blocks enables the proxy module. The rewrite module will not be able to proxy the request to Mongrel if it is not set.
The RewriteCond line determines whether the user agent identifies itself as being something else than FeedBurner. If it is, the client is redirected to the FeedBurner URL. This allows FeedBurner to pass through and retrieve the feed. The redirect here is marked as being permanent (301 is the permanent redirect HTTP response code). We also tell RewriteRule to stop processing the rules at that point.
The last line proxies the request to Mongrel so it can be handled. Mongrel in turns runs the Typo blog engine. Once Typo is done, the response travels back through Mongrel, apache and makes its way back to the client.
Getting a Slice of the Internet... 1
I have been a Textdrive customer for a few months now. Textdrive's shared hosting plans are pretty good, they always provided me with good support and have a strong user community that helps and supports each others.
The only issue is that as a shared hosting service, there are some limitations to what I could do. Their main focus was on supporting LAMP and Ruby on Rails applications, so Java applications were pretty much out of the question. Same with Camping applications (unless the Camping gem was already installed on your server.) Sure, Textdrive would have installed the gem if I asked. My issue is that I had to ask ;) . Another issue is that you cannot have root access on the server (for very good reasons...).
My solution was to get a Virtual Private Server from SliceHost. In many way, I still share a server with an unknown number of users. We all share the same hardware and internet connection. Each slice has it's own kernel, memory space and slices of CPU time. These are guaranteed and managed so that no one can take over the actual server. I even get to have root access without impacting anyone else.
It took less than 5 minutes to have a slice built and configured after putting in my order. SliceHost has a web console where I can go and restart the server or even rebuild it if I mess up too badly :). The console even provides me with usage information so I can see how close I am to reaching my usage limits.
The only downside is that SliceHost doesn't provide DNS management services. TextDrive's service was fine, but it didn't allow me to add non-TextDrive systems to my domain. I finally found ZoneEdit. With ZoneEdit, you can manage up to 5 different DNS zones for free. You still need to register your domain with a separate registrar (I used Dynamic Network Services as my registrar).
The end result is that you can now visit my latest mapping mashup, which uses Camping for its web framework.
I'm back...
I kept having problems with the Apache + fast-cgi + RoR combination on Texdrive. Not their fault, but a limitation of the Apache fast-cgi bindings that I kept hitting. Thankfully, the very helpful Textdrive staff promptly provided a solution: they assigned a port to me so I could use lighttpd to host my Typo driven blog and other applications.
It took me a while and some challenges to get everything working again on the lighttpd + fast-cgi + RoR and lighttpd + fast-cgi + PHP in my environment. The bulk of it were learning pains. It looks like things are back to normal now, which is a good thing. If someone is curious, I'll go ahead and I'll post my final configuration files.
I still need to find a way to work around some of the Typo URL issues. I might have to write some url rewriting rules in order to make the transition transparent. Let me know if you are experiencing problems.
