Skip to content

Grafana Loki - Installation and Configuration

What is Loki?

Grafana Loki collects, combines and queries logs from various sources into one centralized system.

Loki indexes logs by labels(metadata) from logs instead of the actual logs, making it more cost effective and performant than other solutions like Elasticsearch.

Configuration and query language similar to Prometheus

How does it work?

Grafana Loki has a Promtail/Fluentd/Logstash agent on the client machine which collects and sends the logs from the client to the Grafana Loki server where it can be indexed.

Labels are set by the user, so you can have control of the flow of logs and how they will be indexed.

Loki uses LogQL to filter logs.

Installation

  1. Create a dir for Loki

    mkdir ~/loki
    cd ~/loki
    

  2. Install Loki

  3. See release page for more versions

For me I got v2.9.13

curl -O -L "https://github.com/grafana/loki/releases/download/v2.9.13/loki-linux-amd64.zip"
unzip loki-linux-amd64.zip

  1. Install Loki config files

Version specific downloads

Use the Git references that match your downloaded Loki version to get the correct configuration file. For example, if you are using Loki version 3.4.1, you need to use the https://raw.githubusercontent.com/grafana/loki/v3.4.1/cmd/loki/loki-local-config.yaml URL to download the configuration file.

Use the Git references that match your downloaded Loki version to get the correct configuration file. For example, if you are using Loki version 2.9.13, you need to use the https://raw.githubusercontent.com/grafana/loki/v2.9.13/cmd/loki/loki-local-config.yaml URL to download the configuration file.

  • For v2.9.13
    wget https://raw.githubusercontent.com/grafana/loki/v2.9.13//cmd/loki/loki-local-config.yaml
    wget https://raw.githubusercontent.com/grafana/loki/v2.9.13//clients/cmd/promtail/promtail-local-config.yaml
    

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

  1. Test running Loki

  2. Create a service

  3. Edit the file by sudo vim /etc/systemd/system/GrafanaLoki.service
[Unit]
Description=Grafana Loki Service
After=network.target

[Service]
Type=simple
User=franz
WorkingDirectory=/home/franz/loki
ExecStart=/home/franz/loki/loki-linux-amd64 -config.file=/home/franz/loki/loki-local-config.yaml
Restart=on-failure
# Optional: adjust environment variables if needed
# Environment=MY_VAR=value

[Install]
WantedBy=multi-user.target

The service can be tested using

sudo systemd-analyze verify /etc/systemd/system/GrafanaLoki.service

If there are no errors, you should be fine

  1. Reload the deamon
sudo systemctl daemon-reload
  1. Start and enable the service
# Enable and start
sudo systemctl enable --now GrafanaLoki
# Check status
sudo systemctl status GrafanaLoki