您的位置:首页 > 运维架构 > Linux

Linux 日志切割工具cronolog详解

2017-03-23 21:36 381 查看
一、前言

二、cronolog 简介

三、cronolog 特点

四、cronolog 安装

五、cronolog 使用

六、cronolog 总结

注,操作系统 CentOS 6.4 x86_64,软件版本 cronolog 1.6.2,软件下载http://cronolog.org/download/index.html

一、前言

大家都知道apache服务器,默认日志文件是不分割的,一个整文件既不易于管理,也不易于分析统计。本博文主要讲解Web服务器日志切割工具cronolog,下面我们就来详细的讲解一下。

二、cronolog 简介

Welcome to cronolog.org, the home of the cronolog web log rotation program.cronolog is a simple filter program that reads log file entries from standard input and writes each entry to the output file specified by a filename template and the current date and time. When the expanded filename changes, the current file is closed and a new one opened. cronolog is intended to be used in conjunction with a Web server, such asApache, to split the access log into daily or monthly logs.

cronolog 是一个简单的过滤程序,读取日志文件条目从标准输入和输出的每个条目并写入指定的日志文件的文件名模板和当前的日期和时间。当扩展文件名的变化,目前的文件是关闭,新开辟的。cronolog 旨在和一个Web服务器一起使用,如Apache,分割访问日志为每天或每月的日志。

三、cronolog 特点

cronolog主要和Web服务器配置使用,特别是Apache服务器,Apache 默认日志文件是不分割的,一个整文件既不易于管理,也不易于分析统计。安装cronolog后,可以将日志文件按时间分割,易于管理和分析。下面是与Apache配置的一些指令:

下面是具体案例,

四、cronolog 安装

1.安装yum源

2.安装ntp

3.时间同步

4.安装cronolog

(1).直接用yum安装

(2).源码安装

好了,到这里我们的cronolog就安装完成了,下面我们来说一下cronolog如何使用。

五、cronolog 使用

(1).基本使用

cronolog 一般是采取管道的方式来工作的,采用如下的形式:

其中,loggenerator为产生log的程序,而log_file_pattern是日志文件的路径,可以在其中加入cronolog所支持的时间相关的pattern字符,如/www/log/%y/%m/%d/access.log。其pattern为%字符后跟一特殊字符,简述如下:

转义符:

时间域:

日期域:

(2).结合apache使用

编辑httpd.conf文件,将其中的

(3).下面是效果

六、cronolog 总结

好了,到这里我们的cronolog工具就讲解完成了。有博友会问为什么不用apache自带的日志分割工具?apache自带的日志分割工具rotatelogs,据专家说在进行日志切割时容易丢日志,所以这里我们就用cronolog来做日志切割。最后,希望大家有所收获^_^……

本文出自 “Share your knowledge …” 博客,请务必保留此出处http://freeloda.blog.51cto.com/2033581/1346076
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: