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¶
-
Create a dir for Loki
-
Install Loki
- 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
- 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/main/cmd/loki/loki-local-config.yaml wget https://raw.githubusercontent.com/grafana/loki/main/clients/cmd/promtail/promtail-local-config.yaml
-
Test running Loki
-
Create a service
- 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
If there are no errors, you should be fine
- Reload the deamon
- Start and enable the service