![rsyslog 服务器还将远程日志保存在 /var/syslog 中](https://linux22.com/image/882238/rsyslog%20%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%BF%98%E5%B0%86%E8%BF%9C%E7%A8%8B%E6%97%A5%E5%BF%97%E4%BF%9D%E5%AD%98%E5%9C%A8%20%2Fvar%2Fsyslog%20%E4%B8%AD.png)
我已将我的 ubuntu 服务器设置为 syslog 服务器,以接受来自路由器的所有日志并将它们保存在 /var/log/ 文件夹中单独的 mikrotik.log 文件中。
一切正常,但我注意到所有消息也被复制到了 /var/syslog 日志文件中。
有什么办法可以阻止这些路由器消息出现在我的 /var/syslog 日志中吗?
以下是我的 syslog 配置文件:
/etc/rsyslog.d/10-mikrotik.conf
$template RouterLog, "/var/log/mikrotik.log"
:fromhost-ip, isequal, "192.168.2.1" -?RouterLog
& stop
/etc/rsyslog.d/50-默认.conf
# Default rules for rsyslog.
#
# First some standard log files. Log by facility.
#
auth,authpriv.* /var/log/auth.log
*.*;auth,authpriv.none -/var/log/syslog
#cron.* /var/log/cron.log
#daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
#lpr.* -/var/log/lpr.log
mail.* -/var/log/mail.log
#user.* -/var/log/user.log
#
# Logging for the mail system. Split it up so that
# it is easy to write scripts to parse these files.
#
#mail.info -/var/log/mail.info
#mail.warn -/var/log/mail.warn
mail.err /var/log/mail.err
#
# Logging for INN news system.
#
news.crit /var/log/news/news.crit
news.err /var/log/news/news.err
news.notice -/var/log/news/news.notice
#
# Emergencies are sent to everybody logged in.
#
*.emerg :omusrmsg:*
#
# I like to have messages displayed on the console, but only on a virtual
# console I usually leave idle.
#
# NOTE: adjust the list below, or you'll go crazy if you have a reasonably
# busy site..
#
daemon.*;mail.*;\
news.err;\
*.=debug;*.=info;\
*.=notice;*.=warn |/dev/xconsole
/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
# 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
答案1
在发布这个问题之前我做了以下更改:
/etc/rsyslog.d/mikrotik.conf
到:
/etc/rsyslog.d/10-mikrotik.conf
它确实解决了我的问题但我现在才发现它。
答案2
尝试在您不重复的规则后立即添加此行。
& ~
例如编辑/etc/rsyslog.d/10-mikrotik.conf
成如下的样子
$template RouterLog, "/var/log/mikrotik.log"
:fromhost-ip, isequal, "192.168.2.1" -?RouterLog
# & stop
& ~
这应该会阻止日志消息的副本继续发送到/var/log/syslog
然后,当然跑service rsyslog restart