Installing Loki on MXLinux

Introduction

Loki is a horizontally-scalable, highly-available, multi-tenant log aggregation system designed to support large-scale, distributed systems. In this tutorial, we will walk you through the process of installing Loki on MXLinux.

Prerequisites

Step 1: Installing Docker

Before we can install Loki, we need to install Docker on our MXLinux instance. Here's how you can do that:

  1. Open a terminal on your MXLinux instance.

  2. Update your system's repository cache by running the following command:

    sudo apt-get update
    
  3. Install Docker by running the following command:

    sudo apt-get install docker
    
  4. Verify that Docker has been installed successfully by running the following command:

    docker --version
    

    If Docker has been installed successfully, the output should display the version of Docker installed.

Step 2: Installing docker-compose

docker-compose is a tool for defining and running multi-container Docker applications. We'll need it to run Loki on our MXLinux instance. Here's how you can install docker-compose:

  1. Open a terminal on your MXLinux instance.

  2. Run the following command to install docker-compose:

    sudo apt-get install docker-compose
    
  3. Verify that docker-compose has been installed successfully by running the following command:

    docker-compose --version
    

    If docker-compose has been installed successfully, the output should display the version of docker-compose installed.

Step 3: Creating a Docker Network

Loki requires a Docker network to be set up in order for it to communicate with other services. Here's how to set it up:

  1. Open a terminal on your MXLinux instance.

  2. Run the following command to create a new Docker network:

    sudo docker network create loki
    

Step 4: Installing Loki

With Docker and docker-compose installed and a Docker network set up, we can now proceed with installing Loki. Here's how you can do that:

  1. Open a terminal on your MXLinux instance.

  2. Create a new directory where you will store your Loki configuration files. For example:

    sudo mkdir /etc/loki
    
  3. Navigate to the directory you just created:

    cd /etc/loki
    
  4. Create a new file called docker-compose.yml by running the following command:

    sudo nano docker-compose.yml
    
  5. Copy and paste the following code into the docker-compose.yml file:

    version: "3.7"
    
    services:
      loki:
        image: grafana/loki:latest
        ports:
          - 3100:3100
        command: -config.file=/etc/loki/local-config.yaml
        volumes:
          - ./local-config.yaml:/etc/loki/local-config.yaml
        networks:
          - loki
    
      promtail:
        image: grafana/promtail:latest
        command: -config.file=/etc/promtail/config.yaml
        volumes:
          - ./config.yaml:/etc/promtail/config.yaml
          - /var/log:/var/log
        networks:
          - loki
    
    networks:
      loki:
    
  6. Save and exit.

  7. Navigate back to the /etc/loki directory:

    cd /etc/loki
    
  8. Create a new file called local-config.yaml by running the following command:

    sudo nano local-config.yaml
    
  9. Copy and paste the following code into the local-config.yaml file:

    auth_enabled: false
    
    server:
      http_listen_port: 3100
    
    positions:
      filename: /tmp/loki/positions.yaml
    
    # Enable Gzip compression for HTTP requests
    http:
      compression_level: 9
    
  10. Save and exit.

  11. Create a new file called config.yaml by running the following command:

sudo nano config.yaml
  1. Copy and paste the following code into the config.yaml file:
server:
  http_listen_port: 9080

positions:
  filename: /tmp/promtail/positions.yaml

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

scrape_configs:
- job_name: system
  static_configs:
  - targets:
      - localhost
    labels:
      job: varlogs
      __path__: /var/log/*log
  1. Save and exit.

  2. Start the Loki and Promtail services by running the following command:

docker-compose up -d

This will start the Loki and Promtail services in the background.

  1. Verify that Loki is running by navigating to http://localhost:3100 in your web browser.

If Loki is running successfully, you should see the Loki dashboard.

Conclusion

In this tutorial, we've covered the steps required to install Loki on MXLinux. Now that Loki is installed, you can start using it to aggregate and query log data from your applications.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!