Install Loki Binary and Start as a Service
Download and Install Loki Binary
To keep this as simple as possible, we will install the Loki binary as a service on our existing Grafana server.
To check the latest version of Grafana Loki, visit the Loki releases page. https://github.com/grafana/loki/releases/
And allow the execute permission on the Loki binary
Create the Loki config
Now create the Loki config file.
And add this text.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
This default configuration was copied from [https://raw.githubusercontent.com/grafana/loki/master/cmd/loki/loki-local-config.yaml] when it was version 1.6.1. There will be changes to this config depending on any future updates to Loki.
Test Loki Works,
You can now test Loki by running
Open a browser and visit,
http://[Your Server Domain or IP]:3100/metrics
Now stop the Loki server by pressing CTRL-C. Note that it may take a minute for the process to stop.
Configure Loki as a Service
Now we will configure Loki as a service so that we can keep it running in the background.
Create user specifically for the Loki service
Create a file called loki.service
Add the script and save
1 2 3 4 5 6 7 8 9 10 11
Now start and check the service is running.
We can now leave the new Loki service running.
If you ever need to stop the new Loki service, then type
If you reboot your server, the Loki Service may not restart automatically.
You can set the Loki service to auto restart after reboot by entering,
sudo systemctl enable loki.service
Note it may take a minute to stop.
When your Loki server is running, it may be accessible remotely. If you only want localhost to be able to connect, then type
1 2 3
After blocking port 3100 for external requests, you can verify that local request still work using
iptables settings will be lost in case of system reboot. You will need to reapply them manually,
This will save your settings into two files called,
Any changes you make to the iptables configuration won't be auto saved to these persistent files, so if you want to update these files with any changes, then use the commands,
iptables-save > /etc/iptables/rules.v4
iptables-save > /etc/iptables/rules.v6
If you any of these errors
Loki: Internal Server Error. 500. open /tmp/loki/index/index_2697: permission denied
"failed to flush user" "open /tmp/loki/chunks/...etc : permission denied"
Loki: Internal Server Error. 500. Internal Server Error
Data source connected, but no labels received. Verify that Loki and Promtail is configured properly.
You should check the owner of the folders configured in the storage_config section of the the config-loki.yml to match the name of the user configured in the loki.service script above.
My user is loki, and the folders begins with /tmp/loki so I recursively set the owner.
chown -R loki:loki /tmp/loki
You may need to restart the loki service and checking again its status.