我应该如何使用systemd处理远程日志记录?

mat*_*tes 9 logging journal systemd docker

我在Google Compute Engine(GCE)上运行多个CoreOS实例.CoreOS使用systemd的日志记录功能.如何将所有日志推送到远程目标?据我所知,systemd日志没有远程日志记录功能.我目前的解决方案看起来像这样:

journalctl -o short -f | ncat <addr> <ip>
Run Code Online (Sandbox Code Playgroud)

使用https://logentries.com 通过TCP使用基于令牌的输入:

journalctl -o short -f | awk '{ print "<token>", $0; fflush(); }' | ncat data.logentries.com 10000
Run Code Online (Sandbox Code Playgroud)

还有更好的方法吗?

编辑: https ://medium.com/coreos-linux-for-massive-server-deployments/defb984185c5

fch*_*che 10

systemd过去版本216包括通过客户端/服务器进程对的远程日志记录功能.

http://www.freedesktop.org/software/systemd/man/systemd-journal-remote.html

  • 您正在寻找的不是“systemd-journal-remote”,而是“systemd-journal-upload”,并且自版本 216 起也可用。 (2认同)
  • 一个是接收器,另一个是发射器。 (2认同)

J.C*_*.C. 6

使用的缺点-o short是格式难以解析; short-iso更好.如果您使用的是ELK堆栈,那么以JSON格式导出会更好.像下面这样的系统服务可以很好地将JSON格式的日志发送到远程主机.

[Unit]
Description=Send Journalctl to Syslog

[Service]
TimeoutStartSec=0
ExecStart=/bin/sh -c '/usr/bin/journalctl -o json -f | /usr/bin/ncat syslog 515'

Restart=always
RestartSec=5s

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

在远端,logstash.conf对我来说包括:

input {
  tcp {
    port  => 1515
    codec => json_lines
    type  => "systemd"
  }
}

filter {
  if [type] == "systemd" {
    mutate { rename => [ "MESSAGE", "message" ] }
    mutate { rename => [ "_SYSTEMD_UNIT", "program" ] }
  }
}
Run Code Online (Sandbox Code Playgroud)

这导致整个journalctl数据结构可供Kibana/Elasticsearch使用.