rsyslog

http://11996114.blog.51cto.com/11986114/1955668

linux系统中用来实现日志功能的服务称为rsyslog,是早期syslog服务的增强版本,默认情况下是自动安装,并启动的。

1、启动服务

[root@37-test log]# service rsyslog start


2、配置文件

[root@37-test log]# more /etc/rsyslog.conf 



基本格式:

facility.priority log_location


[root@37-test log]# more /etc/rsyslog.conf  |grep -v ^# |grep -v ^$

$ModLoad imuxsock.so # provides support for local system logging (e.g. via logger command)

$ModLoad imklog.so # provides kernel logging support (previously done by rklogd)

$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

*.info;mail.none;authpriv.none;cron.none                /var/log/messages

authpriv.*     //*表示任意级别,none就是没有级别,不记录     /var/log/secure

mail.*          -/var/log/maillog    //-表示不等待磁盘同步,确认操作是否已经写入到磁盘中,

cron.*                                                  /var/log/cron

*.emerg                                                 *

uucp,news.crit                                          /var/log/spooler

local7.*                                                /var/log/boot.log


plr @10.40.0.100 表示使用udp协议将消息存储到指定远程服务器上。

user @@10.40.0.200 表示使用TCP协议将消息存储到指定远程服务器上。


3、日志存放位置

[root@37-test log]# ls /var/log

anaconda.ifcfg.log    cups                 messages-20170108  spooler-20170101

anaconda.log          dmesg                nprobe             spooler-20170108

anaconda.program.log  dmesg.old            ntopng             tallylog

anaconda.storage.log  dracut.log           ntpstats           wpa_supplicant.log

anaconda.syslog       dracut.log-20130101  pm-powersave.log   wtmp

anaconda.xlog         gdm                  ppp                xferlog

anaconda.yum.log      httpd                puppet             xferlog-20161218

audit                 iptraf               redis              xferlog-20161225

boot.log              lastlog              salt               xferlog-20170101

btmp                  maillog              samba              xferlog-20170108

btmp-20170101         maillog-20161218     secure             Xorg.0.log

cento                 maillog-20161225     secure-20161218    Xorg.0.log.old

ConsoleKit            maillog-20170101     secure-20161225    yum.log

cron                  maillog-20170108     secure-20170101    yum.log-20140610

cron-20161218         messages             secure-20170108    yum.log-20150101

cron-20161225         messages-20161218    spooler            yum.log-20160101

cron-20170101         messages-20161225    spooler-20161218   yum.log-20170101

cron-20170108         messages-20170101    spooler-20161225


4、实时监控日志信息

[root@37-test log]# tail /var/log/messages-20170108 -f

Jan  8 03:01:23 37-test puppet-agent[17734]: Caching catalog for 37-test

Jan  8 03:01:24 37-test puppet-agent[17734]: Applying configuration version '1483815681'

Jan  8 03:01:59 37-test puppet-agent[17734]: (/Stage[main]/Common/Exec[hot_fix_for_fms_audio_config]/returns) executed successfully

Jan  8 03:01:59 37-test puppet-agent[17734]: (/Stage[main]/Common/Exec[hot_fix_for_CourswareBussiness.php]/returns) executed successfully

Jan  8 03:01:59 37-test puppet-agent[17734]: (/Stage[main]/Common/Exec[hot_fix_for_fms_video_config]/returns) executed successfully


5、日志消息的来源-facility

rsyslog通过facility概念来定义日志消息的来源,以方便对日志进行分类。

-kern 内核消息

-user 用户级消息

-mail 邮件系统消息

-daemon 系统服务消息

-auth 认证系统消息

-lpr 打印系统消息

-syslog 日志系统自身消息

-authpriv 权限系统消息

-cron 计划定时任务消息

-news 新闻系统消息

-uucp uucp系统消息

-ftp ftp服务消息

6、priority/serverity level(日志优先级,级别)

-emergency 系统已经不可用

-alert 必须立即处理

-critical 严重错误

-error 错误

-warning 警告

-notice 正常信息,但较为重要

-informational 正常信息

-debug debug信息


日志级别包括最大级别和最小级别

    最大级别:指记录日志的最低等级是什么,换句话说如果定义了日志的最大级别是error,那么他的意思就是说只记录error及以上级别的错误日志。

    最小级别:和最大级别正好相反,并且也不常用。