Rsyslog过滤

时间:2015-09-21 09:56:42

标签: rsyslog

如何将不同的应用/服务日志消息从一台服务器转发到中央rsyslog服务器?为了澄清 : server1:swift(一体化) 服务器2:rsyslog现在 swift日志位置:/ var / log / swift / all / log(server1) sshd日志位置:/ var / log / secure(server1)

我想将swift和sshd日志存储在server2的不同位置,问题是server2将日志记录在不​​同的位置,但这两个位置都存储来自all.log和安全的日志!我怎么过滤这个?

这是server1(swift)rsyslog.conf

#### MODULES ####

# The imjournal module bellow is now used as a message source instead of imuxsock.
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imjournal # provides access to the systemd journal
#$ModLoad imklog # reads kernel messages (the same are read from journald)
#$ModLoad immark  # provides --MARK-- message capability

# Provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514

# Provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514


#swift log forward to remote rsyslog server
$ModLoad imfile
$InputFileName /var/log/swift/all.log
$InputFileTag swift-log
$InputFileStateFile swift-log
$InputFileSeverity info
$InputFileFacility local7
$InputRunFileMonitor
local7.*                  @rsyslog.labtest.com

#sshd log forward to remote rsyslog server
$ModLoad imfile
$InputFileName /var/log/secure
$InputFileTag sshd
$InputFileStateFile var-log-secure
$InputFileSeverity info
$InputFileFacility local7
$InputRunFileMonitor

# Send over TCP
# local7.*                                @@rsyslog.labtest.com
# # Send over UDP
local7.*                  @rsyslog.labtest.com
#### GLOBAL DIRECTIVES ####

# Where to place auxiliary files
$WorkDirectory /var/lib/rsyslog

# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# File syncing capability is disabled by default. This feature is usually not required,
# not useful and an extreme performance hit
#$ActionFileEnableSync on

# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf

# Turn off message reception via local log socket;
# local messages are retrieved through imjournal now.
$OmitLocalLogging on

# File to store the position in the journal
$IMJournalStateFile imjournal.state


#### RULES ####

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*                                                 /dev/console

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none                /var/log/messages

# The authpriv file has restricted access.
authpriv.*                                              /var/log/secure

# Log all the mail messages in one place.
mail.*                                                  -/var/log/maillog


                                                                                                                                                                                                 38,1          56%

    }

这是server2(rsyslog)rsyslog.conf

# rsyslog configuration file

# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html

#### MODULES ####

# The imjournal module bellow is now used as a message source instead of imuxsock.
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imjournal # provides access to the systemd journal
#$ModLoad imklog # reads kernel messages (the same are read from journald)
#$ModLoad immark  # provides --MARK-- message capability

# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514


#### GLOBAL DIRECTIVES ####

# Where to place auxiliary files
$WorkDirectory /var/lib/rsyslog

# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# File syncing capability is disabled by default. This feature is usually not required,
# not useful and an extreme performance hit
#$ActionFileEnableSync on

# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf

# Turn off message reception via local log socket;
# local messages are retrieved through imjournal now.
$OmitLocalLogging on

# File to store the position in the journal
$IMJournalStateFile imjournal.state

#### RULES ####

#:fromhost, isequal, "swift.labtest.com" /var/log/swift.log
#:fromhost, isequal, "swift.labtest.com" ~ 



# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*                                                 /dev/console

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none                /var/log/messages

# The authpriv file has restricted access.
authpriv.*                                              /var/log/secure

# Log all the mail messages in one place.
mail.*                                                  -/var/log/maillog


# Log cron stuff
cron.*                                                  /var/log/cron

# Everybody gets emergency messages
*.emerg                                                 :omusrmsg:*

# Save news errors of level crit and higher in a special file.
uucp,news.crit                                          /var/log/spooler

# Save boot messages also to boot.log
local7.*                                                /var/log/boot.log

# ### begin forwarding rule ###
# The statement between the begin ... end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
#$ActionQueueMaxDiskSpace 1g   # 1gb space limit (use as much as possible)
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
#$ActionQueueType LinkedList   # run asynchronously
#$ActionResumeRetryCount -1    # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514
# ### end of the forwarding rule ###
#
#
$template Swift, "/var/log/swift/swift.log"
local7.*                                -?Swift

$template sshd, "/var/log/sshd/sshd.log"
local7.*                                -?sshd

1 个答案:

答案 0 :(得分:1)

当您通过imfile从文件中读取消息时,您可以分配标记(分别为swift-log和sshd)。您可以在接收服务器上使用这些标记进行过滤。类似的东西:

if $syslogtag == "sshd" then {
  action(type="omfile" file="/var/log/secure"
} else if $syslogtag == "swift-log" then {
  action(type="omfile" file="/var/log/swift
}

或者,您也可以更改imfile配置,以便为有尾文件(例如local6和local7)分配不同的工具。然后你可以使用BSD风格的配置进行过滤,如:

local6.* /var/log/secure # assuming local6 is assigned to sshd logs
local7.* /var/log/swift  # and local7 for swift logs

您可以在此处找到可以使用的属性列表:http://www.rsyslog.com/doc/master/configuration/properties.html

有关在此处使用条件和其他技巧的信息:http://www.rsyslog.com/doc/master/rainerscript/index.html

虽然对于某些事情你可能需要升级到最新版本的rsyslog(例如8.13是最新的,但许多发行版仍然带有5.x)。您可以在此处找到热门发行版的软件包:http://www.rsyslog.com/downloads/download-other/