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 https://dl.bintray.com/mitchellh/consul/0.5.2_linux_amd64.zip unzip 0.5.2_linux_amd64.zip rm 0.5.2_linux_amd64.zip 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/abhishek.sh

Create an encryption key to share amongst the consul agents

consul keygen

Set up server config

Create a config file on Consul Masters

/var/lib/consul/conf/server/config.json
{ "bootstrap_expect": 3,
"server": true,
"client_addr": "0.0.0.0",
"datacenter": "abhishek",
"data_dir": "/var/lib/consul/data",
"encrypt": "<you generate>",
"log_level": "INFO",
"enable_syslog": true,
"recursors": [
"<AWS defaul DNS (probably 10.0.0.2)>",
"<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 consul-000-abhishekamralkar.in consul-001-abhishekamralkar.in consul-002-abhishekamralkar.in

Now we need to setup Consul client

  • Create a config file on Consul Nodes
/var/lib/consul/conf/client/config.json

{ "server": false,
"datacenter": "dcos-west-2",
"client_addr": "0.0.0.0",
"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": [ "10.0.0.2" ],
"start_join": ["consul-000-abhishekamralkar.in, consul-001-abhishekamralkar.in, consul-002-abhishekamralkar.in"] }
  • Download and install Consul UI
mkdir -p /var/lib/consul/web/ 
cd /var/lib/consul/web/
wget https://dl.bintray.com/mitchellh/consul/0.5.2_web_ui.zip
unzip 0.5.2_web_ui.zip
rm -rf 0.5.2_web_ui.zip

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

https://github.com/johnbellone/consul-cookbook

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