Install Consul Agent

Published: by Creative Commons Licence

Prepartion

vm1 192.168.33.13 vm1.roomit.tech as consul server

vm2 192.168.33.14 vm2.roomit.tech as consul client

You have already install Consul Server in vm1. this is link : How To Install Consul Server

Runnig up both VM

vagrant up vm1 vm2

running consul server in vm1

vagrant ssh vm1
systemctl start consul

Login vm2 and add user consul

vagrant ssh vm2
useradd consul
passwd consul

Installation

Install Tools

apt install unzip -y wget

Download Package

wget -c  https://releases.hashicorp.com/consul/1.7.1/consul_1.7.1_linux_amd64.zip

Hiearachy

/opt/consule-client/
├── bin
├── cfg
└── data
mkdir -p /opt/consule-client/{bin,cfg,data}
chown consul:consul -R /opt/consule-client

Install and Save Path Environment

unzip consul_1.7.1_linux_amd64.zip -d /opt/consule-client/bin/
chmod +x /opt/consule-client/bin/consul
echo "export PATH=$PATH:/opt/consule-client/bin" >> ~/.bashrc 
source ~/.bashrc

Generate Keys

consul keygen
j4j7yRLgC0JfKu0tT05xlINH56k3R6c0S1L2K1cCuYw=

Configure Consul Client in /opt/consule-client/cfg/config.json

{
    "server": false,
    "datacenter": "Tendean",
    "data_dir": "/opt/consule-client/data/",
    "encrypt": "InWruaxMIrBj64pd4d+FmhH57A3jw3RzCaIdLVxt+vA=",
    "log_level": "INFO",
    "enable_syslog": true,
    "leave_on_terminate": true,
    "addresses" : {
         "http": "127.0.0.1"
    },
    "bind_addr": "192.168.33.11",
    "start_join": [
        "192.168.33.10"
    ]
}

Create Systemd init in /etc/systemd/system/consul-client.service

[Unit]
Description=Consul Startup process
After=network.target
 
[Service]
Type=simple
Type=simple
User=consul
Group=consul
ExecStart=/bin/bash -c '/opt/consule-client/bin/consul agent -config-dir /opt/consule-client/cfg/'
TimeoutStartSec=0
 
[Install]
WantedBy=default.target

Reload Daemon

systemctl daemon-reload

Start Service

systemctl start consul-client

Check Service

systemctl start consul-client

If Success Go to vm1 and check members

root@vm1:/opt/consule-server/data/serf# consul members
Node  Address             Status  Type    Build  Protocol  DC       Segment
vm1   192.168.33.10:8301  alive   server  1.7.1  2         tendean  <all>
vm2   192.168.33.11:8301  alive   client  1.7.1  2         tendean  <default>