syslog介紹(二):Linux下syslog基本配置

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.