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 "https://api.github.com/repos/grafana/loki/releases/latest" | 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 "https://github.com/grafana/loki/releases/download/v${PROMTAIL_VERSION}/promtail-linux-amd64.zip"

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 "https://raw.githubusercontent.com/grafana/loki/v${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:

[Unit]
Description=Promtail client for sending logs to Loki
After=network.target

[Service]
ExecStart=/opt/promtail/promtail -config.file=/opt/promtail/promtail-local-config.yaml
Restart=always
TimeoutStopSec=3

[Install]
WantedBy=multi-user.target

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.