When the boss wants a prototype as soon as possible or a client needs something tomorrow, the cloud is the best place to turn. You can have a fully configured machine serving data in minutes.
One of the most developer-friendly options is DigitalOcean, a cloud that offers fast machines at reasonable prices, delivering them in seconds. It doesn’t offer the fancier features that the major cloud providers do—at this writing—but it does package raw machines in a way that’s a breeze to deploy. If you’re a developer with an idea that needs a home, DigitalOcean’s machines are blank slates ready to go.
What’s on offer
Once paid for, DigitalOcean instances, called droplets, generally start in less than a minute. When combined with their reasonable pricing, this speed makes DigitialOcean droplets ideal for the buildup and tear-down common when testing and debugging new sites. With droplets, experimentation is easy.
There are several methods to begin with droplets, depending on your needs. Some developers will want a raw machine with a standard version of the operating system. That can be accomplished in a few steps. The rest of the build-out is up to you.
But if you need a common configuration, DigitalOcean offers a number of standard images that are ready to run. They can be deployed in about as many steps as the regular machines.
First, let’s build a basic machine, then we’ll turn our attention to what it takes to deploy a preconfigured image on DigitalOcean.
Build a basic machine on a DigitalOcean droplet
DigitalOcean’s droplets are akin to what other companies call “instances” or “virtual servers.” A droplet feels like a standalone box on your desk because you get the root password and access to all the file system, enabling you to configure it anyway you like. This is a bit of a facade because droplets are really virtual machines, each a share of a much larger machine that appears to be an independent server under your control. With this setup, it's relatively easy to resize your droplet to add more memory or disk space if your application demands it.
When you launch a droplet, you must make four major decisions and a few minor ones. Each takes only a few clicks on the web interface. (DigitalOcean also offers an API for automation.) They are:
- Operating system: DigitalOcean offers six of the major open source Unix operating systems. Most are built on Linux, but there’s also FreeBSD. All the recent major versions are also available. Windows, MacOS, or Solaris are not currently available. Many people use Ubuntu, the default choice.
- Size: Droplets come in 14 sizes priced for the most part by RAM. A standard machine comes with 2GB of RAM and costs 3 cents per hour or $20 per month. If you want twice as much RAM, you’ll pay twice as much. The size also determines the number of virtual CPUs, the amount of local disk space, and the amount of data you can transfer over the network, but these only roughly scale with price. When you switch from a droplet that costs 3 cents per hour to 6 cents per hour, you go from only 40GB of disk space to 60GB. You get more as you pay more, but what you get is not always proportional to the price. DigitalOcean also offers a very small machine with only 512MB of RAM. This is often sufficient for small jobs and is an ideal size for quick experiments. At the current price, $5 per month, it’s extremely attractive for trying out new ideas. It’s easy to set up and destroy a number of these machines without breaking your budget. You don’t have to agonize too much over your capacity decision because droplets can be resized later if you need more. (The other parameters listed here, like OS or location, can’t be easily changed.)
- Location: DigitalOcean maintains 12 datacenters around the world, and you should probably choose the one closest to your initial user base. You can always set up a worldwide network when demand grows. Worth noting is that only three of DigitalOcean’s datacenters currently support adding disk storage as a separate block: New York (NYC1), Frankfort (FRA1), and San Francisco (SFO2). These three alone offer the option to create a separate block of disk storage and mount it with your droplets. If you expect to make use of this, you must choose one of these three datacenters.
- Block storage: DigitalOcean recently started offering the option to create a separate block of disk storage that lives independently from your droplets. This is useful if you’re going to create persistent files or databases that will live on when the droplets are turned off. If you’re scaling up and down frequently by turning droplets on and off, it makes sense to store the persistent data in one of these blocks. They’re currently available only in three datacenters (NYC1, FRA1, and SFO2).
Beyond these choices, there are a few options worth noting. If you need to back up your machine, the simplest solution is to check the “backup” option, and DigitalOcean will create and retain four weekly backups of your machine for an extra charge of 20 percent. If you need more frequent backups, you’ll need to add this feature yourself.
If you are going to run several machines in the same datacenter and want to set up a private link between them, you can add a private network. If you need more protection between datacenters, you’ll need to add a layer of encryption to your stack instead. Indeed, you may want to make sure your communication between machines is encrypted even within the same datacenter. DigitalOcean is starting to roll out bare-bones telemetry that tracks basic statistics about your machine, like load and RAM consumption. This works only with a few of the major OSes like Ubuntu, and it can be enabled with a click.
There are also options for preloading data alongside the standard version of the OS. The most important is the SSH key that authenticates you when you log in. If you need more general data uploaded, DigitalOcean offers to upload a block of text that can contain arbitrary information.
After you’ve made these decisions, you can repeat the process by adding other droplets with the same configuration.
The last step is giving your droplet a name, so you can remember why you created it and what it is supposed to do.
After you push the button to deploy, you’ll get an email with all the particulars a minute or so later. Here’s what it will look like:
Droplet Name: frog
IP Address: 22.214.171.124
Once you receive it, log in and treat it like a new machine you’ve installed anywhere. That means changing your password and setting up work accounts so that you don’t need to log in as root. You’ll also want to run the following:
sudo apt-get update (to update the local package listings)
sudo apt-get upgrade
sudo apt-get dist-upgrade
Deploy a standard package from DigitalOcean
DigitalOcean offers a number of standard packages with popular open source software preconfigured, so it’s a snap to get up and running quickly. Many of the most common uses for servers come as prebuilt images, including options such as Drupal, WordPress, MongoDB, or Git.
Prebuilt images are a mixed blessing because not all of the software is as up-to-date as possible. It can be a challenge to keep up with the quick revision cycles of many open source projects, and DigitalOcean does not always update them immediately. For instance, when writing this piece, I built a droplet with an image consisting of Ubuntu 14.04 and Drupal 8.1.3, though Ubuntu 16.04 and Drupal 8.2.5 were freely available. This means you’ll have to do a bit more work once the droplet is built to update your OS and software to the latest versions.
The good news is that many of DigitalOcean’s scripts are comprehensive. They often complete many of the little details for creating accounts and building connections with the database. In the case of Drupal, the script builds an admin account, assigns a random password, and stores this password in the message of the day that you’ll see when logging into the droplet via SSH.
It looks like this:
Thank you for using DigitalOcean’s Drupal application. We have created a base install that can be seen at http://126.96.36.199/, you should go there now and finish the installation process via the credentials below.
Nginx listens on public IP (188.8.131.52) port 80 and forwards requests to php-fpm listening on a socket. Nginx access log is in /var/log/nginx/access.log and error log is in /var/log/nginx/error.log To restart Drupal, run : sudo restart php5-fpm
DigitalOcean also provides useful information in a tutorial page for each option.
This can be enough information to hang yourself, however. When I built out Drupal 8.1.3, I quickly discovered there was a security problem with the build and it was important to upgrade to 8.2.5 as soon as possible. You should recognize that the scripts may save you plenty of time and effort, but they won’t remove the need to learn more about the underlying software. You’ll need to learn how to maintain it and watch for potential problems.
Building a complete “one-click app” with prebuilt DigitalOcean images is very similar to building a basic version of the operating system. You make the same decisions about size, location, and other details. DigitalOcean simply loads a slightly different image with the software running.
Build a cluster on DigitalOcean
If your application is successful, you may find yourself with a droplet that can’t keep up with all the traffic. Increasing the size of the droplet can help, but the approach is limited when you need more CPU power.
Using several droplets that act like a cluster is the traditional solution. Several droplets can work together to respond to requests. Many call this process “load balancing”; DigitalOcean uses the term “floating IP address.” When you enable it, all of the traffic that comes into the particular IP address will be spread around the droplets in your cluster.
The first step to creating a cluster requires you have a droplet in place. Go to the main page for the droplet where networking information runs along the top. When you click on “Enable floating IP address,” it will take you to a page for configuring them. From here, you can connect the floating IP addresses to the droplets.
This page will also list all floating IP addresses in case you want to reassign or delete them. It’s a good idea to delete them when you’re finished—unused but assigned IP addresses are charged a small amount per hour because they’re valuable commodities.
Rebuild a DigitalOcean droplet after powering off
The power to your droplets can be turned off, an act that is a bit of a fiction for virtual machines running on a cluster. The host hardware stays on, but the virtual machine is shut off and must be rebooted when it is turned back on.
The best way to shut down a computer is through the operating system. Either of these commands will work from the command line:
sudo shutdown -h now
If your droplet becomes wedged or unresponsive, you can also shut it down from the DigitalOcean website, but this action could lead to corrupted data and inconsistent file systems. The Power tab for each droplet includes two options for either rebooting a droplet or shutting it off completely.
When you’ve shut down your droplet, you can resize, reconfigure, or fix it. The droplet can be turned back on by going to the Power tab of the droplet, then pushing the “Power on” button.
Resize a DigitalOcean droplet
When the power is off, the Resize tab of the droplet’s main page offers two options for resizing the droplet. The first merely changes the amount of CPU and RAM devoted to a droplet. It’s a good option when you need more power temporarily because it can be reversed, allowing you to switch back after you’re done.
The second option changes the RAM, CPU, and disk space, a step that can take longer because the disk space must be expanded. This option is not reversible because there’s no simple way to shrink the disk space. If you need to shrink the size of your droplet, you’ll need to create a new smaller version and copy data yourself using a snapshot or
Rebuild the file system of a DigitalOcean droplet
You can restart many distributions with a recovery kernel after the machine is powered off. This option can be found under the Kernel tab of the droplet’s main page. When you click the button, you can swap out the kernel and restart it. Not every droplet has this option enabled. (It is generally a good idea to keep good backups so that you don’t need to rely on
fsck to solve your problems.)
DigitalOcean offers a thorough tutorial on various ways to mount drives and execute standard
fsck routines. They also offer the option for rebooting with a recovery ISO that can solve other problems and save data.
Make network changes to a DigitalOcean droplet
You can also adjust the network configuration of your droplet when it is powered down. The Networking tab of the droplet’s main page offers the option to either enable private networking or turn on the public IPv6 access. Both can be configured with a click.
Reset root on a DigitalOcean droplet
If you’ve forgotten the root password or you worry about some kind of compromise, you can reset your root password when the droplet is off. Use the Access tab of the main droplet page.
- Public cloud megaguide: Amazon, Microsoft, Google, IBM, and Joyent compared
- Get started with TensorFlow
- Get started with Azure Machine Learning
- Review: The best frameworks for machine learning and deep learning
- What deep learning really means
- 10 new AWS cloud services you never expected
- 10 AWS security blunders and how to avoid them
- The dirty dozen: 12 cloud security threats
- 13 ways the cloud has changed (since last you looked)