http://areyouok.iteye.com/blog/287980
簡介
不同的Linux發行版使用不同syslog程式來記錄系統日誌。
的Debain 4.0/Ubuntu8.04(案頭版)預設使用的是sysklogd,設定檔為/etc/syslog.conf。
Fedora9預設使用rsyslogd,設定檔為/etc/rsyslog.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