How to setup Promtail in Ubuntu 20.04
Promtail is an agent which ships the contents of local logs to Loki instance. It is usually deployed to every machine that has applications needed to be monitored.
It primarily:
- Discovers targets
- Attaches labels to log streams
- Pushes them to the Loki instance
In this article i’m using Promtail version 2.4.1.
Prerequisites
Loki already configured (check this article on how to setup Loki)
Grafana already configured
A Running Application which needs to be monitor (For this article I’m using NGINX)
Install Promtail
Download Promtail binary according to your system and CPU architecture from here.
I’m system is Linux and CPU architecture is amd64. To check CPU architecture run below command.
#check cpu architecture
uname -a#example for Loki on the linux operating system and amd64 architecture
curl -O -L "https://github.com/grafana/loki/releases/download/v2.4.1/promtail-linux-amd64.zip"#extract the binary
unzip "promtail-linux-amd64.zip"#make sure it is executable
chmod a+x "promtail-linux-amd64"#copy binary to /usr/local/bin/
sudo cp promtail-linux-amd64 /usr/local/bin/promtail#verify installation by checking version
promtail --version
Now, it’s time create config file for Promtail.
#create dir in /etc
sudo mkdir -p /etc/promtail /etc/promtail/logs#promtail config file for nginx
sudo curl -o /etc/promtail/promtail-config.yaml -L "https://gist.githubusercontent.com/theLazyCat775/6fe9125e529221166e9f02b00244638a/raw/84f510e6f62d0e60ab95dbe7f9732a629a27eb6d/promtail-config.yaml"
Configure Promtail to run as a service.
#Create a file called promtail.service
sudo vi /etc/systemd/system/promtail.service
Add the script and save.
[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.target
Run below command to start promtail as a service.
sudo systemctl daemon-reload #To reload systemd
sudo systemctl start promtail #to start promtail
sudo systemctl status promtail #to check status
sudo systemctl restart promtail #to restart
You can check logs of Loki at /etc/promtail/logs/promtail.log
Enable Promtail on system boot.
sudo systemctl enable promtail.service
Now Promtail is successfully installed and running as service in Ubuntu 20.04.