如何配置rsyslog以将日志从特定程序发送到远程syslog服务器?
我有一个程序,它输出到syslog与给定的标签/程序名称。 我希望能够从该程序中过滤syslog流量并将其发送到远程syslog服务器,将所有其他syslog流量留在本地。
我可以将所有流量发送到远程服务器
*.* @remote_server
我该如何过滤它?
Rsyslog配置文件位于: /etc/rsyslog.d/*.conf
conf
Rsyslog按顺序读取conf文件,因此请务必命名配置文件,以便在发生任何其他情况之前加载特定的配置。 因此,从前导零开始命名文件,即00-my-file.conf
。 最好创建一个新文件,以便更新等不会覆盖您的本地配置。
例:
if $programname == 'programname' and $msg contains 'a text string' and $syslogseverity <= '6' then /var/log/custom/bind.log
或者,如果您只想丢弃某些条目:
if $programname == 'programname' then ~
在你的情况下:(UDP)
if $programname == 'programname' then @remote.syslog.server & ~
或(TCP)
if $programname == 'programname' then @@remote.syslog.server & ~
& ~
表示进一步停止处理匹配(仅限前一行!)条目。
一些更一般的信息:
此外,始终确保filter位于同一行:
# Example: Log mail server control messages to mail-queue.log if $hostname == 'titus'\ and $programname == 'smtp.queue.'\ and $syslogseverity <= '6' then /var/log/titus/mail-queue.log & ~
有用的filter:
$hostname $programname $msg $syslogseverity
运营商:
== (equals) contains and or
更多信息: http : //wiki.rsyslog.com/index.php/Configuration_Samples