首页 > 系统服务 > 详细

linux日志回滚

时间:2016-07-19 19:03:45      阅读:299      评论:0      收藏:0      [点我收藏+]

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


本文出自 “淡叹明心” 博客,请务必保留此出处http://dantanmingxin.blog.51cto.com/2061202/1827823

linux日志回滚

原文:http://dantanmingxin.blog.51cto.com/2061202/1827823

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!