Benjamin Curtis

Speculations on Web Development

Easy Server Migrations

| Comments

What if you could complete a server migration with just a few minutes of down-time? What if you didn’t have to wait for DNS changes to propagate to have all of your users use your new server? It’s not only possible, it’s easy! As long as you use mongrel, that is.

A few months ago I had to do a couple of server migrations, moving a set of web sites from one host to another. In the past, that’s often been a painful experience of dealing with users hitting two different servers as the DNS changes propagated. The brute force approach to the problem was to turn the DNS TTL way down and set up a proxy or rewrite rule on the old web server to send traffic to the new one.

These days, though, I’m always proxying traffic from the web server to mongrel, so changing the proxy destination turns out to be an excellent way to make a server move. Here’s what I do to make the move:

  1. Configure the new server to mirror the old one, making sure that the mongrels are listening to the public IP so that they can take the proxy traffic from the old server.
  2. Start the application on the new server with a recent copy of the database.
  3. Set up a maintenance page on the application on the old server to keep users from updating the database.
  4. Copy the database from the old server to the new server. Alternatively, you could have set up replication from the old server to the new server, making this step unnecessary since the new database server would be up-to-date via replication.
  5. Switch the proxy destination in the old web server configuration from localhost to the new server.

You could feasibly script the cutover, especially if you had set up database replication, which would mean the only real work you do at the time of the switch is putting up the maintenance page (which would only be there for a few seconds) and changing the proxy configuration. And what about DNS? Just set it, and forget it!

This is yet another reason why mongrel is better than FastCGI.

Comments