How To Setup Consul Cluster (Multi-Node) on Linux – Beginners Guide

Consul is an open source key-value store. It is used for use cases such as service discovery, config management etc. This guide has detailed instructions to setup consul cluster with multiple nodes.

Prerequisites

  1. Three Linux servers
  2. Following ports opened between all three servers. If you on AWS, Azure or GCP make sure you have the security groups and firewall tags added properly to allow communications of the below-mentioned ports.
    • 8300  – TCP
    • 8301  – TCP & UDP
    • 8302  – TCP & UDP
    • 8400  – TCP
    • 8500  – TCP
    • 8600  – TCP & UDP

Setup Consul Cluster

This tutorial is based on a three-node consul cluster. The nodes are named as follows.

  1. consul-1
  2. consul-2
  3. consul-3

Follow the steps given below for a fully functional consul cluster.

READ  How To Get Six Months Pluralsight Free Subscription

Install and Configure Consul on All the Three Nodes

The following steps have to be performed on all the three nodes except step 4.

Step 1: CD into bin directory and download Linux consul binary from here

Step 2: Unzip the downloaded file and remove the zip file.

Step 3: Create the following two directories.

Step 4: Create a consul secret using the following command from one of the three servers. Copy the secret to a text file.

Step 5: Create a config file on all the three servers.

Copy the following config to the file. Replace encrypt value with the secret created in step 4 and start_join IP’s with your server IP’s.

Create a Consul Service

Execute the following steps on all the three nodes.

Step 1: Create a systemd file.

Copy the following contents to the file.

Step 2: Reload the system daemons

Bootstrap and Start the Cluster

Step 1: On consul-1 server, start the consul service

Step 2: Start consul on other two servers (Consul-2 and consul-3) using the following command.

Step 3: Check the cluster status by executing the following command.

You should get an output like the following. It means your consul cluster is up and running.

Access Consul UI

From consul version 1.20, UI is an inbuilt consul component.

You can access the consul web UI using the following URL syntax.

For example,

You can view an UI as shown below.

consul web ui setup

Also, you can view a complete UI demo from here

Free DevOps Resources

Get DevOps news, tutorials and resources in your inbox. A perfect way If you want to get started with devops. Like you, we dont like spam.