如何让 rsyslog 将日志文件发送到 /var/log 之外的位置?

如何让 rsyslog 将日志文件发送到 /var/log 之外的位置?

我有一个中央系统日志服务器(ubuntu 14.04 服务器),我将其设置为从许多服务器获取日志。

该服务器有一个非常大的存储硬盘,安装在/home/username/logs

我想将 rsyslog 日志发送到该位置,每个服务器都有不同的目录。

现在,我已经完成了所有工作,只是它只会将文件存储在 /var/log 目录中。

我的/etc/rsyslog.conf设置允许根据 IP 来存储来自不同服务器的日志文件

/etc/rsyslog.conf

#  /etc/rsyslog.conf    Configuration file for rsyslog.
#
#                       For more information see
#                       /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
#
#  Default logging rules can be found in /etc/rsyslog.d/50-default.conf


#################
#### MODULES ####
#################

$ModLoad imuxsock # provides support for local system logging
$ModLoad imklog   # provides kernel logging support
#$ModLoad immark  # provides --MARK-- message capability

# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

# provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514

# This one is the template to generate the log filename dynamically, depending on the client's IP address.
$template FILENAME,"/var/log/%fromhost-ip%/syslog.log"

# Log all messages to the dynamically formed file. Now each clients log (192.168.1.2, 192.168.1.3,etc...), will be under a separate directory which is formed by the template FILENAME.
*.* ?FILENAME

# Enable non-kernel facility klog messages
$KLogPermitNonKernelFacility on

###########################
#### GLOBAL DIRECTIVES ####
###########################

#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# Filter duplicated messages
$RepeatedMsgReduction on

#
# Set the default permissions for all log files.
#
$FileOwner syslog
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
$PrivDropToUser syslog
$PrivDropToGroup syslog

#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog
#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf

下面几行具体是我想要的

# This one is the template to generate the log filename dynamically, depending on the client's IP address.
$template FILENAME,"/var/log/%fromhost-ip%/syslog.log"

# Log all messages to the dynamically formed file. Now each clients log (192.168.1.2, 192.168.1.3,etc...), will be under a separate directory which is formed by the template FILENAME.
*.* ?FILENAME

但我不想有$template FILENAME,"var/log/....",我希望它类似于$template FILENAME,"/home/username/logs/ "

是什么阻止我将目录更改为 /var/log 之外的目录,我该如何解决这个问题?

我知道我可能可以将该驱动器安装在 /var/log 下的某个地方,但我现在很好奇。

答案1

当我创建要存储 syslog 数据的目录时,我以 root 身份运行该命令。一旦我将所有者更改为 syslog,一切就都正常了。

呃,由于权限问题而创建 SE 问题很尴尬。

相关内容