How to Set Up Promtail in Ubuntu 20.04
On this page
Promtail is an essential tool for shipping logs from your applications to a Loki instance. When integrated with Grafana, it enables seamless log aggregation and monitoring. This guide walks you through installing and configuring Promtail on Ubuntu 20.04.
Prerequisites
- Loki and Grafana are already configured.
- A running application to monitor (e.g., NGINX in this example).
Step 1: Install Promtail
Check Your CPU Architecture:
bashuname -aDownload the Promtail Binary: Replace
amd64with your system’s architecture if different.bashcurl -O -L "https://github.com/grafana/loki/releases/download/v2.4.1/promtail-linux-amd64.zip"Extract and Make Executable:
bashunzip "promtail-linux-amd64.zip" chmod a+x "promtail-linux-amd64"Move Binary to System Path:
bashsudo cp promtail-linux-amd64 /usr/local/bin/promtailVerify Installation:
bashpromtail --version
Step 2: Configure Promtail
Create Configuration Directory:
bashsudo mkdir -p /etc/promtail /etc/promtail/logsDownload Example Configuration File: This example config is optimized for NGINX logs.
bashsudo curl -o /etc/promtail/promtail-config.yaml -L "https://gist.githubusercontent.com/theLazyCat775/6fe9125e529221166e9f02b00244638a/raw/84f510e6f62d0e60ab95dbe7f9732a629a27eb6d/promtail-config.yaml"
Step 3: Run Promtail as a Service
Create a Systemd Service File:
bashsudo vi /etc/systemd/system/promtail.serviceAdd the following content:
ini[Unit] Description=Promtail service After=network.target [Service] Type=simple User=root ExecStart=/usr/local/bin/promtail -config.file /etc/promtail/promtail-config.yaml Restart=on-failure RestartSec=20 StandardOutput=append:/etc/promtail/logs/promtail.log StandardError=append:/etc/promtail/logs/promtail.log [Install] WantedBy=multi-user.targetEnable and Start the Service:
bashsudo systemctl daemon-reload sudo systemctl start promtail sudo systemctl status promtailEnable Service on Boot:
bashsudo systemctl enable promtail.service
Step 4: Verify Logs
Check Promtail logs to ensure it is shipping logs to the Loki instance:
sudo tail -f /etc/promtail/logs/promtail.logConclusion
Promtail is now successfully installed and running as a service on Ubuntu 20.04. It is actively monitoring your application (NGINX in this case) and shipping logs to Loki for aggregation. Pair it with Grafana for powerful visualization and monitoring.
Need More Help? If you encounter issues or have specific requirements, feel free to reach out in the comments or connect on Twitter.