How to setup Loki in Ubuntu 20.04

  • 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.

Install Loki

#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
loki --version
#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
#Create a file called loki.service
sudo vi /etc/systemd/system/loki.service
[Unit] 
Description=Loki service
After=network.target

[Service]
Type=simple
User=loki
ExecStart=/usr/local/bin/loki -config.file /etc/loki/loki-local-config.yaml
Restart=on-failure
RestartSec=20
StandardOutput=append:/etc/loki/logs/loki.log
StandardError=append:/etc/loki/logs/loki.log

[Install]
WantedBy=multi-user.target
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
sudo systemctl enable loki.service
http://localhost:3100/metrics
http://localhost:3100/metrics

--

--

--

DevOps Engineer, Linux lover, Technology and Automation enthusiast. A strong believer in continuous learning.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sujit Patel

Sujit Patel

DevOps Engineer, Linux lover, Technology and Automation enthusiast. A strong believer in continuous learning.

More from Medium

Running Ansible from Gitlab CI

Jenkins Vs Teamcity CI Tool

How to install Jenkins without installing Java?(Using docker)

Reverse Proxy Feature of NGINX Server