利用logrotate對MySQL日志進行輪轉
利用logrotate對MySQL日志進行輪轉
[Linux]利用logrotate對MysqL日志進行輪轉。 。日志輪轉特別適用于具有固定文件名的日志文件,比如MysqL的出錯日志、常規查詢日志、慢查詢日志等。Linux系統有一個非常好用的根據logratate可以實現自動輪轉,本文介紹它的原理和用法。默認情況下,logratate部署為每天運行的cronjob,你可以在目錄/etc/cron.daily里找到名為logratate的配置文件。那么它是在每天的上面時候運行的呢?打開文件/etc/crontab就知道了,下面是我機器上的情況。[plain] 。SHELL=/bin/bash 。PATH=/sbin:/bin:/usr/sbin:/usr/bin 。MAILTO=root 。
導讀[Linux]利用logrotate對MysqL日志進行輪轉。 。日志輪轉特別適用于具有固定文件名的日志文件,比如MysqL的出錯日志、常規查詢日志、慢查詢日志等。Linux系統有一個非常好用的根據logratate可以實現自動輪轉,本文介紹它的原理和用法。默認情況下,logratate部署為每天運行的cronjob,你可以在目錄/etc/cron.daily里找到名為logratate的配置文件。那么它是在每天的上面時候運行的呢?打開文件/etc/crontab就知道了,下面是我機器上的情況。[plain] 。SHELL=/bin/bash 。PATH=/sbin:/bin:/usr/sbin:/usr/bin 。MAILTO=root 。
系統大全為您提供[Linux]利用logrotate對MysqL日志進行輪轉?日志輪轉特別適用于具有固定文件名的日志文件,比如MysqL的出錯日志、常規查詢日志、慢查詢日志等。Linux系統有一個非常好用的根據logratate可以實現自動輪轉,本文介紹它的原理和用法。默認情況下,logratate部署為每天運行的cronjob,你可以在目錄/etc/cron.daily里找到名為logratate的配置文件。那么它是在每天的上面時候運行的呢?打開文件/etc/crontab就知道了,下面是我機器上的情況:[plain]?SHELL=/bin/bash?PATH=/sbin:/bin:/usr/sbin:/usr/bin?MAILTO=root?HOME=/???#run-parts?01****rootrun-parts/etc/cron.hourly?024***rootrun-parts/etc/cron.daily?224**0rootrun-parts/etc/cron.weekly?4241**rootrun-parts/etc/cron.monthly?從上面的配置我們可以知道,/etc/cron.daily是在每天凌晨4:02執行。也就是說,每天4:02分/etc/cron.daily/logratate將會自動執行,下面是它的內容:[plain]?#!/bin/sh???/usr/sbin/logrotate/etc/logrotate.conf?EXITVALUE=$??if[$EXITVALUE!=0];then???/usr/bin/logger-tlogrotate"ALERTexitedabnormallywith[$EXITVALUE]"?fi?exit0?從上面我們可以知道,logratate默認的配置文件是/etc/logratate.conf,下面是它的內容:[plain]?EXITVALUE=$??if[$EXITVALUE!=0];then???/usr/bin/logger-tlogrotate"ALERTexitedabnormallywith[$EXITVALUE]"?fi?exit0?[root@lx202/etc/cron.daily]#cat/etc/logrotate.conf?#see"manlogrotate"fordetails?#rotatelogfilesweekly?weekly???#keep4weeksworthofbacklogs?rotate4???#createnew(empty)logfilesafterrotatingoldones?create???#uncommentthisifyouwantyourlogfilescompressed?#compress???#RPMpackagesdroplogrotationinformationintothisdirectory?include/etc/logrotate.d???#nopackagesownwtmp--we'llrotatethemhere?/var/log/wtmp{???monthly???minsize1M???create0664rootutmp???rotate1?}???/var/log/btmp{???missingok???monthly???minsize1M???create0600rootutmp???rotate1?}?從上面我們可以知道,這個默認的配置文件將讀取目錄/etc/logrotate.d,所以我們只要把自己寫的配置文件放到該目錄下即可。MysqL本省提供了一個rotate的參考配置文件,在support-files目錄下,文件名為MysqL-log-rotate,內容如下:[plain]?#Thislognamecanbesetin/etc/my.cnf?#bysettingthevariable"err-log"?#inthe[safe_MysqLd]sectionasfollows:?#?#[safe_MysqLd]?#err-log=/opt/MysqL/data/MysqLd.log?#?#Iftherootuserhasapasswordyouhavetocreatea?#/root/.my.cnfconfigurationfilewiththefollowing?#content:?#?#[MysqLadmin]?#password=
?#user=root?#?#where""isthepassword.?#?#ATTENTION:This/root/.my.cnfshouldbereadableONLY?#forroot!???/opt/MysqL/data/MysqLd.log{?????#create600MysqLMysqL?????notifempty?????daily?????rotate3?????missingok?????compress???postrotate?????#justifMysqLdisreallyrunning?????iftest-x/opt/MysqL/bin/MysqLadmin&&???????/opt/MysqL/bin/MysqLadminping&>/dev/null?????then???????/opt/MysqL/bin/MysqLadminflush-logs?????fi???endscript?}?logrotate常見選項:選項含義compress壓縮日志文件的所有非當前版本copy復制當前的日志文件,忽略create參數copytruncate復制當前的日志文件,并置空當前文件daily每天輪日志文件idateext輪換的日志后綴為-YYYYMMDD格式delaycompress壓縮除了當前和最近之外的所有其他版本missingok如果日志不存在,不會報錯notifempty如果日志為空,則不輪換rotaten在輪換方案中包含n個版本的日志size=logsize如果日志文件大于logsize才輪換我們只要根據自己的需要,修改相應配置即可,下面是一個例子:1)創建MysqLroot密碼文件vi/root/.my.cnf[plain]?[MysqLadmin]?password=***?user=root?chmod600/root/.my.cnf2)把MysqL-log-rotate拷貝至/etc/logrotate.d目錄下,修改其內容為:[plain]?/data/MysqL/log/slow.log?/data/MysqL/log/alert.log{?????create600MysqLMysqL?????notifempty?????daily?????rotate7?????missingok?????#compress???postrotate?????#justifMysqLdisreallyrunning?????iftest-x/opt/MysqL/bin/MysqLadmin&&???????/opt/MysqL/bin/MysqLadminping&>/dev/null?????then???????/opt/MysqL/bin/MysqLadminflush-logs?????fi???endscript?}?3)執行以下命令測試[plain]?/usr/sbin/logrotate-f/etc/logrotate.d/MysqL-log-rotate?以上就是系統大全給大家介紹的如何使的方法都有一定的了解了吧,好了,如果大家還想了解更多的資訊,那就趕緊點擊系統大全官網吧。本文來自系統大全http:///如需轉載請注明!推薦:win7純凈版
利用logrotate對MySQL日志進行輪轉
[Linux]利用logrotate對MysqL日志進行輪轉。 。日志輪轉特別適用于具有固定文件名的日志文件,比如MysqL的出錯日志、常規查詢日志、慢查詢日志等。Linux系統有一個非常好用的根據logratate可以實現自動輪轉,本文介紹它的原理和用法。默認情況下,logratate部署為每天運行的cronjob,你可以在目錄/etc/cron.daily里找到名為logratate的配置文件。那么它是在每天的上面時候運行的呢?打開文件/etc/crontab就知道了,下面是我機器上的情況。[plain] 。SHELL=/bin/bash 。PATH=/sbin:/bin:/usr/sbin:/usr/bin 。MAILTO=root 。
為你推薦