您的位置:首页 > 其它

logrotate工具清理日志

2014-07-26 15:16 302 查看
服务器使用实例:

vim /etc/logrotate.d/tomcat

写入一下内容

/home/tomcat*/logs/catalina.out {

rotate 7

daily

copytruncate

compress

notifempty

missingok

}

保存,然后执行

/usr/sbin/logrotate -f /etc/logrotate.conf

该命令执行后,应该是作为进程一直在运行,重启服务器可能需要再次执行

参考来源:

服务器上的tomcat的catalina.out文件越来越大,查看起来很不方便,以前每次都是想起来的时候手工清理一下(cat /dev/null > catalina.out),后来发现了logratate这个工具,Ubuntu下的mysql,nginx好像也是用的这个工具还定期整理log的。配置文件为/etc/logrotate.conf,和很多其它ubuntu下的工具一下,也可以把配置文件写在/etc/logrotate.d/下面。如对我们的tomcat的log文件进行整理,sudo
vi /etc/logrotate.d/tomcat,

/opt/tomcat*/logs/catalina.out {

rotate 14

daily

copytruncate

compress

notifempty

missingok

}

其中:

rotate 7 表示保留7天的备份文件

daily 表示每天整理一次

copytruncate 表示先复制log文件的内容,然后再清空

compress 表示压缩备分文件

missingok 表示如果找不到log文件也没OK

notifempty 表示如果log文件是空的,就不进行rotate

可以通过/usr/sbin/logrotate -f /etc/logrotate.conf来执行。

ubuntu有/etc/cron.daily/logrotate文件,内容为:

#!/bin/sh

test -x /usr/sbin/logrotate || exit 0

/usr/sbin/logrotate /etc/logrotate.conf

表示每天会定时执行一次这个命令

通过ntp同步服务器的时间

根据 ubuntu的文档 有两种方式可以用来使服务器的时间和ntp server同步。一种是通过ntpdate命令,如

ntpdate ntp.ubuntu.com

然后在/etc/cron.daily/下新建一个文件来每天执行一次这个命令

另一种是通过ntpd来更新。sudo apt-get install ntp。配置文件/etc/ntp.conf,可以通过修改配置文件为改变ntp server, 我们用的是210.72.145.44这个server

对于Linux 的系统安全来说,日志文件是极其重要的工具。系统管理员可以使用logrotate 程序用来管理系统中的最新的事件,对于Linux 的系统安全来说,日志文件是极其重要的工具。系统管理员可以使用logrotate 程序用来管理系统中的最新的事件。logrotate 还可以用来备份日志文件,本篇将通过以下几部分来介绍

  日志文件的管理:

  1、logrotate 配置

  2、缺省配置 logrotate

  3、使用include 选项读取其他配置文件

  4、使用include 选项覆盖缺省配置

  5、为指定的文件配置转储参数
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: