Install Consul Ubuntu 22.04

1. Install Required Dependencies

Start by installing necessary tools like unzip, curl, and gnupg:

sudo apt update
sudo apt install unzip curl gnupg -y

2. Add HashiCorp’s GPG Key and Repository

Add the HashiCorp GPG key and the official Consul repository:

curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

3. Install Consul

After updating the package index, install Consul with:

sudo apt update
sudo apt install consul -y

Verify the installation with:

consul version

4. Configure Consul

Create a configuration directory and a configuration file for the Consul server:

sudo mkdir -p /etc/consul.d
sudo nano /etc/consul.d/server.hcl

In server.hcl, add configurations similar to:

datacenter = "dc1"
data_dir = "/opt/consul"
server = true
bootstrap_expect = 1
ui_config {
  enabled = true
}
bind_addr = "0.0.0.0"
client_addr = "0.0.0.0"
advertise_addr = "{{ GetInterfaceIP \"eth0\" }}"

5. Set Up Consul as a Systemd Service

Create a systemd service file:

sudo nano /etc/systemd/system/consul.service

Add the following content:

[Unit]
Description=Consul Service
After=network-online.target
Wants=network-online.target

[Service]
User=consul
ExecStart=/usr/bin/consul agent -config-dir=/etc/consul.d
Restart=on-failure

[Install]
WantedBy=multi-user.target

Enable and start the Consul service:

sudo systemctl daemon-reload
sudo systemctl enable consul
sudo systemctl start consul

6. Open Required Ports

If using a firewall, open Consul’s ports:

sudo ufw allow 8300/tcp 8301/tcp 8301/udp 8302/tcp 8302/udp 8500/tcp 8600/tcp 8600/udp

7. Access the Web UI

Access the Consul web interface by navigating to http://<your-server-ip>:8500.


RyanX October 29, 2024
Share this post
Tags
Archive