Docker rsyslog 驱动程序在实际消息之前添加消息长度
Docker rsyslog driver add message length before actual message
我正在尝试配置一个 rsyslog 服务器来接收来自 docker 个容器的日志。我目前正在为 运行 一个 docker 容器使用以下突击队:
sudo docker run -d --log-driver=syslog --log-opt syslog-address=udp://localhost:514 --log-opt syslog-format=rfc5424 --log-opt tag="remote:shouldshow" alpine echo "some random message"
我正在使用 rfc5424,因为从 docker 到 rsyslog 的标准日志格式会在冒号字符处中断消息,拆分标记 remote:shouldshow 并将 shouldshow 添加到消息中。
有关此情况的更多信息,请参见:https://github.com/docker/docker/issues/18712
问题是我的日志消息来自 docker 在消息之前有一个额外的三位数,例如以下示例中的 127(来自 rsyslog 的 rawmsg 属性):
127 <30>1 2016-07-12T00:51:13-03:00 vitor-Lenovo-G50-70 docker/remote:shouldshow 2910 docker/remote:shouldshow some random message
当我尝试使用 syslog 属性(如 APP-NAME 或 syslogtag)时,它们的值都为 <30>1。
我已经复制了这条没有 127 的消息,并通过 netcat 将其发送到系统日志服务器,并且正确解析了值,如下所示:
echo '<30>1 2016-07-12T00:15:53-03:00 vitor-Lenovo-G50-70 docker/remote:shouldshow 2910 docker/remote:shouldshow some random message' | nc -u -v localhost 514
有人知道为什么会这样吗?任何帮助将非常感激。提前致谢。
查看 docker 代码,我发现这个三位数就是消息的长度。我仍然面临同样的问题,rsyslog 无法正确解析此消息,包括在实际日志消息之前包含它的长度。
经过一番努力,我已经弄明白了。事实证明,如果您将 Docker 日志驱动程序配置为使用 RFC5424 系统日志格式,Docker 使用一个使用 RFC5425 标准发送系统日志消息的库,该标准定义了通过 TLS 发送系统日志消息的标准方式。 https://www.rfc-editor.org/rfc/rfc5425
因此,如果您将 Docker 日志驱动程序配置为使用 TLS,并将您的 rsyslog 服务器配置为接收加密消息,rsyslog 会正确解析该消息。
我正在尝试配置一个 rsyslog 服务器来接收来自 docker 个容器的日志。我目前正在为 运行 一个 docker 容器使用以下突击队:
sudo docker run -d --log-driver=syslog --log-opt syslog-address=udp://localhost:514 --log-opt syslog-format=rfc5424 --log-opt tag="remote:shouldshow" alpine echo "some random message"
我正在使用 rfc5424,因为从 docker 到 rsyslog 的标准日志格式会在冒号字符处中断消息,拆分标记 remote:shouldshow 并将 shouldshow 添加到消息中。 有关此情况的更多信息,请参见:https://github.com/docker/docker/issues/18712
问题是我的日志消息来自 docker 在消息之前有一个额外的三位数,例如以下示例中的 127(来自 rsyslog 的 rawmsg 属性):
127 <30>1 2016-07-12T00:51:13-03:00 vitor-Lenovo-G50-70 docker/remote:shouldshow 2910 docker/remote:shouldshow some random message
当我尝试使用 syslog 属性(如 APP-NAME 或 syslogtag)时,它们的值都为 <30>1。
我已经复制了这条没有 127 的消息,并通过 netcat 将其发送到系统日志服务器,并且正确解析了值,如下所示:
echo '<30>1 2016-07-12T00:15:53-03:00 vitor-Lenovo-G50-70 docker/remote:shouldshow 2910 docker/remote:shouldshow some random message' | nc -u -v localhost 514
有人知道为什么会这样吗?任何帮助将非常感激。提前致谢。
查看 docker 代码,我发现这个三位数就是消息的长度。我仍然面临同样的问题,rsyslog 无法正确解析此消息,包括在实际日志消息之前包含它的长度。
经过一番努力,我已经弄明白了。事实证明,如果您将 Docker 日志驱动程序配置为使用 RFC5424 系统日志格式,Docker 使用一个使用 RFC5425 标准发送系统日志消息的库,该标准定义了通过 TLS 发送系统日志消息的标准方式。 https://www.rfc-editor.org/rfc/rfc5425
因此,如果您将 Docker 日志驱动程序配置为使用 TLS,并将您的 rsyslog 服务器配置为接收加密消息,rsyslog 会正确解析该消息。