Installing Loki on CentOS / Debian
Loki is a repository for logs (prometheus like), i.e. a set of components for a complete system for working with logs.
Add a system user from which Loki will work
$ sudo useradd -r -M -s /bin/false loki
Downloading Loki
$ cd /usr/local/bin
$ sudo curl -O -L "https://github.com/grafana/loki/releases/download/v2.0.0/loki-linux-amd64.zip"
Unpack
Распаковываем
$ sudo unzip loki-linux-amd64.zip
Delete the archive
$ sudo rm loki-linux-amd64.zip
Affairs file executable
$ sudo chmod a+x "loki-linux-amd64"
Change owner
$ sudo chown loki:loki loki-linux-amd64
We create a configuration file, or download a ready
$ wget https://raw.githubusercontent.com/grafana/loki/master/cmd/loki/loki-local-config.yaml
$ sudo nano config-loki.yml
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
max_transfer_retries: 0
schema_config:
configs:
- from: 2018-04-15
store: boltdb
object_store: filesystem
schema: v11
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: 0s
table_manager:
retention_deletes_enabled: false
retention_period: 0s
In address: 127.0.0.1 – listen to localhost In address: 0.0.0.0 we specify to listen to all available interfaces.
Change the owner of the config
$ sudo chown loki:loki config-loki.yml
Create Systemd Unit
$ sudo nano /etc/systemd/system/loki.service
[Unit]
Description=Loki service
After=network.target
[Service]
Type=simple
User=loki
ExecStart=/usr/local/bin/loki-linux-amd64 -config.file /usr/local/bin/config-loki.yml
[Install]
WantedBy=multi-user.target
Add the service to startup and start
$ sudo systemctl daemon-reload
$ sudo systemctl enable --now loki
$ systemctl status loki
We look at the service logs
$ sudo tail -f /var/log/messages | grep loki
Checking port 3100 to see if Loki has started
$ ss -nltup | grep 3100
We configure the Firewall, open the port to the outside, if necessary
$ sudo firewall-cmd --add-port=3100/tcp --permanent
$ sudo firewall-cmd --reload
http://[Your-Server-Domain-or-IP]:3100/metrics
Next, it remains to connect Loki to the Grafana visualization system, and install on the servers from which we want to shoot logs, the agent – Promtail