一、简介
在centos7系统中,默认的日志系统是rsyslog,它是一类unix系统上使用的开源工具,用于在ip网络中转发日志信息,rsyslog采用模块化设计,是syslog的替代品。
1、rsyslog特点
实现了基本的syslog协议
直接兼容syslogd的syslog.conf配置文件
在同一台机器上支持多个rsyslogd进程,支持多线程
丰富的过滤功能,可以实现过滤日志信息中的任何部分,可将消息过滤后在转发
灵活的配置选项,配置文件中可以写简单的逻辑判断,自定义输出格式等
增加了重要的功能,如使用tcp进行消息传输,支持UDP,TCP,SSL,TLS,RELP
有现成的前端web展示程序
可以使用MySQL,PGSQL,Oralce实现日志存储
默认安装的rsyslog软件包提供的守护进程是rsyslog,它是一项系统的基础服务,应该设置开机运行
2、核心组成
facility(设施,收集管道),priority(级别),target(路径)
facility:从功能或程序上对日志进行分类
auth:认证相关
authpriv:认证权限相关
cron:计划任务相关
daemon:守护进程相关
kern:内核相关
lpr:打印相关
mail:邮件相关
news:新闻相关
security:安全相关
syslog:自身日志
user:用户相关
uucp:unix to unix copy,早期系统文件共享服务
local0-local7:用户自定义facility
priority:日志级别也可以叫loglevel
debug:调试
info:除去debug外的所有信息
notice:注意
warn,warning:警告
err,error:错误信息
crit:蓝色警报
alert:橙色警报
emerg,panic:红色警报
指定级别的方式:
*:所有级别
none:没有级别
priority:比此级别高的(包含)所有级别的日志信息都会记录
=priority:仅记录指定级别
target:路径
文件路径:将日志记录于指定的文件中;在文件路径之前使用”-“,表示异步写入;
用户:将日志信息通知给文件
*:所有用户
日志服务器:@SERVER
管道:| COMMAND
3、配置文件明细
vim /etc/rsyslog.conf
1 # rsyslog configuration file
2
3 # For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html4 # If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html
5
6 #### MODULES #### #模块部分7
8 # The imjournal module bellow is now used as a message source instead of imuxsock.9 $ModLoad imuxsock #支持本地系统 provides support forlocal system logging (e.g. via logger command)10 $ModLoad imjournal # provides access to the systemd journal11 #$ModLoad imklog # reads kernel messages (the same are read from journald)12 #$ModLoad immark # provides --MARK--message capability13
14 # Provides UDP syslog reception15 #$ModLoad imudp16 #$UDPServerRun 514
17
18 # Provides TCP syslog reception19 #$ModLoad imtcp20 #$InputTCPServerRun 514
21
22
23 #### GLOBAL DIRECTIVES #### #全局指定24
25 # Where to place auxiliary files26 $WorkDirectory /var/lib/rsyslog27
28 # Use default timestamp format29 $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat30
31 # File syncing capability is disabled by default. This feature is usually not required,32 # not useful and an extreme performance hit33 #$ActionFileEnableSync on34
35 # Include all config files in /etc/rsyslog.d/
36 $IncludeConfig /etc/rsyslog.d/*.conf37
38 # Turn off message reception via local log socket;39 # local messages are retrieved through imjournal now.40 $OmitLocalLogging on41
42 # File to store the position in the journal43 $IMJournalStateFile imjournal.state44
45
46 #### RULES #### #规则部分47
48 # Log all kernel messages to the console.49 # Logging much else clutters up the screen.50 # 本地物理终端,比如启动引导的时候,打印在屏幕上的日志,可以用dmesg看51 #kern.* /dev/console52
53 # Log anything (except mail) of level info or higher.54 # Don't log private authentication messages!55#可以使用分号隔开,”*.info“所有的info,排除mail ,authpriv,cron56 *.info;mail.none;authpriv.none;cron.none /var/log/messages57
58 #如果想给发给日志服务器只需要指定服务器59 #*.info;mail.none;authpriv.none;cron.none @192.168.216.5360
61
62
63 # The authpriv file has restricted access.64 #authpriv.* ,authpriv的任何级别65 authpriv.* /var/log/secure66
67 # Log all the mail messages in one place.68#任意的mail,-/var/log/maillog 减号是异步的意思,因为不是特别关键,所以异步,节省效率69 mail.* -/var/log/maillog70
71
72 # Log cron stuff73 cron.* /var/log/cron74
75 # Everybody gets emergency messages76#所有登陆到系统上的用户的信息77 *.emerg :omusrmsg:*78
79 # Save news errors of level crit and higher in a special file.80 #”,“代表uucp和news都使用一个级别crit警告81 uucp,news.crit /var/log/spooler82
83 # Save boot messages also to boot.log84 #自定义日志ÿ