Skip to Content
Installation

Install Consul

A record of which services run and where they are located, with an honest assessment of when a business actually needs it.

Last reviewed:

What Consul is

A register of which services are running and where they are. Instead of entering an IP address in the code, the program asks Consul where, for example, the database is right now, and gets the answer.

Why would it move? Because services restart, change machines and get new addresses. With a couple of services on one computer you never notice, and then you do not need Consul. With ten services on three machines it is the only reasonable solution.

Consul also keeps track of whether the services are alive. It checks in at regular intervals, and if a service does not respond it is removed from the register. The next program that asks then gets an address that actually works instead of one that stopped responding ten minutes ago.

Be honest with yourselves about whether you need this. Consul is a tool for systems that have outgrown a single machine. If you are going to learn how larger systems fit together, it is an excellent exercise. If you are going to get a web shop up and running, there are simpler paths.

Windows

Download the zip file for Windows from hashicorp.com and unpack it. Inside there is a single file, consul.exe. There is no installer, and none is needed.

Put the file in its own folder, for example C:\consul, and add that folder to the system path under Environment Variables in the Windows settings. Then you can start the program from any folder. If you skip that step everything still works, but only when you are in that particular folder.

Check with:

consul version

Linux Mint

Consul is in the publisher's own package repository. Open Terminal and run the lines in order:

wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(grep -oP '(?<=UBUNTU_CODENAME=).*' /etc/os-release || lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt-get update && sudo apt-get install consul

The line gets the version name from UBUNTU_CODENAME in /etc/os-release instead of from lsb_release -cs. That is deliberate: Linux Mint has its own version names, for example wilma, and that name does not exist in HashiCorp's repository. UBUNTU_CODENAME instead gives the name of the Ubuntu version Mint is based on, and that is the line it finds automatically.

Three things to do first

  1. Start a practice server. First create a folder that the agent reads configuration from, and point to it when you start, otherwise you have nowhere to put the service in step three:
    mkdir consul.d
    consul agent -dev -config-dir=consul.d
    The agent saves nothing and disappears when you close the window, which is exactly what you want while you are learning. Leave the window open and open a new one for the next step.
  2. Go to http://localhost:8500. The web interface is there, and you see Consul itself as a registered service. That is the whole idea in a single window.
  3. Register something of your own. Put a file named webb.json in consul.d, with a service that has a name and a port:
    {
      "service": {
        "name": "webb",
        "port": 8000
      }
    }
    Then run consul reload in the second window. The service shows up in the list, and by then you have understood what the tool does. If nothing happens, it is almost always because the agent was started without -config-dir: then there is no folder to reread, and consul reload does exactly what it promises, which is to reread nothing.

The most common trap

Leaving a dev server open to the network. The -dev flag turns off just about all security, so you do not have to configure it away while you practice. No login, no encryption, full permissions for anyone who finds the port. On your own computer it is no problem. On a machine with a public IP address, you hand over control of the entire registry to anyone who scans the port.

Use -dev to learn, and nothing else. If Consul is going to run for real, that is a different configuration with permissions and certificates, and you can read about that at the publisher.

Also worth knowing: Consul has been under the BSL license for a few years now. Using it in your own systems, including a company's, is free. The terms only kick in if you build a competing product out of the tool itself.

Cart

Loading