Systemd can collect and store logs, but it doesn’t have a built-in method of logging to remote locations such as log management systems. Instead, it relies on the device’s syslog service to relay messages between journald and a remote syslog server.
However, syslog is text-based and the journald uses a binary format,
so your logs need to be converted before they can be transferred. You
can do this by using either systemd’s ForwardToSyslog configuration
setting, or by using rsyslog’s imjournal module.
/etc/systemd/journald.conf has a ForwardToSyslog=yes
option that would allow you to forward the logs to syslog, which seems like a pretty inelegant way to me.
In rsyslog you can add the module imjournal
, to get the journal logs. To use it, add the following to your /etc/rsyslog.conf file. The mmjsonparse module lets ryslog parse journald messages:
module(load="imjournal")
module(load="mmjsonparse")
Kernel messages can be logged with the standard the imklog
module. Just add: module(load="imklog")
to the configuration file /etc/rsyslog.conf. With the standard rsyslog configuration, this should log kernel messages to /var/log/messages and /var/log/syslog.
The forwarding can be done over UDP or TCP.
Forwarding:
*.* action(type="omfwd" target="10.0.2.1" port="514" protocol="udp") # UDP
*.* action(type="omfwd" target="10.0.2.1" port="10514" protocol="tcp") # TCP
Obsolote Legacy Format
*.* @10.0.1.1:514 # UDP
*.* @@10.0.1.1:514 # TCP
After adding this (please not in legacy format), your rsyslog client should start forwarding the messages to your remote syslog server.
I only added the legacy format to the answer, because if you'll find a LOT of configurations written like this.