我想把我的Apache日志以自定义格式(GELF)发送到UDP接收服务器(运行Graylog2)。 我确信一切正常,但过了一会儿,我得到了一个警告,我的服务器没有响应。 我在Apache错误日志中看到一大堆:
piped log program 'nc -w 1 -u logserver 12201' failed unexpectedly
有趣的是,在stream量非常小的服务器上,即使没有网站stream量,我也会在日志中不断看到这个错误。 而当有交通,日志确实发送netcat到graylog – 所以它确实工作。
如果我停止Apache并重新启动它,重新启动后,错误日志中将继续显示错误。 停下来之后,我确定没有失控的进程。
configuration是:
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
和CustomLog:
CustomLog "|nc -w 1 -u logserver 12201" graylog2_access
我不知道如何得到更多的debugging信息,以什么失败。
Apache文档: http : //httpd.apache.org/docs/2.2/logs.html#piped
Apache将在服务器启动时启动pipe道日志进程,并在服务器运行时崩溃的情况下重新启动。 (这最后一个特点就是为什么我们可以将这种技术称为“可靠的pipe道日志”)。
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, ie nc will listen forever for a connection, with or without the -w flag. The default is no timeout.
你看到的是Apache启动netcat的超时时间为1秒。 不pipe有没有日志数据,netcat会在一秒后超时(由于-w 1选项)并退出。 然后Apache重新启动netcat。 泡,冲洗,重复。
我build议在这种情况下从netcat命令中删除-w 1 。
退后一步,我会build议使用这个函数的系统日志(不知道为什么你没有与它在第一个地方)。