linux syslog日志服务

简介  
不同的Linux发行版使用不同syslog程序来记录系统日志。
的Debain 4.0/Ubuntu8.04(桌面版)默认使用的是sysklogd,配置文件为/etc/syslog.conf。

Fedora9默认使用rsyslogd,配置文件为/etc/rsyslog.conf。

ubuntu中使用rsyslog,配置文件在/etc/rsyslog.d/50-default.conf

opensuse11使用syslog-ng,配置文件为/etc/syslog-ng/syslog-ng.conf。

这里仅一debian为例介绍一下syslog.conf的配置,rsyslog.conf的格式和syslog.conf是基本一样的。可以用man syslog.conf命令查看配置帮助。

配置文件由多条规则构成,每条规则有3个部分,#开头的是注释。每条规则分3个部分指定Facility、Severity以及要采取的措施。规则是组合 的。

例子  
下面的规则指定Facility为mail,Severity为err以上级别的日志写入/var/log/mail.err文件,而err以下级别的日 志则被忽略:
mail.err                        /var/log/mail.err

Facility和Severity可以使用通配符,也可以指定多个,用逗号隔开:
auth,authpriv.*                 /var/log/auth.log

Facility和Severity的组合可以有多个,用分号隔开,文件前面加一个减号表示日志不立即写入文件,而是在缓冲中积攒到一定的条件再写,这样 可以提高性能,但是当机可能会丢失数据:
*.*;auth,authpriv.none          -/var/log/syslog
 

可以把syslog消息通过UDP发送到syslog服务器的514端口:
*.err    @192.168.0.1

发生错误时,在控制台打屏:
*.err    /dev/console

日志格式 
debian 4.0外发的syslog都有换行符\n结尾,没有主机名和时间,例如:
<38>su[2257]: (pam_unix) session opened for user root by root(uid=0)
<30>dhclient: bound to 192.168.233.129 -- renewal in 878 seconds.

本地syslog日志文件中的样本(/var/log/auth.log),有主机名和时间,但没有Facility和Severity
Oct  8 22:36:56 debian sshd[2261]: (pam_unix) session opened for user root by root(uid=0)

fedora的rsyslogd转发的syslog则没有换行符\n结尾。


最后给出debian4.0默认的syslog.conf文件
 :

#  /etc/syslog.conf     Configuration file for syslogd.  
#  
#                       For more information see syslog.conf(5)  
#                       manpage.  

#  
# First some standard logfiles.  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  
uucp.*                          /var/log/uucp.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  

#  
# Some `catch-all' logfiles.  
#  
*.=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                         *  

#  
# 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  

# The named pipe /dev/xconsole is for the `xconsole' utility.  To use it,  
# you must invoke `xconsole' with the `-file' option:  
#  
#    $ xconsole -file /dev/xconsole [...]  
#  
# NOTE: adjust the list below, or you'll go crazy if you have a reasonably  
#      busy site..  
#  
daemon.*;mail.*;\  
        news.crit;news.err;news.notice;\  
        *.=debug;*.=info;\  
        *.=notice;*.=warn       |/dev/xconsole

你可能感兴趣的:(linux syslog日志服务)