Skip to content

Install Loki Binary and Start as a Service

Video Lecture

Install Loki Binary and Start as a Service Install Loki Binary and Start as a Service

 (Pay Per View)

You can use PayPal to purchase a one time viewing of this video for $1.49 USD.

Pay Per View Terms

  • One viewing session of this video will cost the equivalent of $1.49 USD in your currency.
  • After successful purchase, the video will automatically start playing.
  • You can pause, replay and go fullscreen as many times as needed in one single session for up to an hour.
  • Do not refresh the browser since it will invalidate the session.
  • If you want longer-term access to all videos, consider purchasing full access through Udemy or YouTube Memberships instead.
  • This Pay Per View option does not permit downloading this video for later viewing or sharing.
  • All videos are Copyright © 2019-2025 Sean Bradley, all rights reserved.

Download and Install Loki Binary

We will install the Loki binary as a service on our existing Grafana server.

To check the latest version of Grafana Loki, 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.5.3/loki-linux-amd64.zip"

A new Ubuntu is unlikely to have unzip pre-installed, so install it using the command,

#
apt install unzip

Now unzip the downloaded file,

#
unzip "loki-linux-amd64.zip"

And allow execute permission on the Loki binary

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

Create the Loki config

#
nano loki-local-config.yaml

Copy & paste this config into the new loki-local-config.yaml

loki v3.5.3

auth_enabled: false

server:
  http_listen_port: 3100
  grpc_listen_port: 9096
  log_level: debug
  grpc_server_max_concurrent_streams: 1000

common:
  instance_addr: 127.0.0.1
  path_prefix: /tmp/loki
  storage:
    filesystem:
      chunks_directory: /tmp/loki/chunks
      rules_directory: /tmp/loki/rules
  replication_factor: 1
  ring:
    kvstore:
      store: inmemory

query_range:
  results_cache:
    cache:
      embedded_cache:
        enabled: true
        max_size_mb: 100

limits_config:
  metric_aggregation_enabled: true
  enable_multi_variant_queries: true

schema_config:
  configs:
    - from: 2020-10-24
      store: tsdb
      object_store: filesystem
      schema: v13
      index:
        prefix: index_
        period: 24h

pattern_ingester:
  enabled: true
  metric_aggregation:
    loki_address: localhost:3100

ruler:
  alertmanager_url: http://localhost:9093

frontend:
  encoding: protobuf

#querier:
#  engine:
#    enable_multi_variant_queries: true

Alternatively, you can download a Loki config that matches your version. Replace the hashes (#) in the url.

#
wget https://raw.githubusercontent.com/grafana/loki/v#.#.#/cmd/loki/loki-local-config.yaml

Configure Loki to run as a service

Now we will configure Loki to run as a service so that it stays running in the background.

Create a user specifically for the Loki service

#
useradd --system loki

Create a file called loki.service

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

Add the script and save

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

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

[Install]
WantedBy=multi-user.target

Now start and check the service is running.

#
#
service loki start
service loki status

We can now leave the new Loki service running.

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

#
#
service loki stop
service loki status

Note it may take a minute to stop.

Warning

If you reboot your server, the Loki Service may not restart automatically.

You can set the Loki service to auto restart after reboot by entering,

#
systemctl enable loki.service

Troubleshooting

Permission Denied, Internal Server Error

If you get any of these errors

  • Loki: Internal Server Error. 500. open /tmp/loki/index/index_2697: permission denied
  • "failed to flush user" "open /tmp/loki/chunks/...etc : permission denied"
  • Loki: Internal Server Error. 500. Internal Server Error

You should check the owner of the folders configured in the storage_config section of the the loki-local-config.yaml to match the name of the user configured in the loki.service script above.

My user is loki, and the folders begins with /tmp/loki so I recursively set the owner.

chown -R loki:loki /tmp/loki

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

If when connecting to Loki using the Grafana data source configuration, you see the error Loki: Bad Gateway. 502. Bad Gateway, this will happen if the Loki service is not running, your have entered the wrong URL, or ports are blocked by a firewall. The default Loki install uses both ports 3100 for HTTP and 9096 for gRPC.

Data source connected, but no labels received

When connecting to your Loki data source for the first time, you may see the error,

  • Data source connected, but no labels received. Verify that Loki and Promtail is configured properly.

Note how it says, Data source connected at the beginning of the warning. Recent versions of Loki, despite having a successful connection, will still indicate that you have no labels because you don't have Promtail sending any data to it yet. Promtail is set up and discussed in the next lesson.

Unable to connect with Loki. Please check the server logs for more details

To view the Grafana server logs,

#
tail /var/log/grafana/grafana.log

To filter by errors,

#
tail /var/log/grafana/grafana.log | grep level=error

Error yaml: unmarshal errors: field enable_multi_variant_queries not found

Delete these lines from the end of the loki-local-config.yaml file that was downloaded from the official loki repository.

- querier:
-   engine:
-     enable_multi_variant_queries: true

and move the enable_multi_variant_queries: true to under the limits_config:.

limits_config:
  metric_aggregation_enabled: true
+  enable_multi_variant_queries: true

and then restart and check status.

#
#
service loki start
service loki status