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
- A running instance of MXLinux with sudo access.
- Docker and docker-compose installed on the MXLinux instance.
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:
Open a terminal on your MXLinux instance.
Update your system's repository cache by running the following command:
sudo apt-get updateInstall Docker by running the following command:
sudo apt-get install dockerVerify that Docker has been installed successfully by running the following command:
docker --versionIf 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:
Open a terminal on your MXLinux instance.
Run the following command to install docker-compose:
sudo apt-get install docker-composeVerify that docker-compose has been installed successfully by running the following command:
docker-compose --versionIf 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:
Open a terminal on your MXLinux instance.
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:
Open a terminal on your MXLinux instance.
Create a new directory where you will store your Loki configuration files. For example:
sudo mkdir /etc/lokiNavigate to the directory you just created:
cd /etc/lokiCreate a new file called
docker-compose.ymlby running the following command:sudo nano docker-compose.ymlCopy and paste the following code into the
docker-compose.ymlfile: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:Save and exit.
Navigate back to the
/etc/lokidirectory:cd /etc/lokiCreate a new file called
local-config.yamlby running the following command:sudo nano local-config.yamlCopy and paste the following code into the
local-config.yamlfile:auth_enabled: false server: http_listen_port: 3100 positions: filename: /tmp/loki/positions.yaml # Enable Gzip compression for HTTP requests http: compression_level: 9Save and exit.
Create a new file called
config.yamlby running the following command:
sudo nano config.yaml
- Copy and paste the following code into the
config.yamlfile:
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
Save and exit.
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.
- 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.