Prompt
How do I set up a self-hosted log management stack?
Latest observation
A good self-hosted log management stack usually has these parts:
- Log collection agent on each server/container
- Log shipper/forwarder to send logs centrally
- Storage + search/indexing
- Visualization + alerting
- Retention, backups, and access control
Common stack options
Option A: Promtail + Loki + Grafana
Best if you want something simpler and cheaper to run than Elasticsearch.
- Promtail collects logs
- Loki stores and indexes metadata, not full log text
- Grafana searches and visualizes logs
Pros
- Lower resource usage
- Easier to operate
- Great for Kubernetes and Docker
Cons
- Less powerful full-text search than Elasticsearch-style systems
Option B: Filebeat/Fluent Bit + Elasticsearch/OpenSearch + Kibana/OpenSearch Dashboards
Best if you need powerful indexing and search.
- Filebeat or Fluent Bit collects logs
- Elasticsearch or OpenSearch stores and indexes logs
- Kibana or OpenSearch Dashboards provides UI
Pros
- Strong search and analytics
- Mature ecosystem
Cons
- Higher CPU/RAM/storage needs
- More operational overhead
Option C: Vector + ClickHouse + Grafana
Good for high-volume, cost-effective setups.
- Vector collects and transforms logs
- ClickHouse stores them efficiently
- Grafana queries and visualizes
Pros
- Very fast and scalable
- Efficient storage
Cons
- More custom setup
- Less turnkey than the others
Recommended simple setup
If you’re starting out, I’d suggest:
- Docker or Kubernetes logs
- Promtail or Fluent Bit
- Loki
- Grafana
This is usually the easiest self-hosted stack to get running.
Basic setup steps
1. Define your log sources
Decide what you want to collect:
- Linux syslogs
- application logs
- Docker container logs
- Kubernetes pod logs
- firewall/auth logs
2. Deploy the collector
Install an agent on each machine:
- Fluent Bit if you want flexible routing/formatting
- Promtail if using Loki
- Filebeat if using ELK/OpenSearch
Configure it to:
- read from
/var/log/* - read Docker container log files
- parse JSON if your apps emit structured logs
- add labels like host, service, environment, container name
3. Deploy the backend
For Loki
Typical components:
- Loki
- optional object storage (S3, MinIO, or filesystem for small installs)
- Grafana
For OpenSearch/Elasticsearch
Typical components:
- indexer cluster
- dashboard UI
- storage volumes
- ingest pipelines
Make sure to set:
- retention period
- storage limits
- index rotation if applicable
4. Configure dashboards
In Grafana/Kibana/OpenSearch Dashboards:
- create log views by host/service
- build search filters
- create alert rules for errors, high volume, auth failures, etc.
Examples of useful alerts:
- too many
errorlogs in 5 minutes - repeated failed logins
- service crash loops
- disk usage warnings from logs
5. Secure the stack
Important basics:
- Put the UI behind HTTPS
- Use authentication and role-based access
- Restrict network access to the log backend
- Encrypt traffic between agents and backend if possible
- Separate prod vs dev logs
- Avoid storing secrets in logs
6. Set retention and backups
Logs grow quickly. Decide:
- how long to keep raw logs
- whether to archive older logs
- when to compress or delete old data
Typical retention:
- 7–30 days for detailed logs
- longer for audit/security logs
Back up:
- configs
- dashboards
- authentication settings
- metadata/index state, if needed
Example minimal Docker Compose approach
A very simple single-node Loki + Grafana deployment might include:
- Loki container
- Grafana container
- Promtail on each host
- volumes for persistence
If you want, I can provide a working docker-compose.yml for this.
Design tips
- Use structured logging (JSON) in apps
- Normalize fields like
service,env,level,request_id - Keep labels low-cardinality in Loki
- Don’t over-index in Elasticsearch/OpenSearch
- Centralize time sync with NTP
- Plan storage based on log volume, not just current size
How to choose
Choose Loki if:
- you want simplicity
- you’re okay with less powerful text search
- you use Grafana already
Choose OpenSearch/Elasticsearch if:
- you need heavy search/analytics
- you have many users and advanced queries
- you can support higher infrastructure cost
Choose Vector + ClickHouse if:
- you expect large scale
- you want strong performance and lower storage cost
- you’re comfortable with a more custom stack
If you tell me your environment, I can recommend a concrete stack and give you a deployment plan. For example:
- bare metal vs Docker vs Kubernetes
- number of servers
- approximate log volume per day
- whether you want metrics/traces too