#### 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 # 如果需要将rsyslog配置成服务,需要打开udp或tcp的模块加载与监听端口,也可以全部打开。 #### 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 locallog 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 # 所有facility的info级别,但不包括mail;authpriv;cron,因为这三个facility的级别是none # 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:* # :omusrmsg:*表示将所有emerg级别的日志通知给所有登录用户 # Save news errors of level crit and higher in a special file. uucp,news.crit /var/log/spooler # 这表示uucp.crit和news.crit,因为都是crit级别,所以前面将facility写在一起用逗号分隔 # Save boot messages also to boot.log local7.* /var/log/boot.log # 配置文件共分为三段,第一段MODULES是加载模块的, 第二段GLOBAL DIRECTIVES是全局配置,第三段RULES是针对具体的设置与级别将日志保存到哪里。 # 第三段RULES的配置格式为: # facility.priority target # # 其中facility表示设施,是日志生成器,或叫日志收集管道,它从功能或程序上对日志进行分类,包括: # auth, authpriv, cron, daemon, kern, lpr, mail, mark, news, security, user, uucp, # local0-local7, syslog。 # # priority表示日志级别,包括:debug, info, notice, warn(warning), err(error), # crit(critical), alert, emerg(要死了, panic)。指定级别方法: # *:所有级别; # none:没有级别,不记录; # priority:此级别及更高级别的日志信息都记录; # =priority:此级别。 # # target表示保存的路径,指定方法有: # 文件路径:记录于指定的日志文件中,通常应该在/var/log/目录下。文件路径前的"-"表示异步写入; # 用户:将日志通知给指定用户; # *:所有用户; # 日志服务器:@host; # host:必须要监听在tcp或udp协议514端口上提供服务; # 管道: |COMMAND
Mar 25 09:11:26 localhost sshd[15000]: Accepted password for root from 192.168.1.17 port 55624 ssh2 Mar 25 09:11:28 localhost sshd[15000]: error: no more sessions Mar 25 09:11:28 localhost sshd[15000]: error: no more sessions
vim /etc/rsyslog.conf local2.* /var/log/sshd.log # 在第三段配置上添加 systemctl restart rsyslog
再次登录,之后就可以查看到日志了 cat /var/log/sshd.log Mar 25 09:11:26 localhost sshd[15000]: Accepted password for root from 192.168.1.17 port 55624 ssh2 Mar 25 09:11:28 localhost sshd[15000]: error: no more sessions Mar 25 09:11:28 localhost sshd[15000]: error: no more sessions