转载本站文章请注明,转载自: 月影鹏鹏 [http://Jacky.Aiwaly.com]
本文链接: http://jk.aiwaly.com/wp/linux%e8%84%9a%e6%9c%ac%e5%af%b9%e6%97%a5%e5%bf%97%e5%88%86%e6%9e%90.html
有了日志文件后,我们可以利用UNIX的一些工具和一此专门的日志分析工具对
日志文件进行分析。
实例一:列出访问过本网站的主机名或IP:
对于这个需求,我们可以通过一个Unix的一个脚本语句来完成:
cat /var/log/httpd/access_log | awk ‘{print $1}’
用上面的方法虽然可以得到访问过本网站的主机名或IP,但是由于有些是多次
访问的,我们希望在上面得到的结果的基础上做一些优化,使得列出的表中,
每个主机只出现一次。我们可以使用:
cat /var/log/httpd/access_log | awk ‘{print $1}’ | wc -l
3. 当然,我们可以根据需要选择第三方提供日志分析工具甚至自己开发一些日
3. 志分析工具来满足我们的需求。常见的第三方日志分析工具有:WebTrends、
3. Wusage、wwwstat、http-analyze、pwebstats、WebStat Explorer、
3. AccessWatch。
计算独立ip 数实例
[wangpeng@www ~]$ cat /var/log/httpd/access_scanmon.com_log.2006-05-25-00_00_00 | awk ‘{print $1}’ | sort | uniq -c | sort -n | wc -l
91
统计apache 日志中 访问独立ip个数 (排除搜索引擎 本地ip)
#cat access_scanmon.comlog.2006-06-02-00_00_00 | grep -v “Baiduspider+(+http://www.baidu.com/search/spider.htm)” | grep -v “msnbot/1.0 (+http://search.msn.com/msnbot.htm)” | grep -v “Mozilla/5.0 (compatible; Yahoo! Slurp China; http://misc.yahoo.com.cn/help.html)” | grep -v “Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)” | grep -v “mp3Spider cn-search-devel at yahoo-inc dot com” | grep -v “mp3Spider cn-search-devel at yahoo-inc dot com” | grep -v “Openfind data gatherer, Openbot/3.0+(robot-response@openfind.com.tw;+http://www.openfind.com.tw/robot.html)” | grep -v “Apache/2.2.0 (Unix) (internal dummy connection)” |grep -v 221.221 | awk ‘{print $1}’ | sort | uniq -c | sort -n | wc -l
搜索引擎信息
“Baiduspider+(+http://www.baidu.com/search/spider.htm)”
“msnbot/1.0 (+http://search.msn.com/msnbot.htm)”
“Mozilla/5.0 (compatible; Yahoo! Slurp China; http://misc.yahoo.com.cn/help.html)”
“Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)”
“GET / HTTP/1.1″ 200 71619 “-” “mp3Spider cn-search-devel at yahoo-inc dot com”
“Openfind data gatherer, Openbot/3.0+(robot-response@openfind.com.tw;+http://www.openfind.com.tw/robot.html)”