1蜓竹、介紹
Logrotate是linux日志切割工具?
Logrotate是基于crontab定時(shí)任務(wù)實(shí)現(xiàn)的定時(shí)日志切割平绩,配置文件為 /etc/logrotate.conf务嫡。crontab的每天的定時(shí)執(zhí)行任務(wù)目錄/etc/cron.daily存放每天要執(zhí)行的定時(shí)任務(wù)闸迷,里邊就有l(wèi)ogrotate文件冒签。
2、logrotate命令:
logrotate -f /etc/logrotate.conf強(qiáng)制執(zhí)行?
logrotate -d /etc/logrotate.conf debug 測(cè)試編寫的logrotate文件
3笔诵、示例可用配置
/etc/logrotate.conf配置文件中有一行
include /etc/logrotate.d
表示包含/etc/logrotate.d目錄下邊的文件返吻,可在該目錄下新建一個(gè)文件如im,內(nèi)容如下:
/opt/im/log/*/info/*.log {
? ? daily
? ? missingok
? ? copytruncate
? ? rotate 10000000
? ? compress
? ? notifempty
? ? delaycompress
? ? dateext
}
4、配置選項(xiàng)說明
compress:通過gzip 壓縮轉(zhuǎn)儲(chǔ)舊的日志?
nocompress:不需要壓縮時(shí)乎婿,用這個(gè)參數(shù)?
copytruncate:用于還在打開中的日志文件测僵,把當(dāng)前日志備份并截?cái)?
nocopytruncate:備份日志文件但是不截?cái)?
create mode owner group:使用指定的文件模式創(chuàng)建新的日志文件?
nocreate:不建立新的日志文件?
delaycompress:和 compress 一起使用時(shí),轉(zhuǎn)儲(chǔ)的日志文件到下一次轉(zhuǎn)儲(chǔ)時(shí)才壓縮?
nodelaycompress:覆蓋 delaycompress 選項(xiàng)谢翎,轉(zhuǎn)儲(chǔ)同時(shí)壓縮捍靠。?
errors address:專儲(chǔ)時(shí)的錯(cuò)誤信息發(fā)送到指定的Email 地址?
ifempty:即使是空文件也轉(zhuǎn)儲(chǔ),這個(gè)是 logrotate 的缺省選項(xiàng)岳服。?
notifempty:如果是空文件的話,不轉(zhuǎn)儲(chǔ)?
mail address:把轉(zhuǎn)儲(chǔ)的日志文件發(fā)送到指定的E-mail 地址?
nomail:轉(zhuǎn)儲(chǔ)時(shí)不發(fā)送日志文件?
olddir directory:轉(zhuǎn)儲(chǔ)后的日志文件放入指定的目錄希俩,必須和當(dāng)前日志文件在同一個(gè)文件系統(tǒng)?
noolddir:轉(zhuǎn)儲(chǔ)后的日志文件和當(dāng)前日志文件放在同一個(gè)目錄下?
prerotate/endscript:在轉(zhuǎn)儲(chǔ)以前需要執(zhí)行的命令可以放入這個(gè)對(duì)吊宋,這兩個(gè)關(guān)鍵字必須單獨(dú)成行?
postrotate/endscript:在轉(zhuǎn)儲(chǔ)以后需要執(zhí)行的命令可以放入這個(gè)對(duì),這兩個(gè)關(guān)鍵字必須單獨(dú)成行?
sharedscripts:所有的日志文件都輪轉(zhuǎn)完畢后統(tǒng)一執(zhí)行一次腳本?
daily:指定轉(zhuǎn)儲(chǔ)周期為每天?
weekly:指定轉(zhuǎn)儲(chǔ)周期為每周?
monthly:指定轉(zhuǎn)儲(chǔ)周期為每月?
rotate count:指定日志文件刪除之前轉(zhuǎn)儲(chǔ)的次數(shù)颜武,0 指沒有備份璃搜,5 指保留5 個(gè)備份?
size size:當(dāng)日志文件到達(dá)指定的大小時(shí)才轉(zhuǎn)儲(chǔ),Size 可以指定 bytes (缺省)以及KB (sizek)或者M(jìn)B