Install Promtail Binary and Start as a Service

Video Lecture

Install Promtail Binary and Start as a Service Install Promtail Binary and Start as a Service Install Promtail Binary and Start as a Service

Download and Install Promtail Binary

Now we will create the Promtail service that will act as the collector for Loki.

cd /usr/local/bin
sudo curl -fSL -o promtail.gz "https://github.com/grafana/loki/releases/download/v1.4.1/promtail-linux-amd64.zip"
sudo gunzip promtail.gz

And allow the execute permission on the Promtail binary

sudo chmod a+x promtail

Create the Promtail config

Now we will create the Promtail config file.

sudo nano config-promtail.yml

And add this script,

server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /tmp/positions.yaml

clients:
  - url: http://127.0.0.1:3100/loki/api/v1/push

scrape_configs:
  - job_name: journal
    journal:
      max_age: 12h
      path: /var/log/journal
      labels:
        job: systemd-journal
    relabel_configs:
      - source_labels: ['__journal__systemd_unit']
        target_label: 'unit'

Test Promtail Works,

You can now test Promtail by running

sudo promtail -config.file /usr/local/bin/config-promtail.yml

Open a browser and visit,

http://[Your Server Domain or IP]:9080

After having a good look around to verify it works, stop the Promtail server by pressing CTRL-C.

Configure Firewall

When your Promtail server is running, it will be accessible remotely. If you only want localhost to be able to connect, then type

iptables -A INPUT -p tcp -s localhost --dport 9080 -j ACCEPT
iptables -A INPUT -p tcp --dport 9080 -j DROP
iptables -L

Configure Promtail as a Service

Now we will configure Promtail as a service so that we can keep it running in the background.

Create a file called promtail.service

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

And add this script,

[Unit]
Description=Promtail service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/promtail -config.file /usr/local/bin/config-promtail.yml

[Install]
WantedBy=multi-user.target

Now start and check the service is running.

sudo service promtail start
sudo service promtail status

We can now leave the new Promtail service running.

If you ever need to stop the new Promtail service, then type

sudo service promtail stop
sudo service promtail status