Apache日志默认情况下是一周切割一次,由于访问量大的时候日志的文件还是比较大的,同时也不利于管理员对日志的分析处理。于是尝试对Apache日志设置按天分割,并通过计划任务执行删除几天的日志。
下面对两条配置命令做一下说明:# ErrorLog logs/error_logErrorLog "| /usr/sbin/rotatelogs /var/log/httpd/error_log-%Y%m%d 86400 480"#CustomLog logs/access_log combinedCustomLog "| /usr/sbin/rotatelogs /var/log/httpd/access_log-%Y%m%d 86400 480" common 使用命令rotatelogs 对日志进行切割,查找该命令的位置使用:which rotatelogs 指定日志文件的位置和名称/var/log/httpd/error_log-%Y%m%d 指定分割时间:86400 默认单位为s。也就是24小时 指定分区时差:480 默认单位m,也就是8小时 日志清理脚本: #!/bin/bash############################################################Author:john ##Date:2017.10.27 ##E-mail:yemf@digitlink.cn ##Comment:http_clear_logs.sh ##Path:/home/shell ##Crontab: 0 3 * * * sh /home/shell/http_clear_logs.sh ##Vesion:v1.0 #############################################################the date 7 days agoDate_7=`date -d "-2 day" +%Y%m%d`http_log_path="/data/apachelogs/"#clear logsrm -fr ${http_log_path}/access_log-${Date_7}rm -fr ${http_log_path}/error_log-${Date_7}