How to setup Loki in Ubuntu 20.04
Loki is a horizontally-scalable, highly-available, multi-tenant log aggregation system inspired by Prometheus. It is designed to be very cost effective and easy to operate. It does not index the contents of the logs, but rather a set of labels for each log stream.
A Loki-based logging stack consists of 3 components:
- Promtail is the agent, responsible for gathering logs and sending them to Loki.
- Loki is the main server, responsible for storing logs and processing queries.
- Grafana for querying and displaying the logs.
In this article i’m using Loki version 2.4.1.
Download Loki binary according to your system and CPU architecture from here.
I’m system is Linux and CPU architecture is amd64. To check CPU architecture run below command.
#check cpu architecture
uname -a#example for Loki on the linux operating system and amd64 architecturecurl -O -L "https://github.com/grafana/loki/releases/download/v2.4.1/loki-linux-amd64.zip"#extract the binary
unzip "loki-linux-amd64.zip"#make sure it is executable
chmod a+x "loki-linux-amd64"#copy binary to /usr/local/bin/
sudo cp loki-linux-amd64 /usr/local/bin/loki#verify installation by checking version
Now, it’s time create config file for Loki.
#create user for loki
sudo useradd --system loki#create dir in /etc
sudo mkdir -p /etc/loki /etc/loki/logs#default loki config file
sudo curl -o /etc/loki/loki-local-config.yaml -L "https://gist.githubusercontent.com/theLazyCat775/ceaf475fc369e25a2d04501f8a7c0a59/raw/fdf2cbc14d540085b68911972f1eb1f8fa9de908/loki-local-config.yaml"#change permissions
sudo chown -R loki: /etc/loki
Configure Loki to run as a service.
#Create a file called loki.service
sudo vi /etc/systemd/system/loki.service
Add the script and save.
ExecStart=/usr/local/bin/loki -config.file /etc/loki/loki-local-config.yaml
Run below command to start loki as a service.
sudo systemctl daemon-reload #To reload systemd
sudo systemctl start loki #to start loki
sudo systemctl status loki #to check status
sudo systemctl restart loki #to restart
You can check logs of Loki at /etc/loki/logs/loki.log
Enable Loki on system boot.
sudo systemctl enable loki.service
To Check metrics received by loki. Open browser and type below address.
Now Loki is successfully installed and running as service in Ubuntu 20.04.