How to Install Consul Server on Ubuntu Linux
You install a Consul server on Ubuntu Linux to deploy HashiCorp’s service networking solution for managing distributed applications.
Consul automates network configuration, enables service discovery, and secures service-to-service communication, making it crucial for microservices and complex system architectures.
This tutorial walks you through setting up a single Consul server on Ubuntu 22.04 LTS, covering the essential steps to get it running.
Update system packages, then download and install the Consul binary to /usr/local/bin. Create a dedicated Consul user and configure directories. Finally, set up a systemd service file to run and manage the Consul agent.
Prerequisites
- A machine running Ubuntu Linux (18.04 or later)
- Sudo privileges
- Stable internet connection for software download
Update System Packages
Open up your terminal and begin by updating your package lists:
sudo apt-get update
Then, upgrade your system packages to the latest versions:
sudo apt-get upgrade
Download Consul
To install Consul server on Ubuntu, you first need to download the Consul software. You can get the latest version directly from HashiCorp’s official website using a simple command.
First, install wget if you do not have it already:
sudo apt-get install wget unzip
Next, download the Consul zip archive. You can find the latest version from the link below:
CONSUL_VERSION="1.17.2"
wget https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip"1.17.2" with the latest Consul version if there is a newer one available.Install Consul
After downloading Consul, the next step is to install it so your system can use it. This involves unzipping the downloaded file and placing the Consul program where your system can find it, making it ready to run.
unzip consul_${CONSUL_VERSION}_linux_amd64.zipMove the Consul binary to your system’s PATH so that it can be executed from anywhere:
sudo mv consul /usr/local/bin/
Verify the installation:
consul --version
The command should output similar lines shown below;
Consul v1.17.2 Revision 7736539d Build Date 2024-01-22T16:55:18Z Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)
Create a Consul User
For security reasons, it’s best not to run Consul as root. Create a new user for Consul:
sudo useradd --system --home /etc/consul.d --shell /bin/false consul
Configure Consul
Now that Consul is installed, you need to set up its configuration. This involves creating specific folders where Consul will store its settings and then making sure the Consul program has permission to use them.
sudo mkdir --parents /opt/consul sudo mkdir --parents /etc/consul.d
Grant the Consul user ownership of those directories:
sudo chown --recursive consul:consul /opt/consul sudo chown --recursive consul:consul /etc/consul.d
Create a basic configuration file by running the command below.
sudo nano /etc/consul.d/consul.hcl
Then, please copy and paste the content below into the file and save it. Remember to replace the bind_addr and advertise_addr addresses with your server’s own.
{
"datacenter": "dc1",
"data_dir": "/opt/consul",
"log_level": "INFO",
"server": true,
"ui": true,
"bind_addr": "192.168.128.2",
"client_addr": "0.0.0.0",
"advertise_addr": "192.168.128.2",
"bootstrap_expect": 1
}Create a Systemd Service File
To make sure Consul runs smoothly in the background and starts automatically, you’ll create a systemd service file. This file tells your Ubuntu system how to manage the Consul process, like starting and stopping it.
sudo nano /etc/systemd/system/consul.service
Then, please copy and paste the content below into the file and save it.
[Unit] Description=Consul Service After=network.target [Service] User=consul Group=consul ExecStart=/usr/local/bin/consul agent -config-dir=/etc/consul.d/ ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target
Next, reload the systemd daemon and enable the Consul service to run on system boot:
sudo systemctl daemon-reload sudo systemctl enable consul
Start and Verify the Consul Service
With the service file ready, you can now start the Consul server and check if it’s running correctly. This step confirms that Consul is active and ready to go on your Ubuntu machine.
sudo systemctl start consul
Check the status of the service:
sudo systemctl status consul
You should see similar lines as shown below.
consul.service - Consul Service
Loaded: loaded (/etc/systemd/system/consul.service; enabled; preset: enabled)
Active: active (running) since Fri 2024-01-26 08:17:23 CST; 1min 43s ago
Main PID: 9990 (consul)
Tasks: 8 (limit: 4571)
Memory: 25.9M
CPU: 1.255s
CGroup: /system.slice/consul.service
└─9990 /usr/local/bin/consul agent -config-dir=/etc/consul.d/
Access the Consul Web UI
Once Consul is running, you can easily check its status and manage it through a handy web interface. Simply open your web browser and go to a specific address using your Ubuntu machine’s IP address to see the Consul UI.
http://<Your_Ubuntu_Machine_IP>:8500/ui/
<Your_Ubuntu_Machine_IP> with the actual IP address of your Ubuntu machine.
That should do it!
Conclusion:
- Consul by HashiCorp is a powerful tool for managing microservices, service meshes, and distributed systems. It provides automated network configurations, service discovery, and secure connectivity across any cloud or runtime environment.
- Following the installation guide, you have successfully installed Consul on your Ubuntu server. This allows you to organize services, manage dependencies, and automate common networking tasks.
- With Consul’s intuitive web UI and robust features, you are now ready to join other nodes to your cluster, configure service discovery, and set up service meshes to meet your organization’s specific requirements.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
No comments yet — be the first to share your thoughts!