Apache 日志分析(一)
日志格式:
101.38.166.177 – –
[10/Jun/2016:14:19:19 +0800] “POST /wp-admin/admin-ajax.php HTTP/1.1”
200 112 “http://www.ko178.cn/wp-admin/post.php?post=20&action=edit”
“Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/47.0.2526.108 Safari/537.36 2345Explorer/7.1.0.12633”
访问次数最多的10个IP:
awk ‘{print $1}’ access_ko178.log |sort |uniq -c|sort -nr|head -n 10
cat access_ko178.log |cut -d ‘ ‘ -f 1 |sort |uniq -c | sort -nr | awk ‘{print $0 }’ | head -n 10
awk 首先将每条日志中的IP抓出来,如日志格式被自定义过,可以 -F 定义分隔符和 print指定列;
sort进行初次排序,为的使相同的记录排列到一起;
upiq -c 合并重复的行,并记录重复次数。
head进行前十名筛选;
sort -nr按照数字进行倒叙排序。
参考命令:
1.显示10条最常用的命令
sed -e “s#| /#n#g” ~/.bash_history | cut -d ‘ ‘ -f 1 | sort | uniq -c | sort -nr | head
2.访问次数最多的几个分钟:
awk ‘{print $4}’ access_ko178.log |cut -c 14-18|sort|uniq -c|sort -nr|head
awk 用空格分出来的第四列是[10/Jun/2016:00:59:59;
cut -c 提取14到18个字符
剩下的内容和问题1类似。
3.访问最多的页面:
awk ‘{print $11}’ access_ko178.log |sed ‘s#^.*cn/(.*/)/”#/1#g’|sort |uniq -c|sort -rn|head
类似问题1和2,唯一特殊是用sed的替换功能将”http://www.ko178.cn/index.php”替换成括号内的内
容:”http://www.ko178.cn(/index.php)”
访问次数最多(负载最重)的几个时间段(以分钟为单位),然后在看看这些时间哪几个IP访问的最多?
4.查看apache/nginx进程:
ps aux | grep httpd | grep -v grep | wc -l
ps aux | grep nginx | grep -v grep | wc -l
5.查看80端口的tcp连接:
netstat -tan | grep “ESTABLISHED” | grep “:80” | wc -l
6.通过日志查看当天ip连接数,过滤重复:
cat access_ko178.log|grep “10/Jun/2016” |awk ‘{print $2}’ |sort|uniq -c |sort -nr
7.当天ip连接数最高的ip都在干些什么(原来是蜘蛛):
cat access_ko178.log | grep “10/Jun/2016:00” | grep “176.31.129.248” | awk ‘{print $8}’ | sort | uniq -c | sort -nr | head -n 10
8.当天访问页面排前10的url:
cat access_ko178.log | grep “10/Jun/2016:00” | awk ‘{print $11}’ | sort | uniq -c | sort -nr | head -n 10
9.用tcpdump嗅探80端口的访问看看谁最高:
tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F”.” ‘{print $1″.”$2″.”$3″.”$4}’ | sort | uniq -c | sort -nr
10.查看该ip在干嘛:
cat access_ko178.log | grep 121.42.0.38| awk ‘{print $1″/t”$8}’ | sort | uniq -c | sort -nr | less
11.查看某一时间段的ip连接数:
grep “2016:0[7-8]” access_ko178.log | awk ‘{print $2}’ | sort | uniq -c| sort -nr | wc -l
12.当前WEB服务器中联接次数最多的20条ip地址:
netstat -ntu |awk ‘{print $5}’ |sort | uniq -c| sort -nr | head -n 20
13.查看日志中访问次数最多的前10个IP:
cat access_ko178.log |cut -d ‘ ‘ -f 1 |sort |uniq -c | sort -nr | awk ‘{print $0 }’ | head -n 10 |less
14.查看日志中出现100次以上的IP:
cat access_ko178.log |cut -d ‘ ‘ -f 1 |sort |uniq -c | awk ‘{if ($1 > 100) print $0}’|sort -nr |less
15.查看最近访问量最高的文件:
cat access_ko178.log |tail -10000|awk ‘{print $7}’|sort|uniq -c|sort -nr|less
cat access_ko178.log|awk ‘{print $7}’|uniq -c |sort -n -r|head -20
16.查看日志中访问超过100次的页面:
cat access_ko178.log | cut -d ‘ ‘ -f 7 | sort |uniq -c | awk ‘{if ($1 > 100) print $0}’ | less
17.列出传输时间超过 30 秒的文件:
cat access_ko178.log|awk ‘($NF > 30){print $7}’|sort -n|uniq -c|sort -nr|head -20
18.最最耗时的页面(超过60秒的)的以及对应页面发生次数:
cat access_ko178.log |awk ‘($NF > 60 && $7~/\.php/){print $7}’ |sort -n|uniq -c|sort -nr|head -100
19.列出传输时间超过 30 秒的文件
cat access_ko178.log|awk ‘($NF > 30){print $7}’ |sort -n|uniq -c|sort -nr|head -20
20.从日志里查看该ip在干嘛
cat access_ko178.log | grep 176.31.129.248| awk ‘{print $1″\t”$7}’ | sort | uniq -c | sort -nr | less
21.统计某url,一天的访问次数
cat access_ko178.log|grep ’10/Jun/2016’|grep ‘index.php’|wc|awk ‘{print $1}’
Apache 日志分析(一)的更多相关文章
- 如果"一切是IO"“一切是file”是成立的,那么上述的想法也一定可以实现吧 awk对apache日志分析 ---
定时执行 自动化处理 直接入库 再去读取这个file入库: root@VM---ubuntu:/var/log/apache2# awk '{print $1 "\t" $7}' ...
- Apache日志分析
Apache日志统计举例 加些来了解一下如何统计Apache的访问日志,一般可以用tail命令来实时查看日志文件变化,但是各种的应用系统中的日志会非常复杂,一堆长度超过你浏览极限的日志出现在你眼前时, ...
- Apache日志分析_shell命令行
说明: 1.我的日志预先设定好按日生成文件:"CustomLog "|/opt/apache/bin/rotatelogs /opt/apache/logs/www.website ...
- Linux下apache日志分析与状态查看方法
假设apache日志格式为:118.78.199.98 – - [09/Jan/2010:00:59:59 +0800] “GET /Public/Css/index.css HTTP/1.1″ 30 ...
- Linux 下 apache 日志分析与状态查看[转]
假设apache日志格式为: 118.78.199.98 – - [09/Jan/2010:00:59:59 +0800] “GET /Public/Css/index.css HTTP/1.1″ 3 ...
- Nginx/Apache日志分析脚本
1,查看apache进程: ps aux | grep httpd | grep -v grep | wc -l 2,查看80端口的tcp连接: netstat -tan | grep "E ...
- Apache 日志分析(二)
01.查看IP cat access_log | awk ‘{print $1}’ 02.对IP排序 cat access_log | awk ‘{print $1}’ | sort 03.打 ...
- Linux apache日志分析常用命令汇总
1.查看当天有多少个IP访问: awk '{print $1}' log_file|sort|uniq|wc –l 2.查看某一个页面被访问的次数: grep "/index.php&quo ...
- elk系列7之通过grok分析apache日志
preface 说道分析日志,我们知道的采集方式有2种: 通过grok在logstash的filter里面过滤匹配. logstash --> redis --> python(py脚本过 ...
随机推荐
- hdoj 5392 Infoplane in Tina Town
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5392 #include<stdio.h> #include<cstring> ...
- 使用struts2实现文件下载
<action name="downloadAction" class=""> <result type="stream" ...
- android 工具类之图片加工
/** * 图片加工厂 * * @author way * */ public class ImageUtil { /** * 通过路径获取输入流 * * @param path * 路径 * @re ...
- 国内外从事CV相关的企业[转]
提示:本文为笔者原创,转载请注明出处:blog.csdn.net/carson2005 经常碰到朋友问我国内从事计算机视觉(CV)领域的公司的发展情况,产品情况,甚至找工作等问题,这里,我给出自己收集 ...
- 转载:页面加载swf插件:swfobject
转自:http://www.cnblogs.com/analyzer/articles/1299592.html 我一直都在用SWFObject 插入flash,好处多多,代码简洁,不会出现微软的“单 ...
- The Aggregate Magic Algorithms
http://aggregate.org/MAGIC/ The Aggregate Magic Algorithms There are lots of people and places that ...
- A few things to remember while coding in Python.
A few things to remember while coding in Python. - 17 May 2012 - UPDATE: There has been much discuss ...
- PHP网址
15个魔术方法的总结: http://blog.csdn.net/bossdarcy/article/details/6210794 PHP代码重构:http://blog.csdn.net/tony ...
- 【转】JAVA SSH 框架介绍
转自:http://www.admin10000.com/document/150.html SSH 为 struts+spring+hibernate 的一个集成框架,是目前较流行的一种JAVA W ...
- cdoj 65 CD Making 水题
CD Making Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/65 De ...