Skip to content

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

Download and Install Promtail Binary

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

We can also get the Promtail binary from the same place as Loki.

To check the latest version of Promtail, visit the Loki releases page. https://github.com/grafana/loki/releases/

#
cd /usr/local/bin
#
curl -O -L "https://github.com/grafana/loki/releases/download/v3.2.0/promtail-linux-amd64.zip"
#
unzip "promtail-linux-amd64.zip"

And allow the execute permission on the Promtail binary

#
chmod a+x "promtail-linux-amd64"

Create the Promtail config

Download the Promtail config that matches the version.

#
wget https://raw.githubusercontent.com/grafana/loki/v3.2.0/clients/cmd/promtail/promtail-local-config.yaml

Configure Promtail as a Service

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

Create user specifically for the Promtail service

#
useradd --system promtail

Create a file called promtail.service

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

And add this script,

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[Unit]
Description=Promtail service
After=network.target

[Service]
Type=simple
User=promtail
ExecStart=/usr/local/bin/promtail-linux-amd64 -config.file /usr/local/bin/promtail-local-config.yaml

[Install]
WantedBy=multi-user.target

Now start and check the service is running.

#
#
#
service promtail start
service promtail status
systemctl enable promtail.service

We can now leave the new Promtail service running.

Now, since this example uses Promtail to read system log files, the promtail user won't yet have permissions to read them.

So add the user promtail to the adm group

#
usermod -a -G adm promtail

Verify that the user is now in the adm group

#
id promtail

Restart Promtail and check status

#
#
service promtail restart
service promtail status

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

#
#
service promtail stop
service promtail status

Note it may take a minute to stop.

Troubleshooting

Permission Denied

msg="error creating promtail" error="open /tmp/positions.yaml: permission denied"

You should check the owner of the file configured in the positions section of the promtail-local-config.yaml matches the name of the user configured in the promtail.service script above.

My user is promtail, and the positions is set as /tmp/positions.yaml, so I set the owner.

#
chown promtail:promtail /tmp/positions.yaml

If you set up Promtail service with to run as a specific user, and you are using Promtail to view adm and you don't see any data in Grafana, but you can see the job name, then possibly you need to add the user Promtail to the adm group.

#
usermod -a -G adm promtail

You may need to restart the Promtail service and checking again its status.

Spaces versus Tabs

If you see the error found character that cannot start any token than that is likely to mean you have a tab somewhere in the YAML indenting one of the tokens. Replace it with spaces.

Tail Promtail

On Linux, you can check the syslog for any Promtail related entries by using the command,

#
tail -f /var/log/syslog | grep promtail

Daemons using outdated libraries

Since Ubuntu 22.04, installing new packages may give you a full screen prompt to restart other dependent services. Press Tab to highlight the OK option, and press Enter.

Log Browser renamed to Label browser

The Log browser has now been renamed to the [Label browser], and it is a button that opens a modal window.

Label Browser

Comments