Install Loki Binary and Start as a Service
Video Lecture
(Pay Per View)
Download and Install Loki Binary
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/
# |
|
# |
|
A new Ubuntu is unlikely to have unzip
pre-installed, so install it using the command,
# |
|
Now unzip the downloaded file,
# |
|
And allow execute
permission on the Loki binary
# |
|
Create the Loki config
# |
|
Copy & paste this config into the new loki-local-config.yaml
loki v3.5.3
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
log_level: debug
grpc_server_max_concurrent_streams: 1000
common:
instance_addr: 127.0.0.1
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory
query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 100
limits_config:
metric_aggregation_enabled: true
enable_multi_variant_queries: true
schema_config:
configs:
- from: 2020-10-24
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
pattern_ingester:
enabled: true
metric_aggregation:
loki_address: localhost:3100
ruler:
alertmanager_url: http://localhost:9093
frontend:
encoding: protobuf
#querier:
# engine:
# enable_multi_variant_queries: true
Alternatively, you can download a Loki config that matches your version. Replace the hashes (#
) in the url.
# |
|
Configure Loki to run as a service
Now we will configure Loki to run as a service so that it stays running in the background.
Create a 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
# # |
|
Note it may take a minute to stop.
Warning
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,
# |
|
Troubleshooting
Permission Denied, Internal Server Error
If you get 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
You should check the owner of the folders configured in the storage_config
section of the the loki-local-config.yaml
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.
If when connecting to Loki using the Grafana data source configuration, you see the error Loki: Bad Gateway. 502. Bad Gateway
, this will happen if the Loki service is not running, your have entered the wrong URL, or ports are blocked by a firewall. The default Loki install uses both ports 3100
for HTTP and 9096
for gRPC.
Data source connected, but no labels received
When connecting to your Loki data source for the first time, you may see the error,
Data source connected, but no labels received. Verify that Loki and Promtail is configured properly.
Note how it says, Data source connected
at the beginning of the warning. Recent versions of Loki, despite having a successful connection, will still indicate that you have no labels because you don't have Promtail sending any data to it yet. Promtail is set up and discussed in the next lesson.
Unable to connect with Loki. Please check the server logs for more details
To view the Grafana server logs,
# |
|
To filter by errors,
# |
|
Error yaml: unmarshal errors:
field enable_multi_variant_queries not found
Delete these lines from the end of the loki-local-config.yaml
file that was downloaded from the official loki repository.
- querier:
- engine:
- enable_multi_variant_queries: true
and move the enable_multi_variant_queries: true
to under the limits_config:
.
limits_config:
metric_aggregation_enabled: true
+ enable_multi_variant_queries: true
and then restart and check status.
# # |
|