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

apache日志切割

2012-04-15 14:26 302 查看
apache日志切割

服务器有大量的用户的话,这些日志文件的大小会很快地增加,在服务器硬盘不是非常充足的情况下,必须采取措施防止日志文件将硬盘撑爆。

1、rotatelogs
rotatelogs不用编译,apache会自动生成
 

  vi /usr/local/apache/conf/httpd.conf
  ErrorLog "| /usr/local/apache/bin/rotatelogs /usr/local/apache/logs/%Y_%m_%d_error_log 86400 480"

  CustomLog "| /usr/local/apache/bin/rotatelogs /usr/local/apache/logs/%Y_%m_%d_access_log 86400 480" common

 

  

  注:

  errorlog.%Y-%m-%d-%H_%M_%S为生成日志的格式,类似于这样:errorlog.2010-04-15-11_32_30 ,以年月日时分秒为单位的,

  86400为轮转的时间单位为秒即一天。

  480 为时差,文件的时间为美国时间,中国的时差要比美国多8个小时也就是480分钟,所以要加上480分钟

  

其配置文件为/etc/logrotate.conf内容如下:(可改动)

# see "man logrotate" for details

# rotate log files weekly

weekly

#以7天为一个周期
# keep 4 weeks worth of backlogs

rotate 4

#每隔4周备份日志文件
# send errors to root

errors root

#发生错误向root报告
# create new (empty) log files after rotating old ones

create

#转完旧的日志文件就创建新的日志文件
# uncomment this if you want your log files compressed

#compress

#指定是否压缩日志文件
# RPM packages drop log rotation information into this directory

include /etc/logrotate.d
# no packages own lastlog or wtmp -- we'll rotate them here

/var/log/wtmp {

monthly

create 0664 root utmp

rotate 1

}
# system-specific logs may be configured here

2、cronolog
  
   下载地址:http://cronolog.org/download/cronolog-1.6.2.tar.gz

  # tar zxvf cronolog-1.6.2.tar.gz

  # cd cronolog-1.6.2

  # ./configure

  # make && make install

  

  默认路径为:/usr/local/sbin/cronolog

  配置apache

  vi /usr/local/apache/conf/httpd.conf
  CustomLog “|/usr/local/sbin/cronolog /usr/local/apache/logs/access_%Y%m%d.log” combined 定义访问日志

  ErrorLog “|/usr/local/sbin/cronolog /home/www/ex/log/error_%Y%m%d.log” 定义错误日志

  保存配置文件后,重启apache服务即可生效。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  apache 日志切割