Linux log cutting tool cronolog detailed explanation and installation

1. Introduction of cronolog

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

2. Features of Cronolog

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

3. Installation of cronolog
Install yum source

[root@localhost ~]# yum -y install wget
[root@localhost ~]# wget http://ftp.sjtu.edu.cn/fedora/epel/6/i386/epel-release-6-8.noarch.rpm
[root@localhost ~]# rpm -ivh epel-release-6-8.noarch.rpm 
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...             ########################################### [100%]
1:epel-release           ########################################### [100%]

4. Install ntp

[root@localhost ~]# yum install -y ntp
[root@localhost ~]# date
2020年 06月 03日 星期三 05:22:38 CST

5, yum install cronolog and apache
which cronolog view the directory where cronolog is installed (verify whether the installation is successful)
/usr/sbin/cronolog

[root@localhost ~]# yum -y install cronolog httpd
[root@localhost ~]# which cronolog
/usr/sbin/cronolog

6. Cut the apache log

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
# CustomLog logs/access_log combined   修改前

#yum安装的
CustomLog "|/usr/sbin/cronolog /log/www/access_%Y-%m-%d.log" combined
CustomLog "|/usr/sbin/cronolog /log/www/error_%Y-%m-%d.log" combined

7, start apache

[root@localhost ~]# service httpd restart

8. Check the effect. If there is no /log/www directory, refresh the apache page with the browser
Insert picture description here

[root@localhost ~]# cd /log/www/
[root@localhost www]# ll
总用量 4
-rw-r--r--. 1 root root 752 6月  13 12:05 access_2020-06-13.log
-rw-r--r--. 1 root root 3572 6月  13 12:12 error_2020-06-13.log

Guess you like

Origin blog.csdn.net/lq_hello/article/details/106729402