rsyslog.conf 是 rsyslogd 的主配置檔案,rsyslog 是*nix 系統上用來記錄系統日誌的.rsyslog.conf 向後相容 syslogd 的 syslog.conf 檔案, 所以可以直接使用 syslog.conf.
 
測試系統:CentOS 6.4
/etc/rsyslog.conf 關於日誌記錄預設設定如下:
 
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*                                         /dev/console
 
# Log anything (except mail) of level info or higher.
# Don’t log private authentication messages!
*.info;mail.none;authpriv.none;cron.none              /var/log/messages
 
# The authpriv file has restricted access.
authpriv.*                                       /var/log/secure
 
# Log all the mail messages in one place.
mail.*                                          -/var/log/maillog
 
 
# Log cron stuff
cron.*                                           /var/log/cron
 
# Everybody gets emergency messages
*.emerg                                          *
 
# Save news errors of level crit and higher in a special file.
uucp,news.crit                                    /var/log/spooler
 
# Save boot messages also to boot.log
local7.*                                          /var/log/boot.log
 
 
<1>#kern.* : 只要是核心產生的資訊, 全部都送的 console(終端機) 去;
<2>*.info;mail.none;authpriv.none;cron.none : 由於 mail,auth,authpriv,cron 等型別
生成的資訊較多, 因此不記錄在/var/log/messages 中, 除此之外的資訊都寫入
messages 中;
<3>authpriv.* : 認證方面的資訊均寫入/var/log/secure 檔案;
<4>mail.* : 郵件方面的資訊均寫入/var/log/maillog 檔案;
<5>cron.* : 計劃任務方面資訊均寫入/var/log/cron 檔案;
<6>*.emerg : 當產生最嚴重的錯誤等級時, 將該等級的資訊以 wall 的方式廣播給所有系統登入的賬號, 要這麼做的原因是希望線上的使用者能夠趕緊通知系統管理員來處理這個問題;
<7>uucp,news.crit : uucp 是早期 Unix-like 系統進行資料傳遞的協議, 後來常用在新聞組的用途中.news 是新聞組, 當新聞組方面的資訊出現有嚴重錯誤時就寫入/var/log/spooler 這個檔案中;
<8>local7.* : 將本機開機時應該顯示到螢幕的資訊寫入到/var/log/boot.log 檔案中;
注意:
在記錄的檔案/var/log/maillog 前面還有個減號”-”, 由於郵件所產生的資訊比較多, 因此我們希望郵件產生的資訊先儲存在速度較快的記憶體中 (buffer), 等到數量夠大了才一次性將所有資料都填入磁碟中, 這樣有助於日誌檔案的訪問效能. 只不過由於資訊是暫存在記憶體中, 因此若不正常關機導致日誌資訊未填到日誌檔案中, 可能會造成部分資料的丟失.
 
 
同樣, 我們也可以自增加日誌檔案:
例如: 我們將所有的資訊都額外寫入/var/log/test.log 這個檔案中.
首先,/etc/rsyslog.conf 中做相應設定. 如下:
 
[root@sqj ~]# vi /etc/rsyslog.conf
#Test 2016-07-16
*.info                                    /var/log/test.log
 
建立 test.log 檔案, 如下:
[root@sqj ~]# cd /var/log/
[root@sqj log]# touch test.log
 
測試:
重啟下 rsyslog 服務, 然後在檢視 test.log 檔案, 如下:
[root@sqj log]# service rsyslog restart
Shutting down system logger: [  OK  ]
Starting system logger: [  OK  ]
[root@sqj log]# vi test.log
 
Jul 15 13:35:16 sqj kernel: imklog 5.8.10, log source = /proc/kmsg started.
Jul 15 13:35:16 sqj rsyslogd: [origin software=”rsyslogd” swVersion=”5.8.10″ x-pid=”25017″ x-info=”http://www.rsyslog.com”] start
 
是不是很簡單, 這樣所有的資訊都會寫入/var/log/test.log 檔案裡面了!