原创作品,允许转载,转载时请务必以超链接形式标明 文章 原始出处、作者信息和本声明。否则将追究 法律 责任。http://lsscto.blog.51cto.com/779396/830031 日志 切割 软件cronolog 下载地址: http://cronolog.org/download/cronolog-1.6.2.tar.gz 1.安装过
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://lsscto.blog.51cto.com/779396/830031
日志切割软件cronolog
下载地址: http://cronolog.org/download/cronolog-1.6.2.tar.gz
1.安装过程
tar zxvf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure
make
make install
2.修改Apache的配置文件httpd.conf,加入以下代码
ErrorLog "|/usr/local/sbin/cronolog /usr/local/apache2.2.22/logs/error_log_%Y%m%d"
CustomLog "|/usr/local/sbin/cronolog /usr/local/apache2.2.22/logs/access_log_%Y%m%d" combined
如果是虚拟主机,则修改http_vhost.conf,例如
ServerAdmin ngnix@qq.com
DocumentRoot "/usr/local/apache2.2.22/htdocs/myisam.com"
ServerName myisam.com
ServerAlias bbs.myisam.com
ErrorLog "|/usr/local/sbin/cronolog /usr/local/apache2.2.22/logs/myisam.com-error_log_%Y%m%d"
CustomLog "|/usr/local/sbin/cronolog /usr/local/apache2.2.22/logs/myisam.com-access_log_%Y%m%d"
combined
ServerAdmin ngnix@qq.com
DocumentRoot "/usr/local/apache2.2.22/htdocs/innodb.com"
ServerName innodb.com
ServerAlias bbs.innodb.com
ErrorLog "|/usr/local/sbin/cronolog /usr/local/apache2.2.22/logs/innodb.com-error_log_%Y%m%d"
CustomLog "|/usr/local/sbin/cronolog /usr/local/apache2.2.22/logs/innodb.com-access_log_%Y%m%d"
combined
4.编写脚本dellogs.sh,可以定时删除过期的日志(如下10天前)
#!/bin/bash
find /usr/local/apache2.2.22/logs -mtime +10 -name "innodb.com-*" -exec rm -rf {} \;
5.加入crontab
crontab -e
* 2 * * * /usr/local/bin/dellogs.sh > /dev/null 每天凌晨2点执行脚本
apache自带日志切割rotatelogs
1.直接修改httpd.conf或者虚拟主机配置文件httpd_vhost.conf
ErrorLog "|/usr/local/apache2.2.22/bin/rotatelogs /usr/local/apache/logs/myisam_error_log_%Y-%m-%d
-%H_%M_%S 86400" (86440单位是秒意思是1天)
CustomLog "|/usr/local/apache2.2.22/bin/rotatelogs /usr/local/apache/logs/myisam_access_log_%Y-%m-
%d-%H_%M_%S 86400" common
也可以定义日志大小,例如
ErrorLog "|/usr/local/apache2.2.22/bin/rotatelogs /usr/local/apache/logs/myisam_error_log_%Y-%m-%d
-%H_%M_%S 5M" (5M意思是每5M就生成新的日志)
CustomLog "|/usr/local/apache2.2.22/bin/rotatelogs /usr/local/apache/logs/myisam_access_log_%Y-%m-
%d-%H_%M_%S 5M" common
注意:rotatelogs设置的时候如果有多个虚拟主机,那么每个虚拟主机都需要配置,不然不会生成我们需要的日
志。
这两个程序还有一点不同: cronolog 如果日志是放在某个不存在的路径则会自动创建目录,而使用 rotatelogs
时不能自动创建。
本文出自 “流星 ” 博客,请务必保留此出处http://lsscto.blog.51cto.com/779396/830031
日志切割软件cronolog
下载地址: http://cronolog.org/download/cronolog-1.6.2.tar.gz
1.安装过程
tar zxvf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure
make
make install
2.修改Apache的配置文件httpd.conf,加入以下代码
ErrorLog "|/usr/local/sbin/cronolog /usr/local/apache2.2.22/logs/error_log_%Y%m%d"
CustomLog "|/usr/local/sbin/cronolog /usr/local/apache2.2.22/logs/access_log_%Y%m%d" combined
如果是虚拟主机,则修改http_vhost.conf,例如
ServerAdmin ngnix@qq.com
DocumentRoot "/usr/local/apache2.2.22/htdocs/myisam.com"
ServerName myisam.com
ServerAlias bbs.myisam.com
ErrorLog "|/usr/local/sbin/cronolog /usr/local/apache2.2.22/logs/myisam.com-error_log_%Y%m%d"
CustomLog "|/usr/local/sbin/cronolog /usr/local/apache2.2.22/logs/myisam.com-access_log_%Y%m%d"
combined
ServerAdmin ngnix@qq.com
DocumentRoot "/usr/local/apache2.2.22/htdocs/innodb.com"
ServerName innodb.com
ServerAlias bbs.innodb.com
ErrorLog "|/usr/local/sbin/cronolog /usr/local/apache2.2.22/logs/innodb.com-error_log_%Y%m%d"
CustomLog "|/usr/local/sbin/cronolog /usr/local/apache2.2.22/logs/innodb.com-access_log_%Y%m%d"
combined
4.编写脚本dellogs.sh,可以定时删除过期的日志(如下10天前)
#!/bin/bash
find /usr/local/apache2.2.22/logs -mtime +10 -name "innodb.com-*" -exec rm -rf {} \;
5.加入crontab
crontab -e
* 2 * * * /usr/local/bin/dellogs.sh > /dev/null 每天凌晨2点执行脚本
apache自带日志切割rotatelogs
1.直接修改httpd.conf或者虚拟主机配置文件httpd_vhost.conf
ErrorLog "|/usr/local/apache2.2.22/bin/rotatelogs /usr/local/apache/logs/myisam_error_log_%Y-%m-%d
-%H_%M_%S 86400" (86440单位是秒意思是1天)
CustomLog "|/usr/local/apache2.2.22/bin/rotatelogs /usr/local/apache/logs/myisam_access_log_%Y-%m-
%d-%H_%M_%S 86400" common
也可以定义日志大小,例如
ErrorLog "|/usr/local/apache2.2.22/bin/rotatelogs /usr/local/apache/logs/myisam_error_log_%Y-%m-%d
-%H_%M_%S 5M" (5M意思是每5M就生成新的日志)
CustomLog "|/usr/local/apache2.2.22/bin/rotatelogs /usr/local/apache/logs/myisam_access_log_%Y-%m-
%d-%H_%M_%S 5M" common
注意:rotatelogs设置的时候如果有多个虚拟主机,那么每个虚拟主机都需要配置,不然不会生成我们需要的日
志。
这两个程序还有一点不同: cronolog 如果日志是放在某个不存在的路径则会自动创建目录,而使用 rotatelogs
时不能自动创建。
本文出自 “流星 ” 博客,请务必保留此出处http://lsscto.blog.51cto.com/779396/830031