Apache错误日志pipe道失败

试图login到一个中央系统日志服务器,直接使用Apache的错误日志pipe道logging器,或获取系统日志转发,但没有任何工作,这些错误对我来说是没有意义的。 我可以让自定义日志工作,但不是ErrorLog。 使用rsyslogd 7.4.4在Ubuntu 14.04上使用Apache / 2.4.7。

在我的虚拟主机configuration(logging器选项后没有空格,没有任何区别):

LogLevel warn ErrorLog "|/usr/bin/tee -a /var/log/apache2/error.log | /usr/bin/logger -tapache_err -plocal1.error" CustomLog "|/usr/bin/logger -p local4.warning -t apache" combined 

然后得到这个错误:

 /usr/bin/tee: invalid option -- 't' 

也试过(有和没有双引号):

 ErrorLog "|syslog:local1" 

但后来得到:

 (2)No such file or directory: AH00089: Couldn't start ErrorLog process 'syslog:local1'. AH00015: Unable to open logs 

甚至尝试过:

 ErrorLog "| /usr/bin/tee -a /var/log/apache2/error.log | nc -u -j xxx.xxx.xxx.xxx 514" 

但是,现在还在抱怨:

 /usr/bin/tee: invalid option -- 'u' 

为什么地球上的第二根pipe子会tee选项,我能做些什么来阻止呢? 我是一个但卡住了,谷歌不是我的朋友,任何其他build议表示赞赏。

第一个pipe道是Apache编写一个新的命令的代码,但是它可能并不是一个全新的shell,它可以让你使用一个新的pipe道,而是执行命令,所有的东西都被当作命令参数,包括新的pipe道等。你可能会绕过它包装成一个壳,使用两种方法,一个是明确的:

 ErrorLog "|/bin/sh -c 'tee ... | logger ...'" 

另一个隐式地使用前缀关键字|$

 ErrorLog "|$tee ... | logger ..." 

根本原因是Apache 2.4的一个变化,参见 http://httpd.apache.org/docs/2.4/upgrading.html

在Unix平台上,使用ErrorLog或CustomLogconfiguration的pipe道日志logging命令是在2.2及更早版本中使用/ bin / sh -c调用的。 在2.4及更高版本中,直接执行pipe道日志命令。 要恢复旧的行为,请参阅pipe道日志logging文档。

find这个post的同时,在Apache 2.2.31中寻找一个涉及清理日志事件的解决scheme,该日志事件还没有ErrorLogFormat 。 这是我提出的解决scheme,并认为其他人会觉得有用。

这使用unbuffered sedErrorLog剥离引用:

 ErrorLog "|/bin/sed -u \'s/,\ referer: .*//\' >> /var/log/httpd/error_log" 

使用内联无缓冲的perl从引用者中删除查询string:

 ErrorLog "|/usr/local/bin/perl -ne \'$|=1;while (<>){$output = $_; $output =~ s/(referer:\ .*)\?/$1/; print $output}\'>>/var/log/httpd/error_log 

调用perl脚本:

 ErrorLog "|/usr/local/bin/perl /tmp/fuss.pl >> /var/log/httpd/error_log