Apache 管道日志到 netcat 失败

ETL*_*ETL 5 netcat apache-2.2 graylog

我想以自定义格式 (GELF) 将我的 Apache 日志发送到 UDP 接收服务器(运行 Graylog2)。我确信一切正常,但过了一会儿,我收到警报,我的服务器没有响应。我在 Apache 错误日志中看到了一大堆:

piped log program 'nc -w 1 -u logserver 12201' failed unexpectedly
Run Code Online (Sandbox Code Playgroud)

有趣的是,在流量非常小的服务器上,即使网站没有流量,我也会在日志中不断看到此错误。当有流量时,日志确实会由 netcat 发送到 graylog - 所以无论如何它都可以工作。

如果我停止 Apache 并重新启动它,则重新启动后错误会继续显示在错误日志中。在停止它之后,我确保没有剩余的失控进程。

配置是:

LogFormat "{ \"version\": \"1.1\", \"host\": \"%V\", \"short_message\": \"%r\", \"full_message\": \"%r, status: %>s, %O bytes, User Agent: %{User-Agent}i\", \"timestamp\": %{%s}t, \"level\": 6, \"_user_agent\": \"%{User-Agent}i\", \"_source_ip\": \"%a\", \"_duration_usec\": %D, \"_duration_sec\": %T, \"_request_size_byte\": %O, \"_http_status\": %s, \"_http_request_path\": \"%U\", \"_http_request\": \"%U%q\", \"_http_method\": \"%m\", \"_http_referer\": \"%{Referer}i\" }" graylog2_access
Run Code Online (Sandbox Code Playgroud)

和自定义日志:

CustomLog "|nc -w 1 -u logserver 12201" graylog2_access
Run Code Online (Sandbox Code Playgroud)

我不确定如何获得更多关于失败的调试信息。

  1. 有人可以帮助我获得有关失败的更详细信息吗?
  2. 如果有人知道为什么会失败,那么这也将是一个很好的答案!
  3. 另一种不断(实时)传送日志的方法也是一个可以接受的解决方案。但是,我知道 logstash 但在这种情况下,我不需要解析,我已经可以以 GELF 格式输出。我过去也尝试过logstash,但它最终总是内存不足并自行停止。

Sla*_*ast 5

Apache 文档:http : //httpd.apache.org/docs/2.2/logs.html#piped

Apache 将在服务器启动时启动管道日志进程,如果在服务器运行时崩溃,则将重新启动它。(这最后一个特性就是为什么我们可以将这种技术称为“可靠的管道日志记录”。)

NC文档: man nc

 -w timeout
         Connections which cannot be established or are idle timeout
         after timeout seconds.  The -w flag has no effect on the -l
         option, i.e. nc will listen forever for a connection, with
         or without the -w flag.  The default is no timeout.
Run Code Online (Sandbox Code Playgroud)

您所看到的是 Apache 以 1 秒的超时时间启动 netcat。无论是否有任何日志数据,netcat 都会在一秒后超时(由于 -w 1 选项)并退出。Apache 然后重新启动 netcat。起泡,冲洗,重复。

-w 1在这种情况下,我建议从 netcat 命令中删除。

退一步说,我建议将 syslog 用于此功能(不知道您为什么不首先使用它)。