On this page
- How do Loki, Alloy and Promtail relate?
- How do I add the repository and install the packages?
- How do I configure Loki for a single server?
- How do I ship journal and file logs with Alloy?
- How do I check that logs arrive?
- How do I send logs from other servers securely?
- How do I migrate from Promtail?
- How do I keep Loki fast and small?
- Questions
How do Loki, Alloy and Promtail relate?
Loki stores log lines and indexes only their labels, such as host, job or unit, which keeps it cheap compared with full text search engines. A separate agent reads logs on each server and pushes them to Loki over HTTP. For years that agent was Promtail. It was deprecated in early 2025 in favour of Grafana Alloy and reached end of life in early 2026, so it no longer receives fixes. Existing Promtail installs keep working, but new servers should use Alloy, and the alloy convert command translates a Promtail YAML file into Alloy syntax.
You read the logs in Grafana, ideally next to the metrics from Prometheus, so a CPU spike and the matching error lines sit on one screen.
How do I add the repository and install the packages?
Loki and Alloy are in the same APT repository as Grafana. If you already set it up for Grafana, skip the first block.
sudo apt install -y wget gpg
sudo mkdir -p /etc/apt/keyrings
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt updatesudo apt install -y loki alloy
apt policy loki alloy
loki -version | head -n 1
alloy --versionRun this on Ubuntu 24.04 or 22.04, or Debian 12 or 13. Plan disk space carefully: logs from a busy web server add up quickly, and Loki should never fill the root filesystem.
How do I configure Loki for a single server?
Replace /etc/loki/config.yml with a compact single node config. It listens on loopback only, stores data under /var/lib/loki and deletes logs older than 14 days:
auth_enabled: false
server:
http_listen_address: 127.0.0.1
http_listen_port: 3100
grpc_listen_address: 127.0.0.1
grpc_listen_port: 9096
common:
instance_addr: 127.0.0.1
path_prefix: /var/lib/loki
replication_factor: 1
ring:
kvstore:
store: inmemory
storage:
filesystem:
chunks_directory: /var/lib/loki/chunks
rules_directory: /var/lib/loki/rules
schema_config:
configs:
- from: 2024-04-01
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
limits_config:
retention_period: 336h
compactor:
working_directory: /var/lib/loki/compactor
retention_enabled: true
delete_request_store: filesystemsudo mkdir -p /var/lib/loki
sudo chown -R loki:loki /var/lib/loki
sudo systemctl restart loki
sudo systemctl enable loki
curl -s http://127.0.0.1:3100/readyThe last command prints ready after a few seconds. If Loki refuses to start, sudo journalctl -u loki -n 40 names the offending line.
How do I ship journal and file logs with Alloy?
Alloy uses its own block based configuration language. Write /etc/alloy/config.alloy:
loki.write "local" {
endpoint {
url = "http://127.0.0.1:3100/loki/api/v1/push"
}
external_labels = { host = "monitor" }
}
loki.source.journal "journal" {
forward_to = [loki.write.local.receiver]
relabel_rules = loki.relabel.journal.rules
labels = { job = "journal" }
}
loki.relabel "journal" {
forward_to = []
rule {
source_labels = ["__journal__systemd_unit"]
target_label = "unit"
}
}
local.file_match "varlog" {
path_targets = [{ "__path__" = "/var/log/nginx/*.log", "job" = "nginx" }]
}
loki.source.file "varlog" {
targets = local.file_match.varlog.targets
forward_to = [loki.write.local.receiver]
}Alloy runs as its own user, which needs read access to the journal and to files owned by the adm group:
sudo usermod -aG systemd-journal,adm alloy
alloy fmt /etc/alloy/config.alloy > /dev/null && echo syntax ok
sudo systemctl restart alloy
sudo systemctl enable alloyAlloy has a debug UI on 127.0.0.1:12345; reach it through an SSH tunnel to see every component and whether it is healthy.
How do I check that logs arrive?
Ask Loki directly before adding Grafana. This lists the label values it has seen and fetches a few recent journal lines:
curl -s http://127.0.0.1:3100/loki/api/v1/label/job/values
curl -G -s http://127.0.0.1:3100/loki/api/v1/query_range \
--data-urlencode 'query={job="journal"}' \
--data-urlencode 'limit=5' | head -c 600Then in Grafana add a data source of type Loki with URL http://127.0.0.1:3100 and open Explore. Useful LogQL to start with:
{job="journal", unit="ssh.service"} |= "Failed password"
sum by (unit) (count_over_time({job="journal"} |~ "(?i)error" [5m]))The first shows failed SSH logins, the second counts lines with "error" per systemd unit, which works well as an alert rule.
How do I send logs from other servers securely?
Remote pushes travel over public IPs because there is no private network between our servers, so never open port 3100 directly. Put Loki behind Caddy on the central server so every request needs HTTPS and a password:
logs.example.net {
basic_auth {
web1 PASTE_HASH_FROM_caddy_hash-password
}
reverse_proxy 127.0.0.1:3100
}On each remote server, install only Alloy, store the plain password in /etc/alloy/loki.pass (owner alloy, mode 600) and point its writer at the HTTPS address:
loki.write "central" {
endpoint {
url = "https://logs.example.net/loki/api/v1/push"
basic_auth {
username = "web1"
password_file = "/etc/alloy/loki.pass"
}
}
external_labels = { host = "web1" }
}Give every server its own user so you can revoke one without touching the others. An SSH tunnel is an alternative for one or two machines, and Caddy HTTPS covers the certificate side.
How do I migrate from Promtail?
Convert the existing file, review the output, then swap services:
alloy convert --source-format=promtail --output=/tmp/config.alloy /etc/promtail/config.yml
sudo cp /tmp/config.alloy /etc/alloy/config.alloy
sudo systemctl disable --now promtail
sudo systemctl restart alloyKeep the labels identical to what Promtail sent, or saved Grafana queries and alerts will stop matching. Remove the old package once Alloy has run cleanly for a day.
How do I keep Loki fast and small?
- Few labels, low cardinality: use host, job and unit; never put user IDs, IPs or request paths in labels.
- Watch disk:
du -sh /var/lib/lokiweekly, and shortenretention_periodif needed. - Drop noise early: a
loki.processstage withstage.dropin Alloy can discard health check lines before they are stored. - Out of order or rate limit errors: read
journalctl -u alloy; raiseingestion_rate_mbinlimits_configfor busy hosts.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Loki and Alloy for central logs
Is Promtail still usable?
Existing installs run, but Promtail has reached end of life and gets no more fixes. Use Grafana Alloy for new servers and convert old configs with alloy convert.
How much disk does Loki need?
It depends on log volume and retention. Measure a day of logs with du -sh /var/lib/loki and multiply by your retention days, with headroom.
Can Loki search full text?
Yes, with line filters such as |= and regular expressions, but it scans the selected streams rather than using a full text index. Narrow by labels first.
Should Loki run on the same server as Grafana?
For a small setup, yes; it keeps traffic on localhost. Split them when log volume needs more RAM or disk.
Where do I see server load at the same time?
Grafana with Prometheus shows inside metrics, and the console Usage graphs tab shows the provider view of the instance.
More in Monitoring and logs
- Netdata real-time monitoring
- Uptime Kuma status page
- Prometheus and node_exporter
- Grafana dashboards
- Zabbix monitoring
- Nagios Core
- Beszel lightweight monitoring
- Cacti graphs with SNMP
- Monit for self-healing services
- btop, htop and other live monitors
- Central logs with rsyslog
- Rotate logs with logrotate
- Read logs with journalctl
- Graylog log management
- Observium network monitoring
- Vector log and metrics pipeline