每次访问网站就会产生若干条日志,当然前提是已经配置了日志。

配置日志的文件在

vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 

把注释掉的这两行打开

ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common

common是日志的格式,把日志的格式改成combined

   ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" combined

日志的位置 logs是针对/usr/locol/apache2来说的。生成的文件是后面的两个名字。可以更名。

   ErrorLog "logs/denny.com-error_log"
CustomLog "logs/denny.com-access_log" combined

检查文件是否正确

apachectl -t

重新加载或者重启

/usr/local/apache2/bin/apachectl restart
/usr/local/apache2/bin/apachectl graceful

去论坛刷新几次,看看是否生成日志文件。

cd /usr/local/apache2/logs/
ls

生成了访问日志denny.com-access_log和错误日志denny.com-error_log

查看访问日志。

cat denny.com-access_log

复制其中一条信息

192.168.1.114 - - [/Dec/::: +] "GET /forum.php?mod=ajax&action=forumchecknew&fid=2&time=1449587726&inajax=yes HTTP/1.1"   "http://www.houchangfu.com/forum.php?mod=forumdisplay&fid=2" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)"

格式是

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

h来源IP 。l和u不存在用-号表示。u用户,t时间,r动作,Referer来源地址。User-Agent来源浏览器。

为了防止日志无限增长,要把每天的日志切割,以日期重命名,然后超过30天的删掉。

打开配置文件

vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 

修改

CustomLog "logs/denny.com-access_log" combined

CustomLog "|/usr/local/apache2/bin/rotatelogs -l  /usr/local/apache2/logs/denny.com-access_%Y%m%d_log 86400" combined

用apache2的命令,-l切割,日志存放路径写据对路径,时间格式 86400秒等于1天。

查看文件格式,重启。

apachectl -t
/usr/local/apache2/bin/apachectl restart

刷新论坛然后ls查看

 ls /usr/local/apache2/logs/
denny.com-access_20151208_log

LAMP 2.0Apache日志切割的更多相关文章

  1. linux shell:nginx日志切割脚本

    需求原因:nginx不具备日志切割功能,日志量较大,方便分析. 实现目的:完成nginx日志切割,并根据时间命名   简要命令: mv /usr/local/tengine/logs/access.l ...

  2. mongo日志切割脚本

    两种mongo日志切割脚本 vim /etc/logrotate.d/mongodb /home/mongodb/mongolog/mongod.log { daily rotate 7 compre ...

  3. Nginx日志切割,以及脚本上传nginx的切割日志

    一:日志切割步骤 命令都在root下进行 1.创建目录 mkdir -p /etc/opt/modules/bin ## 创建文件夹 2.上传cut 3.观察目录 4.修改的cut文件 5.检测 需要 ...

  4. Nginx 笔记与总结(5)访问日志管理:计划任务 + 日志切割

    要在第二天的凌晨把前一天的访问日志切割备份,并以时间作为文件名,例如:access.20150728.log,这就需要在 Linux 中格式化时间,例如: [root@localhost ~]# da ...

  5. apache日志切割

    一.日志切割 安装cronolog CentOS 5.4中编译安装Apache默认日志是不切割的,需要用用工具Cronnolog进行日志切割 1.下载及安装 wget http://cronolog. ...

  6. nginx日志切割并使用flume-ng收集日志

    nginx的日志文件没有rotate功能.如果你不处理,日志文件将变得越来越大,还好我们可以写一个nginx日志切割脚本来自动切割日志文件.第一步就是重命名日志文件,不用担心重命名后nginx找不到日 ...

  7. Nginx日志配置及日志切割

    日志配置 日志对于统计排错来说非常有利的.本文总结了nginx日志相关的配置如access_log.log_format.open_log_file_cache.log_not_found.log_s ...

  8. Nginx (二) Nginx的反向代理负载均衡以及日志切割

    Nginx是一个高并发,高性能的服务器,可以进行反向代理以及网站的负载均衡.这些功能的运用都在配置文件中,也就是Nginx安装目录下的conf/nginx.conf. nginx.conf 1. 先来 ...

  9. Tomcat6,7,8的日志切割

    使用的日志切割工具cronolog(yum就可以了) 确定好路径后,开始配置 Tomcat6 Tomcat6/bin/catalina.sh 292-317行(修改两处) 修改之后为下面的内容 # t ...

随机推荐

  1. Docker学习总结之docker创建私有仓库(private Repositories)

    Docker 创建 Private Repositories 前言 基于GFW的缘故,国内大陆基本无法pull国外的镜像,更别说官方的index了.如果images无法pull下来,那么docker就 ...

  2. linux mount一个硬盘

    我们在使用linux的情况下,难免有时会需要增加一块硬盘,在windows下增加硬盘很简单,所有的操作都是有画面.linux下增加一块硬盘,并且让这块硬盘可以正常的使用,所有的操作都在字符命令行的方式 ...

  3. 【三】MongoDB文档的CURD操作

    一.插入文档 使用insert方法插入文档到一个集合中,如果集合不存在创建集合,有以下几种方法: db.collection.insertOne({}):(v3.2 new)  #插入一个文档到集合中 ...

  4. Never Go Away

    Hey if you ever want to leave it allif you ever want to lose control leave it all escape so far away ...

  5. 汇编语言入门(在debug中编辑和调试程序)

    2013-06-02 17:09 4252人阅读 评论(2) 收藏 举报  分类: 汇编语言(1)  版权声明:本文为博主原创文章,未经博主允许不得转载. 我们在Windows中进入的Dos方式,实际 ...

  6. JSON与AJAX的使用

    主要内容: 一.JSON数据 二.JSON字符串与Java对象的相互转换 三.JSON字符串与JavaScript对象的相互转换 四.AJAX异步加载 一.JSON数据 1.JSON语法规则: 2.J ...

  7. HDU 1800 Flying to the Mars 字典树,STL中的map ,哈希树

    http://acm.hdu.edu.cn/showproblem.php?pid=1800 字典树 #include<iostream> #include<string.h> ...

  8. jquery插件之jquery.extend和jquery.fn.extend的区别

    jquery.extend jquery.extend(),是拓展jquery这个类,即可以看作是jquery这个类本身的静态方法,例如: <!DOCTYPE html> <html ...

  9. L106 Three things we learned from day one at the World Cup

    Hosts Russia got the World Cup off to a flying start by hammering Saudi Arabia 5-0 in the opening ga ...

  10. hdu-1025 Constructing Roads In JGShining's Kingdom(二分查找)

    题目链接: Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)     Memory Li ...