Consul Installation Cluster Mode

We will be installing Consul in Cluster Mode where we will be having 3 consul servers and multiple Consul client.

We will be installing Consul in Cluster mode on CoreOS, but the below steps should work with any OS with Systemd .

###How to install Consul?

First create consul directories skeleton

mkdir -p /var/lib/consul/data 
mkdir -p /var/lib/consul/bin
mkdir -p /var/log/conf/server
mkdir -p /var/lib/consul/conf/server/

On the Mesos Slaves (which will run client agents)

mkdir -p /var/log/conf/client mkdir -p /var/lib/consul/conf/client/

Download and install Consul Executable

cd /var/lib/consul/bin wget unzip rm chmod a+x consul

Set up bash to have consul in your path.Only works for non-sudo

echo 'export PATH=$PATH:/var/lib/consul/bin' >> /etc/profile.d/

Create an encryption key to share amongst the consul agents

consul keygen

Set up server config

Create a config file on Consul Masters

{ "bootstrap_expect": 3,
"server": true,
"client_addr": "",
"datacenter": "abhishek",
"data_dir": "/var/lib/consul/data",
"encrypt": "<you generate>",
"log_level": "INFO",
"enable_syslog": true,
"recursors": [
"<AWS defaul DNS (probably>",
"<consul master 0 ip address>",
"<consul master 1 ip address>",
"<consul master 1 ip address>"
] }

On any of the Consul Master (consul server agent) servers issue the following command.Change the FQDN’s to be appropriate for your cluster

/var/lib/consul/bin/consul join

Now we need to setup Consul client

  • Create a config file on Consul Nodes

{ "server": false,
"datacenter": "dcos-west-2",
"client_addr": "",
"data_dir": "/var/lib/consul/data",
"ui_dir": "/var/lib/consul/web/dist",
"encrypt": "<Key I send you>",
"log_level": "INFO",
"enable_syslog": true,
"ports": { "dns": 53 },
"recursors": [ "" ],
"start_join": [",,"] }
  • Download and install Consul UI
mkdir -p /var/lib/consul/web/ 
cd /var/lib/consul/web/
rm -rf

Consul ui will be accessible on port 8500

If you are Chef user and want to deploy the Consul via Chef , you can check out below cookbook

DevSecOps Practitioner | DevOps Enthusiast | Clojure | Cloud Automation | Cloud Security Enthusiast