在/etc/cron.daily中新增logrotate文件
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
在/etc/logrotate.d中新增log配置文件,進行配置刪除日誌
/log/*.log {
daily
noolddir
rotate 7
missingok
notifempty
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
/bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}
強制重啓回滾服務
#logrotate -vf /etc/logrotate.conf
或者
/usr/sbin/logrotate -vf /etc/logrotate.conf
crontab -l //顯示用戶的crontab文件的內容
crontab -e //編輯用戶的crontab文件的內容
crontab -r //刪除用戶的crontab文件
root目錄下新建執行腳本
touch logrotate.sh
#! /bash/sh
su - root -c "logrotate -vf /etc/logrotate.conf"
chmod u+x logrotate.sh
新增定時啓動
#crontab -e
5 7,19 * * * sh /root/logrotate.sh >> logrotate.log 2>&1
重啓定時服務
service crond restart
重啓日誌服務
service syslog restart
強制進行回滾
logrotate -vf /etc/logrotate.conf