日志格式:
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 日志分析(一)的更多相关文章

  1. 如果"一切是IO"“一切是file”是成立的,那么上述的想法也一定可以实现吧 awk对apache日志分析 ---

    定时执行 自动化处理 直接入库 再去读取这个file入库: root@VM---ubuntu:/var/log/apache2# awk '{print $1 "\t" $7}' ...

  2. Apache日志分析

    Apache日志统计举例 加些来了解一下如何统计Apache的访问日志,一般可以用tail命令来实时查看日志文件变化,但是各种的应用系统中的日志会非常复杂,一堆长度超过你浏览极限的日志出现在你眼前时, ...

  3. Apache日志分析_shell命令行

    说明: 1.我的日志预先设定好按日生成文件:"CustomLog "|/opt/apache/bin/rotatelogs /opt/apache/logs/www.website ...

  4. Linux下apache日志分析与状态查看方法

    假设apache日志格式为:118.78.199.98 – - [09/Jan/2010:00:59:59 +0800] “GET /Public/Css/index.css HTTP/1.1″ 30 ...

  5. Linux 下 apache 日志分析与状态查看[转]

    假设apache日志格式为: 118.78.199.98 – - [09/Jan/2010:00:59:59 +0800] “GET /Public/Css/index.css HTTP/1.1″ 3 ...

  6. Nginx/Apache日志分析脚本

    1,查看apache进程: ps aux | grep httpd | grep -v grep | wc -l 2,查看80端口的tcp连接: netstat -tan | grep "E ...

  7. Apache 日志分析(二)

    01.查看IP cat access_log | awk ‘{print $1}’   02.对IP排序 cat access_log | awk ‘{print $1}’ | sort   03.打 ...

  8. Linux apache日志分析常用命令汇总

    1.查看当天有多少个IP访问: awk '{print $1}' log_file|sort|uniq|wc –l 2.查看某一个页面被访问的次数: grep "/index.php&quo ...

  9. elk系列7之通过grok分析apache日志

    preface 说道分析日志,我们知道的采集方式有2种: 通过grok在logstash的filter里面过滤匹配. logstash --> redis --> python(py脚本过 ...

随机推荐

  1. uva 542 - France '98(概率)

    题目链接:uva 542 - France '98 题目大意:有16支球队比赛,给出16支球队的名称,然后给出16*16的表格,g[i][j] 表示i队胜j队的概率,问说16支球队获得总冠军的概率. ...

  2. UI进阶 科大讯飞(2) 语音合成(文字转换成语音)

    科大讯飞开放平台.SDK下载.添加静态库.初始化见UI进阶 科大讯飞(1) 语音听写(语音转换成文字) 实现语音合成 功能实现步骤: 导入头文件 创建文字识别对象 指定文字识别后的回调代理对象 开启文 ...

  3. 结构类模式(三):组合(Composite)

    定义 将对象组合成树形结构以表示“部分整体”的层次结构.组合模式使得用户对单个对象和组合对象的使用具有一致性. 有时候又叫做部分-整体模式,它使我们树型结构的问题中,模糊了简单元素和复杂元素的概念,客 ...

  4. JedisPool连接池实现难点

    [http://jiangwenfeng762.iteye.com/blog/1280700]   [可改进的问题] 问题是jedispool有没有办法监控状态,比如说当前连接有多少,当前idle连接 ...

  5. 关于Java中的程序,进程和线程的详解...

    程序:一段静态的代码,一组指令的有序集合,它本身没有任何运行的含义,它只是一个静态的实体,是应用软件执行的蓝本. 进程:是程序的一次动态执行,它对应着从代码加载,执行至执行完毕的一个完整的过程,是一个 ...

  6. ASP.NET加载主题和皮肤样式的各种方式

    一.加载主题(皮肤.样式表)的多种方式 除了在页面指令中采用Theme或者StylesheetTheme为单个页面加载主题外,还可以通过配置文件为多个页面批量加载主题,另外,还可以通过改变页面的The ...

  7. codeforces 377A. Puzzles 水题

    A. Puzzles Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/33 ...

  8. 安卓开发之使用viewpager+fragment实现滚动tab页

    闲着.用viewpager+fragment实现了个滚动tab..轻拍,以后会陆续发先小东西出来..爱分享,才快乐.demo见附件.. package com.example.demo; import ...

  9. 关于JS的一点summary

    AJAX Application AJAX--->XML.HTML.JavaScript.JSON.Text.JSONP等数据. 同时代码即业务. code--->Business log ...

  10. [Angular2 Router] CanDeactivate Route Guard - How To Confirm If The User Wants To Exit A Route

    In this tutorial we are going to learn how we can to configure an exit guard in the Angular 2 Router ...