Sub topic 17
Where to go next: log shippers and search backends
This chapter assumes you have built the rsyslog pipeline from the earlier chapters. That means clients forward over TCP, a central receiver writes per-host files, logrotate expires them, and you can test the whole thing with logger. It also assumes you are comfortable with systemd units and basic networking. Here you learn what that pipeline does not do, and which tools cover the gaps.
What the rsyslog pipeline gives you
Your central host now holds a complete copy of every server's logs. The files sit under /var/log/remote/<host>/<program>.log. You can search them with grep, zgrep and tail, and rotation keeps them within a known size.
This is a good base. It is simple, it uses tools already installed on most distributions, and there is little to break. For a handful of servers it may be all you need.
It starts to hurt in four places:
- Searching across hosts. Finding every failed login in the last hour on forty hosts means a
grepover many files, with no index. - Structure. Plain lines are text. To ask "how many 500 responses per minute" you must parse each line again for every query.
- Alerting. Files do not notify anyone. You need another process that reads them and reacts.
- Multi-line and non-syslog sources. A Java stack trace is one event but many lines. Container output, application JSON and cloud audit logs do not always arrive via syslog.
A log shipper and a search backend address these. They are two separate roles, and it helps to keep them apart.
The two roles
A log shipper is an agent that reads logs at the source, optionally parses or enriches them, and sends them somewhere. A search backend stores events in an index so you can query them quickly and build dashboards or alerts on them.
The diagram shows where each sits relative to what you already built.
Two paths reach the backend. The shipper can read sources directly on each server. Or rsyslog itself can forward from the central host to the backend. Both are valid, and the choice is covered below.
Common shippers
All of these can read files and the journal. They differ in weight and in how much processing they do.
| Tool | Typical role | Notes |
|---|---|---|
| rsyslog (with `omelasticsearch`, `omkafka`) | Forward from the central host or clients | You already run it. Output modules may need extra packages. |
| Fluent Bit | Lightweight agent on each server | Small memory use. Good for containers and Kubernetes. |
| Fluentd | Aggregator with many plugins | Heavier. Often runs centrally and receives from Fluent Bit. |
| Filebeat / Elastic Agent | Agent for the Elastic stack | Tails files, handles multi-line events, tracks read position. |
| Vector | Agent and aggregator in one binary | Has a transform language for parsing and routing. |
| Promtail / Grafana Alloy | Agent for Grafana Loki | Labels streams and tails files or the journal. |
Versions and package names change often, so check each project's documentation before you install.
Common search backends
| Backend | Indexing model | Good fit |
|---|---|---|
| Elasticsearch / OpenSearch | Full-text index of every field | Free-form search, rich queries, large analytic workloads. |
| Grafana Loki | Indexes only labels, stores log text in compressed chunks | Lower storage cost, works well if you query by host and service first. |
| Graylog | Server application on top of OpenSearch | Streams, alert rules and user management included. |
| Hosted services | Vendor-run | Less to operate, but you pay per volume and send data off site. |
The main trade-off is indexing cost. Full-text indexing makes any search fast but needs a lot of disk and memory. Label-only indexing is cheaper but slow for searches that do not narrow by label first.
Choosing a path
Decide with a few questions.
- How many hosts and how much volume? Under roughly a few dozen hosts with modest volume, the files plus
grepmay remain enough. - Do you need alerts or dashboards? If yes, you need a backend.
- Do you have people to run it? Elasticsearch clusters need capacity planning, upgrades and shard management. A hosted service moves that work to a vendor.
- Are there compliance rules? Retention length, tamper resistance and data location may rule out some options.
A practical path is incremental. Keep the rsyslog central store as the durable raw archive. Add a backend beside it for search. If the backend breaks or fills up, the raw files remain.
Reusing what you built
You do not have to discard the rsyslog work. Three patterns reuse it.
Forward from the central host
The central receiver can send to a second destination. This keeps client configuration unchanged. Only one machine talks to the backend.
# /etc/rsyslog.d/60-to-backend.conf on the central server
module(load="omfwd")
ruleset(name="remote") {
action(type="omfile" dynaFile="PerHostFile")
action(type="omfwd"
target="backend.example.com" port="6514" protocol="tcp"
queue.type="LinkedList"
queue.filename="backend_queue"
queue.maxDiskSpace="1g"
queue.saveOnShutdown="on"
action.resumeRetryCount="-1")
}This assumes the ruleset named remote from the receiver chapter. If you already have that ruleset in 10-receiver.conf, add the second action there and do not define the ruleset twice. Rsyslog reports a duplicate definition as an error, so run rsyslogd -N1 before restarting.
Both actions run for each message. The queue on the second action means a backend outage does not block writing to files.
Ship the journal and files from each host
Run an agent on every server when you need structured fields, multi-line handling or file sources that never touch syslog. The agent keeps its own read position, so it resumes after restarts. Check how it behaves with the logrotate settings you wrote. An agent that follows files by name or by inode needs to cope with rotation. Most do, but verify with a forced rotation (logrotate -f) and watch for missing or duplicated events.
Use structured output
Rsyslog can emit JSON through templates. Sending JSON lets the backend index fields without a parsing step. Plain syslog lines need a parser, such as a grok pattern or regular expression, and those break when message formats change.
Gotchas when adding a backend
- Do not remove rotation. An indexed copy does not replace the raw files on the central host. Disk still fills if logrotate stops.
- Plan retention in two places. The backend has its own retention, such as index lifecycle policies. Align it with the file retention, or decide which copy is authoritative.
- Mind duplicates. If both a shipper and rsyslog send the same file to the backend, each event is indexed twice. Pick one path per source.
- Protect the transport. The TLS lessons apply here too. Use encrypted connections and authentication to the backend, since logs often contain usernames, addresses and tokens by accident.
- Watch backpressure. When the backend slows down, agents buffer. Without a bounded queue they may use unbounded memory or drop events. Set limits as you did with
queue.maxDiskSpace. - Keep clocks aligned. Searches by time range rely on the time sync work from earlier. Skewed clocks scatter events across the wrong minutes.
A suggested learning order
- Pick one backend and install it on a test machine, not production.
- Forward the central host's messages to it using the rsyslog pattern above.
- Build one search and one alert, for example repeated SSH failures.
- Only then evaluate agents on clients, based on which gaps you actually hit.
Exercise
Your central rsyslog host writes per-host files and rotates them for 30 days. You add a search backend that keeps indexes for 7 days. A colleague proposes deleting the file rotation setup because "the backend has everything". Give two reasons this is a mistake, and name one way to avoid indexing events twice.
Show answer
First, the backend keeps data for only 7 days, so deleting the files loses the 8 to 30 day history, and the files also act as the raw archive if the backend fails or an index must be rebuilt. Second, rotation is what stops the central disk from filling, so removing logrotate while files are still being written leads to a full disk even if nobody reads them. To avoid duplicates, send each source along a single path to the backend: either the shipper reads the file directly, or rsyslog forwards it, but not both.
Exercise
A label-indexed backend like Loki is cheaper to run than a full-text one. Describe one search that will be fast and one that will be slow, and say why.
Show answer
A search that names a host and service label and a short time range is fast, because the labels select a small set of chunks to read. A search for a specific string across all hosts and all time with no label filter is slow, because the backend must decompress and scan the text of many chunks, as it has no full-text index to look up.