一.日志分析
如果apache的安裝時采用默認的配置,那么在/logs目錄下就會生成兩個文件,分別是access_log和error_log
1).access_log
access_log為訪問日志,記錄所有對apache服務器進行請求的訪問,它的位置和內容由CustomLog指令控制,LogFormat指令可以用來簡化該日志的內容和格式
例如,我的其中一臺服務器配置如下:
復制代碼 代碼如下:
CustomLog "| /usr/sbin/rotatelogs /var/log/apache2/%Y_%m_%d_other_vhosts_access.log 86400 480" vhost_combined
-rw-r--r-- 1 root root 22310750 12-05 23:59 2010_12_05_other_vhosts_access.log
-rw-r--r-- 1 root root 26873180 12-06 23:59 2010_12_06_other_vhosts_access.log
-rw-r--r-- 1 root root 26810003 12-07 23:59 2010_12_07_other_vhosts_access.log
-rw-r--r-- 1 root root 24530219 12-08 23:59 2010_12_08_other_vhosts_access.log
-rw-r--r-- 1 root root 24536681 12-09 23:59 2010_12_09_other_vhosts_access.log
-rw-r--r-- 1 root root 14003409 12-10 14:57 2010_12_10_other_vhosts_access.log
#通過CustomLog指令,每天一天生成一個獨立的日志文件,同時也寫了定時器將一周前的日志文件全部清除,這樣可以顯得更清晰,既可以分離每一天的日志又可以清除一定時間以前的日志通過制,LogFormat定義日志的記錄格式
LogFormat "%h %l %u %t /"%r/" %>s %b /"%{Referer}i/" /"%{User-Agent}i/"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t /"%r/" %>s %b /"%{Referer}i/" /"%{User-Agent}i/"" combinedproxy
LogFormat "%h %l %u %t /"%r/" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
隨意的tail一個access_log文件,下面是一條經典的訪問記錄
復制代碼 代碼如下:
218.19.140.242 - - [10/Dec/2010:09:31:17 +0800] "GET /query/trendxml/district/todayreturn/month/2009-12-14/2010-12-09/haizhu_tianhe.xml HTTP/1.1" 200 1933 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729)"
一共是有9項,將他們一一拆開來說明:
復制代碼 代碼如下:
218.19.140.242
-
-
[10/Dec/2010:09:31:17 +0800]
"GET /query/trendxml/district/todayreturn/month/2009-12-14/2010-12-09/haizhu_tianhe.xml HTTP/1.1"
200
1933
"-"
"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729)"
1) 218.19.140.242 這是一個請求到apache服務器的客戶端ip,默認的情況下,第一項信息只是遠程主機的ip地址,但我們如果需要apache查出主機的名字,可以將 HostnameLookups設置為on,但這種做法是不推薦使用,因為它大大的減緩了服務器.另外這里的ip地址不一定就是客戶主機的ip地址,如果 客戶端使用了代理服務器,那么這里的ip就是代理服務器的地址,而不是原機.
2) - 這一項是空白,使用"-"來代替,這個位置是用于標注訪問者的標示,這個信息是由identd的客戶端存在,除非IdentityCheck為on,非則apache是不會去獲取該部分的信息(ps:不太理解,基本上這一項都是為空,奉上原文)
The "hyphen" in the output indicates that the requested piece of information is not available. In this case, the information that is not available is the RFC 1413 identity of the client determined by identd on the clients machine. This information is highly unreliable and should almost never be used except on tightly controlled internal networks. Apache httpd will not even attempt to determine this information unless IdentityCheck is set to On.
新聞熱點
疑難解答