Installing Promtail on ubuntu
Install Promtail
Adding Repo
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 |