Installing Loki on Ubuntu 22.04 LTS


Grafana Loki is a logging platform developed by Grafana Labs. It is designed to be a highly scalable, multi-tenant log aggregation system that is easy to use and operate. It is built on top of the popular open-source log aggregation tool, Prometheus, and is compatible with its data model and query language.


  1. Ubuntu up and running linux machine
  2. Root permission
  3. Internet connectivity
  4. Basic knowledge of linux commands
  5. Up and running Grafana Machine

You will learn how to set up an Loki server on your Ubuntu 22.04 server in this guide.

Step 1: Run System Updates

You need to update the ubuntu current repository by following the given command.

sudo apt-get update 

Step 2: Download Loki

We need to download the Grafana Loki binaries for ubuntu, To get latest version you need to click here and get copy the latest link and change with given command in order to download the package.


To unzip the zip file.


to move in system binary location.

sudo mv loki-linux-amd64 /usr/local/bin/loki

to create directory for data and configuration file.

sudo mkdir /etc/loki && sudo mkdir -p /data/loki

Step 3: Create Loki Config file

We are ready to create a config file to configure listen port, check setting, schema config prefix and other required setting, Execute the given command one by one.

To create a main config file with named loki-local-config.yaml

sudo vim /etc/loki-local-config.yaml

Paste the following standard configuration.

auth_enabled: false

  http_listen_port: 3100

        store: inmemory
      replication_factor: 1
    final_sleep: 0s
  chunk_idle_period: 5m
  chunk_retain_period: 30s
  max_transfer_retries: 0

    - from: 2018-04-15
      store: boltdb
      object_store: filesystem
      schema: v11
        prefix: index_
        period: 168h

    directory: /data/loki/index

    directory: /data/loki/chunks

  enforce_metric_name: false
  reject_old_samples: true
  reject_old_samples_max_age: 168h

  max_look_back_period: 0s

  retention_deletes_enabled: false
  retention_period: 0s

Save and exit from the vim text editor.

Step 4: Creating SystemD Service

The SystemD service is critical to create because it will handle the Grafana-Loki process, which we can easily start, stop, restart, enable, and disable during server boot, Use the given command for the same.

To create a systemD config file with named loki.service

sudo vim /etc/systemd/system/loki.service

Paste the following configuration.

Description=Loki service

ExecStart=/usr/local/bin/loki -config.file /etc/loki-local-config.yaml


Save and exit from the text editor and now we are good to reload the daemon.

sudo systemctl daemon-reload

To start the Grafana;s Loki service.

sudo systemctl start loki.service

To check loki service status.

sudo systemctl status loki.service

It should show in running state with 3100 port number.

You loki server endpoint would be like http://localhost:3100 or http://IP_ADDRESS:3100, You should open the port 3100 in your OS level firewall and network level firewall.

Note: We have only installed Grafana Loki, which collects the logs from the target machine, but we need a Promtail agent in every machine to get logs from the client machine to the Grafana Loki server.

Step 5: Installing Promtail Agent

Pomtail is an agent that is typically installed on every machine that hosts applications that require logs monitoring. It transmits the contents of local logs to Grafana Loki server or the Grafana cloud.

To download Promtail package, You can download the latest version of Promtail by clicking here and update in given command.

curl -LO

To unzip Promtail’s zip file.


To move the promtail’s file in system’s binary location.

sudo mv promtail-linux-amd64 /usr/local/bin/promtail

To create promtail main configuration file.

sudo vim /etc/promtail-local-config.yaml

Paste the following configuration.

  http_listen_port: 9080
  grpc_listen_port: 0

  filename: /data/loki/positions.yaml

  - url: http://localhost:3100/loki/api/v1/push

- job_name: system
  - targets:
      - localhost
      job: varlogs
      __path__: /var/log/*log

Note: In the above promtail configuration we are only adding /var/log directory to ship to loki server.

The above configuration contains the log path, a Grafana endpoint with a port number, and more. You can add more jobs here to monitor your application. We need to update the log path.

To create a SystemD service for promtail.

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

Paste the following configuration.

Description=Promtail service

ExecStart=/usr/local/bin/promtail -config.file /etc/promtail-local-config.yaml


Save and exit from the text editor and we are good to reload the daemon.

To reload the daemon.

sudo systemctl daemon-reload

To start the promtail serivce.

sudo systemctl start promtail.service

To check promtail service status.

sudo systemctl status promtail.service

You should get Promtail service up and running in your screen.

We are good to configure Loki endpoint in our grafana server to receive the logs from promtail agent.

Step 6: Configure Loki with Grafana

We need to add the Loki data source in our Grafana server by using our Loki endpoint, and after that, we will be able to see the logs in our Grafana Loki Query section, and later on, we can create log metrics with alerting.

Login in your Grafana account.

Add the Loki data source.

Enter the Loki server access point and port number.

Test the Loki data source.

Test logs in your Grafana’s Loki query box.


We have successfully installed Grafana-loki with promtail agent on ubuntu 22.04 LTS server, If you still have questions, please post them in the comments section below.


Installing Loki on Ubuntu 22.04 LTS

2 thoughts on “Installing Loki on Ubuntu 22.04 LTS

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top