现在的位置: 首页 > 综合 > 正文

Apache学习笔记(四)Apache日志文件

2017年11月28日 ⁄ 综合 ⁄ 共 4540字 ⁄ 字号 评论关闭

Apache服务器运行后会生成两个日志文件,这两个文件是access_log(访问日志)和error_log(错误日志)。


一、访问日志文件access_log

access_log是apache的访问日志,就是记录Web服务器的所有访问活动,如下所示:

[root@apache logs]# cat access_log
192.168.1.103 - - [16/Mar/2014:21:20:35 +0800] "GET /favicon.ico HTTP/1.1" 404 209
192.168.1.103 - - [16/Mar/2014:21:20:36 +0800] "GET / HTTP/1.1" 200 45
127.0.0.1 - - [20/Mar/2014:20:52:17 +0800] "GET /server-status HTTP/1.1" 404 211
192.168.1.102 - - [20/Mar/2014:20:55:39 +0800] "GET /favicon.ico HTTP/1.1" 404 209
192.168.1.102 - - [20/Mar/2014:20:55:45 +0800] "GET / HTTP/1.1" 200 45
192.168.1.102 - - [20/Mar/2014:20:55:54 +0800] "GET /~root HTTP/1.1" 404 203
192.168.1.102 - - [20/Mar/2014:20:57:55 +0800] "GET /~lee HTTP/1.1" 404 202
192.168.1.102 - - [20/Mar/2014:20:58:43 +0800] "GET /~lee HTTP/1.1" 404 202
192.168.1.102 - - [20/Mar/2014:20:58:44 +0800] "GET /~lee HTTP/1.1" 404 202
192.168.1.102 - - [20/Mar/2014:20:58:47 +0800] "GET / HTTP/1.1" 200 45
127.0.0.1 - - [23/Mar/2014:20:35:32 +0800] "GET /server-status HTTP/1.1" 404 211

从文件内容可以看出,每一行记录了一次访问记录,由7部分组成,格式为:

客户端地址 访问者的标识 访问者的验证名字 请求的时间 请求类型 请求的HTTP代码 发送给客户端的字节数

说明:
1、客户端地址
表明访问网站的客户端的IP地址;
2、访问者的标识
该项一般为空白,用“-”替代;
3、访问者的验证名字
该项用于记录访问者进行身份验证时提供的名字,一般情况下该项也为空白;
4、请求的时间
记录访问操作的发生时间;
5、请求类型
该项记录了服务器收到的是一个什么类型的请求,一般类型包括GET、POST或者HEAD;
6、请求的HTTP代码
通过该项信息可以知道请求是否成功,或者遇到了什么样的错误,正常情况下,该项值为200;
7、发送给客户端的字节数
表示发送给客户端的总的字节数,通过检查该数值是否和文件大小相同,可以知道传输是否被中断。

二、错误日志文件error_log

错误日志是Apache提供的一种标准日志,该日志记录了apache服务器运行过程中所发生的错误信息。在httpd.conf配置文件中提供了以下两个配置参数:

ErrorLog "logs/error_log"#配置错误日志的位置
LogLevel warn#错误日志级别

关于日志级别如下所示:

严重程度 等级 说明
1 emerg 系统不可用
2 alert 需要立即引起注意的情况
3 crit 危急情况
4 error 错误信息
5 warn 警告信息
6 notice 需要引起注意的情况
7 info 一般信息
8 debug 由运行于debug模式的程序输出的信息

说明:
       如果用户把错误日志设置成warn级别,则严重程度由1~5的所有错误信息都会被记录下来。
       error_log日志的内容如下所示:

[root@apache logs]# cat error_log 
[Sun Mar 16 21:12:56.185456 2014] [mpm_worker:notice] [pid 25317:tid 3086522112] AH00292: Apache/2.4.7 (Unix) configured -- resuming normal operations
[Sun Mar 16 21:12:56.185679 2014] [core:notice] [pid 25317:tid 3086522112] AH00094: Command line: '/usr/local/apache2/bin/httpd'
[Sun Mar 16 21:13:29.562608 2014] [mpm_worker:notice] [pid 25317:tid 3086522112] AH00298: SIGHUP received. Attempting to restart
AH00557: httpd: apr_sockaddr_info_get() failed for apache
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
[Sun Mar 16 21:13:29.846077 2014] [mpm_worker:notice] [pid 25317:tid 3086522112] AH00292: Apache/2.4.7 (Unix) configured -- resuming normal operations
[Sun Mar 16 21:13:29.846126 2014] [core:notice] [pid 25317:tid 3086522112] AH00094: Command line: '/usr/local/apache2/bin/httpd'
[Sun Mar 16 23:59:14.334518 2014] [mpm_worker:notice] [pid 25317:tid 3086522112] AH00295: caught SIGTERM, shutting down
[Mon Mar 17 22:56:23.201217 2014] [mpm_worker:notice] [pid 3478:tid 3085915904] AH00292: Apache/2.4.7 (Unix) configured -- resuming normal operations
[Mon Mar 17 22:56:23.216647 2014] [core:notice] [pid 3478:tid 3085915904] AH00094: Command line: '/usr/local/apache2/bin/httpd'
[Tue Mar 18 00:48:06.781916 2014] [mpm_worker:notice] [pid 3478:tid 3085915904] AH00295: caught SIGTERM, shutting down
[Thu Mar 20 20:34:23.092716 2014] [mpm_worker:notice] [pid 3472:tid 3086812928] AH00292: Apache/2.4.7 (Unix) configured -- resuming normal operations
[Thu Mar 20 20:34:23.105434 2014] [core:notice] [pid 3472:tid 3086812928] AH00094: Command line: '/usr/local/apache2/bin/httpd'
[Thu Mar 20 20:52:04.982559 2014] [mpm_worker:notice] [pid 3472:tid 3086812928] AH00298: SIGHUP received. Attempting to restart
[Thu Mar 20 20:52:04.993212 2014] [mpm_worker:notice] [pid 3472:tid 3086812928] AH00292: Apache/2.4.7 (Unix) configured -- resuming normal operations
[Thu Mar 20 20:52:04.993252 2014] [core:notice] [pid 3472:tid 3086812928] AH00094: Command line: '/usr/local/apache2/bin/httpd'
[Thu Mar 20 20:57:42.188343 2014] [mpm_worker:notice] [pid 3472:tid 3086812928] AH00298: SIGHUP received. Attempting to restart
[Thu Mar 20 20:57:42.192459 2014] [mpm_worker:notice] [pid 3472:tid 3086812928] AH00292: Apache/2.4.7 (Unix) configured -- resuming normal operations
[Thu Mar 20 20:57:42.192476 2014] [core:notice] [pid 3472:tid 3086812928] AH00094: Command line: '/usr/local/apache2/bin/httpd'
[Thu Mar 20 23:30:23.427000 2014] [mpm_worker:notice] [pid 3472:tid 3086812928] AH00295: caught SIGTERM, shutting down
[Sun Mar 23 20:33:58.121754 2014] [mpm_worker:notice] [pid 3468:tid 3086468864] AH00292: Apache/2.4.7 (Unix) configured -- resuming normal operations
[Sun Mar 23 20:33:58.125171 2014] [core:notice] [pid 3468:tid 3086468864] AH00094: Command line: '/usr/local/apache2/bin/httpd'

从文件内容可以看出,每一行记录了一个错误,由3个部分组成,格式如下所示:

时间 错误等级 错误信息

例如,下面的一条错误信息:

[Sun Mar 23 20:33:58.125171 2014] [core:notice] [pid 3468:tid 3086468864] AH00094: Command line: '/usr/local/apache2/bin/httpd'

说明:
1、表示发生错误的时间:[Sun Mar 23 20:33:58.125171 2014] ;
2、表示错误的级别:[core:notice] ;
3、表示错误的内容:[pid 3468:tid 3086468864] AH00094: Command line: '/usr/local/apache2/bin/httpd'

抱歉!评论已关闭.