linux日志回滚

在/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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章