The ELK stack — Elasticsearch, Logstash, Kibana, plus a shipper from the Beats family — is the search-heavy alternative to Loki for centralized logs. It indexes everything, which means fast full-text search and slice-and-dice analytics in Kibana, at the cost of larger storage and a heavier operational footprint. This article walks through a single-host install that is sane enough to leave running: index lifecycle policy, a Filebeat shipper with the right module, a Kibana data view, and the heap and disk settings that prevent the cluster from yellow-and-then-red after a week.
How to verify
After the install, every check below should return a clean response.
curl -fsS http://127.0.0.1:9200/_cluster/health?pretty
curl -fsS http://127.0.0.1:9200/_cat/nodes?v
curl -fsS http://127.0.0.1:9200/_cat/indices?v | head -20
curl -fsS http://127.0.0.1:9200/_ilm/policy/logs-default?pretty
curl -sI http://127.0.0.1:5601/api/status | head -5
sudo systemctl status filebeat --no-pager
sudo filebeat test output
cluster_health returns green for a healthy single-node cluster; yellow is normal too because index defaults expect a second node for replica shards. red means a primary shard is unassigned — usually disk hit the 95% flood-stage watermark.
What’s happening
Elasticsearch is a distributed search engine. Documents — logs, in this case — are written to indices, broken into shards, and stored on disk as Lucene segments. Every field in every document is indexed by default, which is what makes Kibana fast and the disk footprint large. Logstash is the heavy-weight ingest pipeline (Java, parsing/enrichment/transformation); Beats are lightweight shippers (Go, lower overhead) that can either push directly to Elasticsearch or stop at Logstash for additional processing. Kibana is the UI.
The two settings that matter on day one. Heap — Elasticsearch’s JVM heap should be set to half of physical RAM, capped at 30–31 GB. Anything past that disables compressed object pointers and the heap actually performs worse. Disk watermarks — Elasticsearch starts moving shards off a node at 85% disk used, blocks writes at 95%. A single-node cluster cannot move shards anywhere, so 95% means the cluster goes read-only until you free disk. Index lifecycle management (ILM) is what prevents that.
The procedure
-
Install Elasticsearch and Kibana from the official APT repo.
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elastic.gpg echo "deb [signed-by=/usr/share/keyrings/elastic.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | \ sudo tee /etc/apt/sources.list.d/elastic-8.x.list sudo apt update sudo apt install -y elasticsearch kibanaThe Elasticsearch installer prints a generated
elasticsuperuser password and a Kibana enrollment token — copy both before you lose the terminal. -
Tune the heap and the network bind. Heap goes into a jvm.options.d drop-in so package upgrades do not overwrite it.
sudo tee /etc/elasticsearch/jvm.options.d/heap.options <<EOF -Xms8g -Xmx8g EOF# /etc/elasticsearch/elasticsearch.yml cluster.name: logs-prod node.name: es-01 network.host: 127.0.0.1 http.port: 9200 discovery.type: single-node cluster.routing.allocation.disk.watermark.low: 85% cluster.routing.allocation.disk.watermark.high: 90% cluster.routing.allocation.disk.watermark.flood_stage: 95%sudo systemctl enable --now elasticsearch -
Configure Kibana to talk to it. Reverse-proxy via Nginx if anyone outside the host will reach it.
# /etc/kibana/kibana.yml server.host: '127.0.0.1' server.port: 5601 elasticsearch.hosts: ['http://127.0.0.1:9200'] elasticsearch.username: 'kibana_system' elasticsearch.password: '<from-elasticsearch-reset-password>'sudo /usr/share/elasticsearch/bin/elasticsearch-reset-password -u kibana_systemgenerates the kibana_system password. Thensudo systemctl enable --now kibana. -
Create an ILM policy and an index template before any data lands. Without ILM, indices grow forever and the cluster goes red the first time disk hits 95%.
curl -X PUT -u elastic:$ELASTIC_PWD -H 'Content-Type: application/json' \ http://127.0.0.1:9200/_ilm/policy/logs-default -d '{ "policy": { "phases": { "hot": { "actions": { "rollover": { "max_age": "1d", "max_primary_shard_size": "50gb" } } }, "warm": { "min_age": "2d", "actions": { "shrink": { "number_of_shards": 1 }, "forcemerge": { "max_num_segments": 1 } } }, "delete": { "min_age": "30d", "actions": { "delete": {} } } } } }' curl -X PUT -u elastic:$ELASTIC_PWD -H 'Content-Type: application/json' \ http://127.0.0.1:9200/_index_template/logs-app -d '{ "index_patterns": ["logs-app-*"], "data_stream": {}, "template": { "settings": { "number_of_shards": 1, "number_of_replicas": 0, "index.lifecycle.name": "logs-default", "index.refresh_interval": "5s" } } }'number_of_replicas: 0is the single-node concession — set it to1once you add a second node. -
Install Filebeat on each application host and ship to Elasticsearch (or via Logstash). Filebeat has modules for common services — nginx, postgresql, system — that handle the parsing.
sudo apt install -y filebeat sudo filebeat modules enable system nginx sudo filebeat setup --pipelines --modules system,nginx \ -E "output.elasticsearch.hosts=['http://es.internal:9200']" \ -E "output.elasticsearch.username=filebeat_writer" \ -E "output.elasticsearch.password=$FILEBEAT_PWD"# /etc/filebeat/filebeat.yml filebeat.config.modules: path: ${path.config}/modules.d/*.yml reload.enabled: true output.elasticsearch: hosts: ['http://es.internal:9200'] username: 'filebeat_writer' password: '${FILEBEAT_PWD}' index: 'logs-app-%{[event.module]}-%{+yyyy.MM.dd}' processors: - add_host_metadata: { when.not.contains.tags: forwarded } - add_cloud_metadata: ~ - drop_fields: { fields: ['agent.ephemeral_id'] } -
Create a Kibana data view. In Kibana, Stack Management → Data Views →
logs-app-*with@timestampas the time field. Discover then shows everything Filebeat ships.
Operational notes
- Watch
_cat/nodesheap usage; sustained above 75% means the heap is undersized for the index rate. - ILM rollover only triggers on writes; an idle index sits in the hot phase. For low-volume indices set a shorter
max_age. number_of_replicas: 0on production indices is acceptable only as long as the host runs alone — adding a second node and forgetting to bump replicas leaves you with no fault tolerance.- Beats authentication uses dedicated service users (
filebeat_writerhere) created via the security API; never reuse theelasticsuperuser. - Snapshot to S3 (or a shared filesystem) on a schedule, and test the restore — the snapshot button is the only thing standing between you and a re-shipping operation when the disk dies.
For an alternative that trades search depth for cheaper storage, see loki-log-aggregation-intro.
Stack Harbor runs ELK clusters this way for clients on the managed operations tier — heap, watermarks, and ILM tied to the disk and retention budget you actually have, with snapshots tested on a quarterly drill.