【问题标题】:Nginx logging to remote rsyslogNginx 记录到远程 rsyslog
【发布时间】:2016-04-08 11:47:09
【问题描述】:

由于 nginx 1.7+ 支持syslog,我尝试将所有 nginx 节点日志聚合到远程 rsyslog 服务器上。我用

设置了nginx.conf
error_log syslog:server=[REMOTE_HOST]:514,tag=nginx;
access_log syslog:server=[REMOTE_HOST]:514,tag=nginx;

在远程 rsyslog 服务器上,我设置了一个配置文件

local7.debug            /var/log/nginx/access.log; RemoteFormat
local7.debug            /var/log/nginx/error.log; RemoteFormat

但仍然无法获取日志,如何在远程 rsyslog 服务器上将所有 nginx access.logerror.log 聚合到单独的文件 access.logerror.log 上?先感谢您。

【问题讨论】:

    标签: logging nginx rsyslog


    【解决方案1】:

    我认为你应该使用if 条件。见example in doc

    if 参数 (1.7.0) 启用条件日志记录。如果条件评估为“0”或空字符串,则不会记录请求。在以下示例中,将不会记录响应代码为 2xx 和 3xx 的请求:

    map $status $loggable {
        ~^[23]  0;
        default 1;
    }
    
    access_log /path/to/access.log combined if=$loggable;
    

    我的想法:如果消息是loggable(你可以重写这个map)标签将nginx-access,如果不是loggable,标签将nginx-error。现在您可以通过tag 使用rsyslog 过滤它。

    但如果你只想分离访问和错误日​​志,你可以使用不同的标签:

    access_log ... tag=nginx-access;
    error_log ... tag=nginx-error;
    

    另一种解决方案:使用severity

    【讨论】:

    • 谢谢回复,我会用severity代替,对于远程rsyslog服务器端,如何配置将接收到的access.log和error.log分开?提前谢谢你。
    • wiki.gentoo.org/wiki/Rsyslog#Severity 所以我认为local7.debug(调试严重性)和local7.info(信息严重性)是正确的。
    猜你喜欢
    • 2017-11-06
    • 2016-01-07
    • 2015-03-25
    • 2017-05-19
    • 2017-07-14
    • 2019-03-05
    • 1970-01-01
    • 2018-06-29
    • 2013-04-25
    相关资源
    最近更新 更多