Install Loki Binary and Start as a Service

Video Lecture

Install Loki Binary and Start as a Service
Install Loki Binary and Start as a Service 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.

cd /usr/local/bin
sudo curl -fSL -o loki.gz "https://github.com/grafana/loki/releases/download/v1.4.1/loki-linux-amd64.zip"
sudo gunzip loki.gz

And allow the execute permission on the Loki binary

sudo chmod a+x loki

Create the Loki config

Now create the Loki config file.

sudo nano config-loki.yml

And add this text

auth_enabled: false

server:
  http_listen_port: 3100

ingester:
  lifecycler:
    address: 127.0.0.1
    ring:
      kvstore:
        store: inmemory
      replication_factor: 1
    final_sleep: 0s
  chunk_idle_period: 5m
  chunk_retain_period: 30s

schema_config:
  configs:
  - from: 2018-04-15
    store: boltdb
    object_store: filesystem
    schema: v9
    index:
      prefix: index_
      period: 168h

storage_config:
  boltdb:
    directory: /tmp/loki/index

  filesystem:
    directory: /tmp/loki/chunks

limits_config:
  enforce_metric_name: false
  reject_old_samples: true
  reject_old_samples_max_age: 168h

chunk_store_config:
  max_look_back_period: 0

table_manager:
  chunk_tables_provisioning:
    inactive_read_throughput: 0
    inactive_write_throughput: 0
    provisioned_read_throughput: 0
    provisioned_write_throughput: 0
  index_tables_provisioning:
    inactive_read_throughput: 0
    inactive_write_throughput: 0
    provisioned_read_throughput: 0
    provisioned_write_throughput: 0
  retention_deletes_enabled: false
  retention_period: 0

Test Loki Works,

You can now test Loki by running

sudo loki -config.file /usr/local/bin/config-loki.yml

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 Firewall

When your Loki server is running, it will be accessible remotely. If you only want localhost to be able to connect, then type

iptables -A INPUT -p tcp -s localhost --dport 3100 -j ACCEPT
iptables -A INPUT -p tcp --dport 3100 -j DROP
iptables -L

Configure Loki as a Service

Now we will configure Loki as a service so that we can keep it running in the background.

Create a file called loki.service

sudo nano /etc/systemd/system/loki.service

Add the script and save

[Unit]
Description=Loki service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/loki -config.file /usr/local/bin/config-loki.yml

[Install]
WantedBy=multi-user.target

Now start and check the service is running.

sudo service loki start
sudo service loki status

We can now leave the new Loki service running.

If you ever need to stop the new Loki service, then type

sudo service loki stop
sudo service loki status

Note it may take a minute to stop