1> 编辑 httpd.conf
<VirtualHost *:80>
ServerName www.sipo.gov.cn
DocumentRoot /gpower/pubhtml/gzjqy
ErrorLog "| /opt/soft/apache2/bin/rotatelogs /data/apachelog/logs/www/chinese_%Y%m%daccess_log.log 86400 480"
CustomLog "| /opt/soft/apache2/bin/rotatelogs /data/apachelog/logs/www/chinese_%Y%m%daccess_log.log 86400 480" combined
<Directory "/gpower/pubhtml/gzjqy">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ErrorLog "| /opt/soft/apache2/bin/rotatelogs /data/apachelog/logs/www/chinese_%Y%m%daccess_log.log 86400 480"
CustomLog "| /opt/soft/apache2/bin/rotatelogs /data/apachelog/logs/www/chinese_%Y%m%daccess_log.log 86400 480" combined
ps:每天生成日志文件
chinese_%Y%m%daccess_log.log
生成格式
2> 定时删除日志文件
touch delete_logs.sh
脚本文件
vi delete_logs.sh
编辑文件
#!/bin/sh
find /opt/soft/apache2/logs/ -mtime +5 -name "*access_log.log" -exec rm -rf {} \;
find :查找
/opt/soft/apache2/logs/
所需查找路径
-mtime +5
固定格式 5为五天
"*access_log.log"
满足此格式的文件
-exec rm -rf {} \;
固定格式
crontab -l
查看定时任务
crontab -e
编辑定时任务
0 3 * * * /opt/soft/apache2/delete_logs.sh
每天三点删除大于5天的日志文件