使用
cronolog可以格式化日志文件的格式,比如按时间分割,易于管理和分析。
cronolog的安装配置非常简单,简要说明如下:
1.下载软件
http://cronolog.org/download/index.html
2.解压缩
gzip -d cronolog-1.6.2.tar.gz
tar xf cronolog-1.6.2.tar
2.进入相应的目录 ./configure
3.make
4.make install
5.修改apache配置文件
以下是我的安装日志,供大家参考:
| [root@eygle opt]# wget http://cronolog.org/download/cronolog-1.6.2.tar.gz--08:05:12-- http://cronolog.org/download/cronolog-1.6.2.tar.gz => `cronolog-1.6.2.tar.gz'Resolving cronolog.org... done.Connecting to cronolog.org[217.160.212.212]:80... connected.HTTP request sent, awaiting response... 200 OKLength: 133,591 [application/x-gzip]100%[==================================>] 133,591 26.23K/s ETA 00:0008:05:19 (26.23 KB/s) - `cronolog-1.6.2.tar.gz' saved [133591/133591][root@eygle opt]# gzip -d cronolog-1.6.2.tar.gz [root@eygle opt]# tar xf cronolog-1.6.2.tar [root@eygle opt]# cd cronolog-1.6.2[root@eygle cronolog-1.6.2]# lsaclocal.m4 config.cache configure cronolog.spec install-sh Makefile.am mkinstalldirs srcAUTHORS config.log configure.in doc lib Makefile.in NEWS testsuiteChangeLog config.status COPYING INSTALL Makefile missing README TODO[root@eygle cronolog-1.6.2]# ./configure loading cache ./config.cachechecking for a BSD compatible install... (cached) /usr/bin/install -cchecking whether build environment is sane... yeschecking whether make sets ${MAKE}... (cached) yeschecking for working aclocal... foundchecking for working autoconf... foundchecking for working automake... foundchecking for working autoheader... foundchecking for working makeinfo... foundchecking for gcc... (cached) gccchecking whether the C compiler (gcc ) works... yeschecking whether the C compiler (gcc ) is a cross-compiler... nochecking whether we are using GNU C... (cached) yeschecking whether gcc accepts -g... (cached) yeschecking for a BSD compatible install... /usr/bin/install -cchecking whether ln -s works... (cached) yeschecking for ranlib... (cached) ranlibchecking for perl... (cached) /usr/bin/perlchecking how to run the C preprocessor... (cached) gcc -Echecking for ANSI C header files... (cached) yeschecking whether stat file-mode macros are broken... (cached) nochecking whether time.h and sys/time.h may both be included... (cached) yeschecking whether struct tm is in sys/time.h or time.h... (cached) time.hchecking for tm_zone in struct tm... (cached) yeschecking for fcntl.h... (cached) yeschecking for limits.h... (cached) yeschecking for unistd.h... (cached) yeschecking for working const... (cached) yeschecking for size_t... (cached) yeschecking whether struct tm is in sys/time.h or time.h... (cached) time.hchecking for strftime... (cached) yeschecking for vprintf... (cached) yeschecking for mkdir... (cached) yeschecking for mktime... (cached) yeschecking for putenv... (cached) yeschecking for strptime... (cached) yeschecking for localtime_r... (cached) yescreating ./config.statuscreating Makefilecreating lib/Makefilecreating src/Makefilecreating doc/Makefilecreating testsuite/Makefilecreating src/cronosplit[root@eygle cronolog-1.6.2]# makeMaking all in libmake[1]: Entering directory `/opt/cronolog-1.6.2/lib'make[1]: Nothing to be done for `all'.make[1]: Leaving directory `/opt/cronolog-1.6.2/lib'Making all in srcmake[1]: Entering directory `/opt/cronolog-1.6.2/src'make[1]: Nothing to be done for `all'.make[1]: Leaving directory `/opt/cronolog-1.6.2/src'Making all in docmake[1]: Entering directory `/opt/cronolog-1.6.2/doc'make[1]: Nothing to be done for `all'.make[1]: Leaving directory `/opt/cronolog-1.6.2/doc'Making all in testsuitemake[1]: Entering directory `/opt/cronolog-1.6.2/testsuite'make[1]: Nothing to be done for `all'.make[1]: Leaving directory `/opt/cronolog-1.6.2/testsuite'make[1]: Entering directory `/opt/cronolog-1.6.2'make[1]: Nothing to be done for `all-am'.make[1]: Leaving directory `/opt/cronolog-1.6.2'[root@eygle cronolog-1.6.2]# make installMaking install in libmake[1]: Entering directory `/opt/cronolog-1.6.2/lib'make[2]: Entering directory `/opt/cronolog-1.6.2/lib'make[2]: Nothing to be done for `install-exec-am'.make[2]: Nothing to be done for `install-data-am'.make[2]: Leaving directory `/opt/cronolog-1.6.2/lib'make[1]: Leaving directory `/opt/cronolog-1.6.2/lib'Making install in srcmake[1]: Entering directory `/opt/cronolog-1.6.2/src'make[2]: Entering directory `/opt/cronolog-1.6.2/src'/bin/sh ../mkinstalldirs /usr/local/sbin /usr/bin/install -c cronolog /usr/local/sbin/cronolog/bin/sh ../mkinstalldirs /usr/local/sbin /usr/bin/install -c cronosplit /usr/local/sbin/cronosplitmake[2]: Nothing to be done for `install-data-am'.make[2]: Leaving directory `/opt/cronolog-1.6.2/src'make[1]: Leaving directory `/opt/cronolog-1.6.2/src'Making install in docmake[1]: Entering directory `/opt/cronolog-1.6.2/doc'make[2]: Entering directory `/opt/cronolog-1.6.2/doc'make[2]: Nothing to be done for `install-exec-am'./bin/sh ../mkinstalldirs /usr/local/info /usr/bin/install -c -m 644 ./cronolog.info /usr/local/info/cronolog.info install-info --info-dir=/usr/local/info /usr/local/info/cronolog.infomake install-man1make[3]: Entering directory `/opt/cronolog-1.6.2/doc'/bin/sh ../mkinstalldirs /usr/local/man/man1 /usr/bin/install -c -m 644 ./cronolog.1m /usr/local/man/man1/cronolog.1m /usr/bin/install -c -m 644 ./cronosplit.1m /usr/local/man/man1/cronosplit.1mmake[3]: Leaving directory `/opt/cronolog-1.6.2/doc'make[2]: Leaving directory `/opt/cronolog-1.6.2/doc'make[1]: Leaving directory `/opt/cronolog-1.6.2/doc'Making install in testsuitemake[1]: Entering directory `/opt/cronolog-1.6.2/testsuite'make[2]: Entering directory `/opt/cronolog-1.6.2/testsuite'make[2]: Nothing to be done for `install-exec-am'.make[2]: Nothing to be done for `install-data-am'.make[2]: Leaving directory `/opt/cronolog-1.6.2/testsuite'make[1]: Leaving directory `/opt/cronolog-1.6.2/testsuite'make[1]: Entering directory `/opt/cronolog-1.6.2'make[2]: Entering directory `/opt/cronolog-1.6.2'make[2]: Nothing to be done for `install-exec-am'.make[2]: Nothing to be done for `install-data-am'.make[2]: Leaving directory `/opt/cronolog-1.6.2'make[1]: Leaving directory `/opt/cronolog-1.6.2'[root@eygle cronolog-1.6.2]# which cronolog/usr/local/sbin/cronolog |
安装完成以后需要对apache进行适当配置,修改httpd.conf文件,主要注意以下几点:
1.自定义日志格式
CustomLog "|/usr/local/sbin/cronolog /opt/apache/logs/access_log.%Y%m%d" combined
2.如果存在多个虚拟站点
可以考虑在VirtualHost进行相应设置
| ServerAdmin webmaster@dummy-host.example.com DocumentRoot /www/docs/dummy-host.example.com ServerName dummy-host.example.com ErrorLog logs/dummy-host.example.com-error_log CustomLog logs/dummy-host.example.com-access_log common |
我的www.eygle.com存在多个子站点,但是都使用了同一个日志文件
配置后生成日志文件的效果:
| [root@eygle logs]# ls -l access_log.20041226 -rw-r--r-- 1 root root 110425 Dec 26 09:10 access_log.20041226 |
-----