Automating Server Builds

Updated by Alex Fornuto

Contribute on GitHub

View Project | View File | Edit File

If you run a large website that requires multiple servers, or have a general interest in server automation, you may 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 with the intention of eliminating server discrepancies.

Server configuration can also be automated through Stackscripts. View the Stackscripts guide for more information.

Why You Should Automate Server Builds

When you set up a Linode for the first time, you manually install packages and applications. For example, in the Hosting a Website guide, the Apache, MySQL, and PHP packages are installed. Manually installing packages is a good way to learn about virtual servers, but it’s also a time-consuming process.

It is recommended that you take steps to automate the server-provisioning process, even if you don’t need multiple Linodes at this 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 want to spin up another Linode in the future, your automatic server building process will save you time.

Golden Disk

The idea behind a golden disk is simple: Create the perfect image and then save it for cloning to other servers. To get started, set up a new Linode, install the desired packages, configure the settings, and then test the configuration. Once satisfied with the server configuration, shut down the Linode, duplicate the disk, and then clone it to all of your other Linodes, either manually or though the Linode API.

Be aware that certain files like /etc/hosts, /etc/hostname, and static networking configurations may need to be modified for individual Linodes.

Cloning your Linode disk.

There are several places to store a golden disk:

  • Linode Images: Linode Images allows you to take snapshots of your disks, and then deploy them to any Linode under your account.
  • 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: Boot the Linode, make the desired changes, and clone the disk again.
  • Existing Linode: You can clone from an existing Linode, but you will need to power down the Linode to ensure a consistent copy.
  • Different Computer: You can 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, with the exception of Linode Images which has its own article.

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. 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. The snapshot will be stored until you overwrite it with another backup.

  1. Use the Linode’s existing disk, or create a new disk.
  2. Install all necessary packages and configure the system settings.
  3. Verify that all installed packages are current. See Monitoring and Maintaining Your Server 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.

Dedicated Linode

A dedicated Linode can be used to store and maintain a golden disk. It can be shut down after you’ve created the disk, and then boot it to update the image.

  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 clone the configuration profile. The disk can be cloned to as many Linodes as you like.

Existing Linode

You can create and store a golden disk using an existing Linode, with some drawbacks: All of the disks stored on the Linode will need to be resized to fit within your target Linode’s allocated storage space, and you will have to shut down the Linode to ensure an accurate clone, which will result in downtime.

  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 clone the configuration profile. The disk can be cloned to as many Linodes as you like.

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.

Third-Party Tools

Golden disks 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 such as:

  • Puppet: An open source configuration management tool that manages systems declaratively. It can automates IT tasks like application configuration, patch management, and even infrastructure audit and compliance. See the following Puppet guides:

  • Chef: An open source configuration management tool that allows you to “turn your infrastructure into code.” See the Chef website for more information. The knife linode subcommand can also be used 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 to be used should the above options not suit your needs.

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