Setup and Requirements for Grafana Loki
Introduction
To successfully deploy and configure Grafana Loki, you must meet several hardware and software requirements, as well as install and configure specific dependencies. Below is a structured guide that includes visual elements and tooltips to make this setup process more understandable and digestible for students.
::: tip Promtail is the log collection agent that pushes logs to Loki. It needs to be configured to send logs to the Loki server. :::
::: tip If you want to send docker container's logs to Loki, there is a plugin available which makes it easy to send logs without promtail. :::
- Grafana: Used for visualization and querying logs stored in Loki.
- Promtail: Collects logs from different sources and sends them to Loki.
Deployment Steps
Deploying Loki is easy with a straightforward set of steps. You can use Docker, Helm, or binaries for the deployment process.
::: info For a quick start, using Docker is the most straightforward approach for testing Loki in a development environment. :::
Install Loki with Docker or Docker Compose
You can install Loki and Promtail with Docker or Docker Compose if you are evaluating, testing, or developing Loki. For production, Grafana recommends installing with Helm or Tanka.
The configuration files associated with these installation instructions run Loki as a single binary.
Prerequisites
- Docker
- Docker Compose (optional, only needed for the Docker Compose install method)
Install with Docker on Linux
-
Create a directory called
loki. Makelokiyour current working directory:mkdir loki
cd loki -
Copy and paste the following commands into your command line to download
loki-local-config.yamlandpromtail-docker-config.yamlto yourlokidirectory.wget https://raw.githubusercontent.com/grafana/loki/v3.3.2/cmd/loki/loki-local-config.yaml -O loki-config.yaml
wget https://raw.githubusercontent.com/grafana/loki/v3.3.2/clients/cmd/promtail/promtail-docker-config.yaml -O promtail-config.yaml -
Copy and paste the following commands into your command line to start the Docker containers using the configuration files you downloaded in the previous step.
docker run --name loki -d -v $(pwd):/mnt/config -p 3100:3100 grafana/loki:3.3.2 -config.file=/mnt/config/loki-config.yaml
docker run --name promtail -d -v $(pwd):/mnt/config -v /var/log:/var/log --link loki grafana/promtail:3.3.2 -config.file=/mnt/config/promtail-config.yaml
::: note
The image is configured to run by default as user loki with UID 10001 and GID 10001. You can use a different user, specially if you are using bind mounts, by specifying the UID with a docker run command and using --user=UID with a numeric UID suited to your needs.
:::
-
Verify that your containers are running:
docker container lsYou should see something similar to the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9485de9ad351 grafana/promtail:3.3.2 "/usr/bin/promtail -…" About a minute ago Up About a minute promtail
cece1df84519 grafana/loki:3.3.2 "/usr/bin/loki -conf…" About a minute ago Up About a minute 0.0.0.0:3100->3100/tcp, :::3100->3100/tcp loki -
Verify that Loki is up and running.
- To view readiness, navigate to http://localhost:3100/ready.
- To view metrics, navigate to http://localhost:3100/metrics.
Install with Docker on Windows
- Copy and paste the following commands into your command line to download
loki-local-config.yamlandpromtail-docker-config.yamlto yourlokidirectory. Note that you will need to replace the<local-path>in the commands with your local path.
cd "<local-path>"
wget https://raw.githubusercontent.com/grafana/loki/v3.3.2/cmd/loki/loki-local-config.yaml -O loki-config.yaml
wget https://raw.githubusercontent.com/grafana/loki/v3.3.2/clients/cmd/promtail/promtail-docker-config.yaml -O promtail-config.yaml
- Copy and paste the following commands into your command line to start the Docker containers using the configuration files you downloaded in the previous step. Note that you will need to replace the
<local-path>in the commands with your local path.
docker run --name loki -v <local-path>:/mnt/config -p 3100:3100 grafana/loki:3.3.2 --config.file=/mnt/config/loki-config.yaml
docker run -v <local-path>:/mnt/config -v /var/log:/var/log --link loki grafana/promtail:3.3.2 --config.file=/mnt/config/promtail-config.yaml
-
Verify that Loki is up and running.
- To view readiness, navigate to http://localhost:3100/ready.
- To view metrics, navigate to http://localhost:3100/metrics.
Install with Docker Compose
::: tip "Steps to install Docker & Docker compose on Amazon Linux"
- Steps to install docker
sudo yum update -y
sudo yum install -y docker
sudo systemctl enable docker
sudo systemctl start docker
sudo usermod -a -G docker ec2-user
docker info
- Steps to install docker compose
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose version
:::
Run the following commands in your command line. They work for Windows or Linux systems.
-
Create a directory called
loki. Makelokiyour current working directory:mkdir loki
cd loki -
Copy and paste the following command into your command line to download the
docker-composefile.wget https://raw.githubusercontent.com/grafana/loki/v3.3.2/production/docker-compose.yaml -O docker-compose.yaml -
With
lokias the current working directory, run the following 'docker-compose` command:docker-compose -f docker-compose.yaml upYou should see something similar to the following:
Container loki-loki-1 Started 0.0s
Container loki-grafana-1 Started 0.0s
Container loki-promtail-1 Started 0.0s -
Verify that Loki is up and running.
- To view readiness, navigate to http://localhost:3100/ready.
- To view metrics, navigate to http://localhost:3100/metrics.