在 RHEL6 上使用新的 rsyslog 模板语法时出错

Bar*_*t B 8 rsyslog rhel6

我正在将我们的 rsyslog 配置从旧服务器迁移到新服务器,并认为我会利用这个机会整理我们的配置。旧配置使用“遗留”模板定义,模板上的 rsyslog 文档建议用新模板语法替换此类定义,这就是我尝试做的。

我根本无法让它工作,而且我在尝试启动 rsyslog 时遇到的错误毫无意义。因此,似乎我从根本上误解了 rsyslog 文档,或者 RHEL6 中包含的 rsyslog 包有些有趣。

这是我要更新的旧模板:

$template secureTemplate,"INSERT INTO var_log_secure (received_at, source_ip, source_hostname, logged_at, severity, service, message, severity_int, syslogtag) VALUES ('%timegenerated:::date-rfc3339%', '%fromhost-ip%', '%hostname%', '%timereported:::date-rfc3339%', '%syslogseverity-text%', '%programname%', '%msg%', '%syslogseverity%', '%syslogtag%')",STDSQL
Run Code Online (Sandbox Code Playgroud)

这是我在阅读 rsyslog 文档后尝试使用新语法中的相同模板:

template(name="secureTemplate" type="string" option.stdsql="on"
  string="INSERT INTO var_log_secure (received_at, source_ip, source_hostname, logged_at, severity, service, message, severity_int, syslogtag) values ('%timegenerated:::date-rfc3339%', '%fromhost-ip%', '%hostname%', '%timereported:::date-rfc3339%', '%syslogseverity-text%', '%programname%', '%msg%', '%syslogseverity%', '%syslogtag%')"
)
Run Code Online (Sandbox Code Playgroud)

这些是我在 rsyslog 启动时遇到的错误:

rsyslogd: [origin software="rsyslogd" swVersion="5.8.10" x-pid="4491" x-info="http://www.rsyslog.com"] start
 rsyslogd-3000:unknown priority name "stdsql="on"" [try http://www.rsyslog.com/e/3000 ]
 rsyslogd:the last error occured in /etc/rsyslog.conf, line 49:"template(name="secureTemplate" type="string" option.stdsql="on""
 rsyslogd:warning: selector line without actions will be discarded
 rsyslogd-3000:unknown priority name "" [try http://www.rsyslog.com/e/3000 ]
 rsyslogd:the last error occured in /etc/rsyslog.conf, line 50:"  string="INSERT INTO var_log_secure (received_at, source_ip, source_hostname, logged_at, severity, service, message, severity_int, syslogtag) values ('%timegenerated:::date-rfc3339%', '%fromhost-ip%', '%hostname%', '%timereported:::date-rfc3339%', '%syslogseverity-text%', '%programname%', '%msg%', '%syslogseverity%', '%syslogtag%')""
 rsyslogd:warning: selector line without actions will be discarded
 rsyslogd-3000:unknown priority name "" [try http://www.rsyslog.com/e/3000 ]
 rsyslogd:the last error occured in /etc/rsyslog.conf, line 51:")"
 rsyslogd:warning: selector line without actions will be discarded
 rsyslogd-3003: Could not find template 'secureTemplate' - action disabled
 [try http://www.rsyslog.com/e/3003 ]
 rsyslogd:the last error occured in /etc/rsyslog.conf, line 55:"then    :ompgsql:127.0.0.1,rsyslog,rsyslog,+Without-Goodbye-22+;secureTemplate"
 rsyslogd:warning: selector line without actions will be discarded
 rsyslogd-2124:CONFIG ERROR: could not interpret master config file '/etc/rsyslog.conf'. [try http://www.rsyslog.com/e/2124 ]
 rsyslogd:EMERGENCY CONFIGURATION ACTIVATED - fix rsyslog config file!
Run Code Online (Sandbox Code Playgroud)

小智 8

嗯,答案很简单(而且可能并不令人满意)。此旧版本不支持新语法。您至少需要 v6,但要使用所有功能需要 v7。到目前为止,Red Hat 没有为 RHEL 提供这些。作为替代方案,您可以使用 rsyslog rpm 包:http ://www.rsyslog.com/rhelcentos-rpms/

另请注意,http : //www.rsyslog.com/doc 上的文档始终适用于最新版本。但是,每个版本都有自己的文档集。参考您的版本随附的文档集显然更好。大多数发行版默认不安装它,但通常有一个以 rsyslog-doc 命名的包。


Dan*_*tts 7

截至 2015 年 9 月,RHEL6 中提供了 rsyslog7 软件包。rsyslog 的当前版本是 8.11,但这个版本至少更接近当前版本。

要安装,首先必须删除 rsyslog 包:

# rpm -e --nodeps rsyslog
# yum -y install rsyslog7
Run Code Online (Sandbox Code Playgroud)