Linode Library Home
Linode Library RSS Feed
Home
Print View View Source

Automating Server Builds

Published: by

If you run a large website that requires multiple servers, or if you just love automating things, you'll want to automate your server builds. You can rapidly spin up multiple servers with exactly the same configuration by creating a golden image that can be cloned to multiple Linodes, or by making a StackScript that installs the same software and settings on each Linode. The goal is eliminating discrepancies among servers, and making the server-provisioning process fast and painless. This guide shows you how to do it.

Contents

Why You Should Automate Server Builds

When you set up your Linode for the first time, you manually installed the packages and applications you needed. For example, in the Hosting a Website guide, we walked you through the process of installing the Apache, MySQL, and PHP packages on your Linode to help you host a website. Manually installing packages is a good way to learn about virtual servers, but it's also a time-consuming and painstaking process. It's not something you'll want to do again when you set up servers in the future.

That's why we recommend that you take steps to automate the server-provisioning process now, even if you don't need multiple Linodes at this very moment. By duplicating the disk image or writing an install StackScript, you'll preserve the current state of your server - including all of the packages you've installed and settings you've configured. If you ever want to spin up another Linode in the future, your automatic server building process will save you a lot of time. Plus, this is a requirement for load balancing and high-availability, both of which require Linodes with exactly the same configuration.

Golden Disk Image

The idea behind a golden disk image is simple. You'll create the perfect image and then save it for cloning to other servers. To get started, you'll set up a new Linode, install the packages you need, configure the settings the way you want them, and then test the configuration. Once you're satisfied that the server is the way you want it, simply shut down your Linode, duplicate the disk image, and then clone it to all of your other Linodes. (You can also clone using our API.) Once you start your Linodes using the cloned disk image, they'll all be running the same operating system and packages with the same system settings.

Cloning your Linode disk image.

There are several places you can store a golden disk image:

These methods are discussed in further detail below.

Existing Linode

You can create and store a golden disk image using an existing Linode, but there are a couple of drawbacks. All of the disk images stored on the Linode will need to be resized to fit within your Linode's allocated storage space. In addition, you will have to shut down the Linode to duplicate and clone the disk image, which will result in downtime.

Here's how to create a golden disk image on an existing Linode and clone it to other Linodes:

  1. Use the Linode's existing disk image, or create a new disk image.
  2. Install all necessary packages and configure the system settings, if you haven't already done so.
  3. Verify that all installed packages are current. See our Monitoring and Maintaining Your Server guide for instructions.
  4. Test your server configuration. At a minimum, this probably includes downloading your version-controlled repository and verifying that your website or application functions properly.
  5. Shut down the Linode.
  6. Resize the disk image. See our Resizing a Disk Image guide for instructions.
  7. If you're planning on using the golden disk image on the existing Linode, you should duplicate the disk image. See our Duplicating a Disk Image guide for instructions.
  8. Clone the disk image to another Linode. You can also optionally clone the configuration profile. The disk image can be cloned to as many Linodes as you like.

You have successfully created and stored a golden disk image on an existing Linode.

Linode Backup Service

If you subscribe to the Linode Backup Service, you can create a golden disk image by making a manual backup of an existing disk image. Just take a snapsnot of the disk image to back it up, and then restore it to your other Linodes. There's no need to clone or resize the disk image. And since the snapshot will be stored until you overwrite it with another backup, this is an ideal storage solution.

Here's how to create a golden disk image on an existing Linode and clone it to other Linodes:

  1. Use the Linode's existing disk image, or create a new disk image.
  2. Install all necessary packages and configure the system settings, if you haven't already done so.
  3. Verify that all installed packages are current. See our Monitoring and Maintaining Your Server guide for instructions.
  4. Test your server configuration. At a minimum, this probably includes downloading your version-controlled repository and verifying that your website or application functions properly.
  5. Take a snapshot of the disk image. See the manual snapshot instructions for more information.
  6. Restore your other Linodes from the snapshot. The disk image can be restored to as many Linodes as you like. See the backup restore instructions for more information.

You have successfully created, stored, and deployed a golden disk image using the Linode backup system.

Dedicated Linode

Users who manage dozens of Linodes will want to use a dedicated Linode to create, store, and maintain a golden disk image. This is an ideal solution, for several reasons. First, you can store and use the disk image on a regular Linode - there's no need to resize the disk image. You can Linode shut down after you've created the disk image, and then boot it to update the image.

Here's how to create a golden disk image on an existing Linode and clone it to other Linodes:

  1. Use an existing Linode, or set up a new one.
  2. Install all necessary packages and configure the system settings, if you haven't already done so.
  3. Verify that all installed packages are current. See our Monitoring and Maintaining Your Server guide for instructions.
  4. Test your server configuration. At a minimum, this probably includes downloading your version-controlled repository and verifying that your website or application functions properly.
  5. Shut down your Linode.
  6. Clone the disk image to another Linode. You can also optionally clone the configuration profile. The disk image can be cloned to as many Linodes as you like.

You have successfully created, stored, and deployed a golden disk image using a dedicated Linode.

Updating the Hostname and IP Address

After you restore or clone a disk image to another Linode, you may need to change its hostname and IP address. For instructions on changing the hostname, see Setting the Hostname. If the golden disk image was configured to use a static IP address, you'll also need to replace the IP address. See Static IP Configuration for more information.

StackScripts

StackScripts are custom scripts that run when a Linode boots for the first time. You can use public StackScripts that were contributed by members of the community, or you can create your own StackScript that is private to your account. StackScripts can update the system, set the host name, add SSH keys, install packages, and even configure settings. For more information about StackScripts, and to learn how you can use them to automate server builds, see this article.

Third-Party Tools

Golden disk images and StackScripts are capable of handling automated server builds for most individuals and small businesses. But if you work for a large business that manages dozens of Linodes, you may need to turn to a third-party configuration management tool. Here are two of the most popular third-party configuration management tools:

There are plenty of other third-party configuration management tools. Feel free to investigate other options if Puppet, Chef, or Ansible don't meet your needs for automating server builds and configuration management.

Creative Commons License

This guide is licensed under a Creative Commons Attribution-NoDerivs 3.0 United States License.

Last edited by Matthew Cone on Tuesday, July 9th, 2013 (r3514).