Automating Server Builds

Updated by Linode

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.

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 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

The idea behind a golden disk 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, 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, they’ll all be running the same operating system and packages with the same system settings.

Cloning your Linode disk.

There are several places you can store a golden disk:

  • Existing Linode: This is the fastest and most cost-effective way to get started with automated server builds. The only downside is that you’ll need to resize the disk to store it, and you’ll need to shut down the Linode before duplicating and cloning the image.
  • Linode Backup Service: After enabling the Linode Backup Service, you can make a manual backup of your Linode (called a “snapshot”). This snapshot can function as your golden disk. Instead of cloning a disk to new Linodes, you can simply restore them from the snapshot backup.
  • Dedicated Linode: This is the preferred method. There’s no need to resize the disk, and you won’t have to worry about downtime. Updating the disk is easy - just boot the Linode, make the changes, and clone the disk again.
  • Different Computer: You can also transfer the disk to another computer. For instructions, see our guide on Copying a Disk Over SSH.

These methods are discussed in further detail below.

Existing Linode

You can create and store a golden disk using an existing Linode, but there are a couple of drawbacks. All of the disks 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, which will result in downtime.

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

  1. Use the Linode’s existing disk, or create a new disk.
  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. See our Resizing a Disk guide for instructions.
  7. If you’re planning on using the golden disk on the existing Linode, you should duplicate the disk. See our Duplicating a Disk guide for instructions.
  8. Clone the disk to another Linode. You can also optionally clone the configuration profile. The disk can be cloned to as many Linodes as you like.

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

Linode Backup Service

If you subscribe to the Linode Backup Service, you can create a golden disk by making a manual backup of an existing disk. Just take a snapsnot of the disk to back it up, and then restore it to your other Linodes. There’s no need to clone or resize the disk. 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 on an existing Linode and clone it to other Linodes:

  1. Use the Linode’s existing disk, or create a new disk.
  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. See the manual snapshot instructions for more information.
  6. Restore your other Linodes from the snapshot. The disk 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 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. This is an ideal solution, for several reasons. First, you can store and use the disk on a regular Linode - there’s no need to resize the disk. You can Linode shut down after you’ve created the disk, and then boot it to update the image.

Here’s how to create a golden disk 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 to another Linode. You can also optionally clone the configuration profile. The disk can be cloned to as many Linodes as you like.

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

Updating the Hostname and IP Address

After you restore or clone a disk 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 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 disks 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:

  • Puppet: An open source configuration management tool capable of managing Linux systems declaratively. It also automates IT tasks like application configuration, patch management, and even infrastructure audit and compliance. We have several Puppet guides in the Linode Library:

  • Chef: An open source configuration management tool that allows you to write configuration “recipes.” Chef can be used as a client-server tool, or it can be used in “solo” mode. See the Opscode website for more information. You can use the knife linode subcommand to manage Linodes with Chef.
  • Ansible: A “radically simple” open source platform for configuring and managing systems. It works by connecting to your systems via SSH — it doesn’t install anything on the remote systems. See the AnsibleWorks website for more information. You can find a Linode module for Ansible on GitHub.

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.

This guide is published under a CC BY-ND 3.0 license.