Install Promtail on Ubuntu 20.04

Install Promtail on Ubuntu 20.04

Promtail is a client for gathering and sending logs to Loki. Promtail is commonly deployed to every machine that needed to monitor logs.

This tutorial shows how to install Promtail on Ubuntu 20.04.

Prepare environment

Before starting, make sure you have installed Loki in your system. You can read post how to install it.

Install Promtail

Promtail installation steps very similar to Loki.

Promtail source code is stored in the same repository as Loki. Retrieve the latest version tag of Promtail release from GitHub and assign version tag to variable.

PROMTAIL_VERSION=$(curl -s "" | grep -Po '"tag_name": "v\K[0-9.]+')

Create a new directory for storing Promtail binary and configuration file.

sudo mkdir /opt/promtail

Run the following command to download Promtail archive from releases page of the Loki repository.

sudo wget -qO /opt/promtail/promtail.gz "${PROMTAIL_VERSION}/"

Extract binary file from archive:

sudo gunzip /opt/promtail/promtail.gz

Set execute permission for extracted file:

sudo chmod a+x /opt/promtail/promtail

We can create a symbolic link to the promtail command in /usr/local/bin directory:

sudo ln -s /opt/promtail/promtail /usr/local/bin/promtail

Now promtail can be used as a system-wide command for all users.

Download configuration file for Promtail:

sudo wget -qO /opt/promtail/promtail-local-config.yaml "${PROMTAIL_VERSION}/clients/cmd/promtail/promtail-local-config.yaml"

Check Promtail version to verify that the installation completed successfully:

promtail -version

Run Promtail as a service

We can configure systemd to run Promtail as a service. Create a systemd unit file:

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

Add the following content:

Description=Promtail client for sending logs to Loki

ExecStart=/opt/promtail/promtail -config.file=/opt/promtail/promtail-local-config.yaml


Start Promtail service:

sudo service promtail start

You can execute the following command to make sure that Promtail service is running:

sudo service promtail status

Also you can stop or restart the service:

sudo service promtail stop
sudo service promtail restart

To enable Promtail to start on boot, run the following command:

sudo systemctl enable promtail

Uninstall Promtail

If you want to completely remove the Promtail, stop the service and remove a systemd unit file.

sudo service promtail stop
sudo systemctl disable promtail
sudo rm -rf /etc/systemd/system/promtail.service
sudo systemctl daemon-reload
sudo systemctl reset-failed

Remove the installation directory:

sudo rm -rf /opt/promtail

Remove symbolic link:

sudo rm -rf /usr/local/bin/promtail

Leave a Comment

Cancel reply

Your email address will not be published.