我正在使用带有 rsyslog 和最新软件包的 Ubuntu 20.04。我想记录来自 iptables 的消息。
我可以看到这些消息dmesg
- 它显示了我期望的数据。
deploy$ dmesg -x
kern :warn : [37464969.767649] iptables: Incoming netperf IN=venet0 OUT= MAC= SRC=x.x.x.x DST=y.y.y.y LEN=60 TOS=0x00 PREC=0x00 TTL=51 ID=43720 DF PROTO=TCP SPT=46221 DPT=12865 WINDOW=29200 RES=0x00 SYN URGP=0
kern :warn : [37464969.767679] iptables: Incoming netperf IN=venet0 OUT= MAC= SRC=x.x.x.x DST=y.y.y.y LEN=60 TOS=0x00 PREC=0x00 TTL=51 ID=34689 DF PROTO=TCP SPT=58437 DPT=12865 WINDOW=29200 RES=0x00 SYN URGP=0
但...这些消息永远不会保存在/var/log
目录中的任何日志文件中。
据我所知,我的/etc/rsyslog.conf
(下面)文件与原始文件相比没有变化,默认规则(在/etc/rsyslog.d/50-default.conf
下面)应该导致kern
消息被写入/var/log/kern.log
.唯一的其他文件/etc/rsyslog.d/
是postfix.conf
(下一个)。
文件权限似乎并不令人惊讶......(底部两个报告)
想法?我缺少什么?谢谢。
/etc/rsyslog.conf
# /etc/rsyslog.conf configuration file for rsyslog
#
# For more information install rsyslog-doc and see
# /usr/share/doc/rsyslog-doc/html/configuration/index.html
#
# Default logging rules can be found in /etc/rsyslog.d/50-default.conf
#################
#### MODULES ####
#################
module(load="imuxsock") # provides support for local system logging
#module(load="immark") # provides --MARK-- message capability
# provides UDP syslog reception
#module(load="imudp")
#input(type="imudp" port="514")
# provides TCP syslog reception
#module(load="imtcp")
#input(type="imtcp" port="514")
# provides kernel logging support and enable non-kernel klog messages
#module(load="imklog" permitnonkernelfacility="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
/etc/rsyslog.d/50-default.conf
# Default rules for rsyslog.
#
# For more information see rsyslog.conf(5) and /etc/rsyslog.conf
#
# 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
#
# Some "catch-all" log files.
#
#*.=debug;\
# auth,authpriv.none;\
# news.none;mail.none -/var/log/debug
#*.=info;*.=notice;*.=warn;\
# auth,authpriv.none;\
# cron,daemon.none;\
# mail,news.none -/var/log/messages
#
# 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.
#
#daemon,mail.*;\
# news.=crit;news.=err;news.=notice;\
# *.=debug;*.=info;\
# *.=notice;*.=warn /dev/tty8
/etc/rsyslog.d/postfix.conf
# Create an additional socket in postfix's chroot in order not to break
# mail logging when rsyslog is restarted. If the directory is missing,
# rsyslog will silently skip creating the socket.
$AddUnixListenSocket /var/spool/postfix/dev/log
ls -al /etc/rsys*
deploy:/etc$ ls -al /etc/rsys*
-rw-r--r-- 1 root root 1383 Oct 12 10:43 rsyslog.conf
rsyslog.d:
total 24
drwxr-xr-x 2 root root 4096 Feb 16 08:28 .
drwxr-xr-x 114 root deploy 12288 Feb 15 18:41 ..
-rw-r--r-- 1 root root 1124 Feb 16 07:48 50-default.conf
-rw-r--r-- 1 root root 242 Jun 19 2020 postfix.conf
ls -al /var/log/kern.log
deploy:/etc$ ls -al /var/log/kern.log
-rw-r----- 1 syslog adm 0 Feb 15 18:50 /var/log/kern.log
sudo systemctl status systemd-journald.service
deploy:~$ sudo systemctl status systemd-journald.service
● systemd-journald.service - Journal Service
Loaded: loaded (/lib/systemd/system/systemd-journald.service; static; vendor preset: enabled)
Active: active (running) since Tue 2021-02-16 09:02:16 EST; 45min ago
TriggeredBy: ● systemd-journald.socket
● systemd-journald-audit.socket
● systemd-journald-dev-log.socket
Docs: man:systemd-journald.service(8)
man:journald.conf(5)
Main PID: 179 (systemd-journal)
Status: "Processing requests..."
Tasks: 1 (limit: 38354)
Memory: 52.7M
CGroup: /system.slice/systemd-journald.service
└─179 /lib/systemd/systemd-journald
Jan 31 21:42:14 example.com systemd-journald[35283]: Journal stopped
Jan 31 21:42:21 example.com systemd-journald[180]: Journal started
Jan 31 21:42:21 example.com systemd-journald[180]: Runtime Journal (/run/log/journal/77578ccc822c4f1aaa10385353e145a7) is 2.5M, max 20.4M, 17.9M free.
Jan 31 21:42:22 example.com systemd-journald[180]: Time spent on flushing to /var/log/journal/77578ccc822c4f1aaa10385353e145a7 is 29.543ms for 19 entries.
Jan 31 21:42:22 example.com systemd-journald[180]: System Journal (/var/log/journal/77578ccc822c4f1aaa10385353e145a7) is 32.0M, max 4.0G, 3.9G free.
Feb 16 09:02:10 example.com systemd-journald[180]: Journal stopped
Feb 16 09:02:16 example.com systemd-journald[179]: Journal started
Feb 16 09:02:16 example.com systemd-journald[179]: Runtime Journal (/run/log/journal/77578ccc822c4f1aaa10385353e145a7) is 2.5M, max 20.4M, 17.9M free.
Feb 16 09:02:16 example.com systemd-journald[179]: Time spent on flushing to /var/log/journal/77578ccc822c4f1aaa10385353e145a7 is 54.224ms for 20 entries.
Feb 16 09:02:16 example.com systemd-journald[179]: System Journal (/var/log/journal/77578ccc822c4f1aaa10385353e145a7) is 160.0M, max 4.0G, 3.8G free.
deploy:~$
答案1
更新:现在正在工作。在解决此问题时,我进行了大量更改,但我相信问题在于下面的行被注释掉了/etc/rsyslog.conf
取消注释它会导致日志条目按预期显示。
#module(load="imklog" permitnonkernelfacility="on")
在此过程中,我收集了一些有关 rsyslog 的事实,并将其放在这里供下一个遇到这种麻烦的穷人(包括我)使用:
- iptables总是
kern.*
通过设施发送其日志消息 - rsyslog 配置位于
/etc/rsyslog.conf
;它经常指向单独的文件,/etc/rsyslog.d
为各种日志文件提供附加规则。 module(load="imklog" ...)
(据我所知),需要加载内核日志记录模块。其他设施可能需要其他模块。/etc/rsyslog.d/50-default.conf
有一行用于将kern.*
消息定向到特定的日志文件。- 在 Ubuntu 20.04(至少)上,您需要
sudo service rsyslog restart
在配置更改后使用 rsyslogd -N1
检查 rsyslog 配置中的错误journald
似乎与我遇到的任何问题无关。
我无法验证的事情:这并不意味着它不能按记录工作,只是我可能做错了。
- 我无法使文件
/etc/rsyslog.d/10-iptables.conf
覆盖50-default.conf
目录中的文件(将某些消息定向到单独的文件)。