Merge pull request #2566 from disylee/master

disylee update
This commit is contained in:
Xingyu.Wang 2015-03-30 13:30:14 +08:00
commit 8ff45c670b
2 changed files with 167 additions and 144 deletions

View File

@ -1,144 +0,0 @@
disylee 来一篇~
How to analyze and view Apache web server logs interactively on Linux
================================================================================
Whether you are in the web hosting business, or run a few web sites on a VPS yourself, chances are you want to display visitor statistics such as top visitors, requested files (dynamic or static), used bandwidth, client browsers, and referring sites, and so forth.
[GoAccess][1] is a command-line log analyzer and interactive viewer for Apache or Nginx web server. With this tool, you will not only be able to browse the data mentioned earlier, but also parse the web server logs to dig for further data as well - and **all of this within a terminal window in real time**. Since as of today [most web servers][2] use either a Debian derivative or a Red Hat based distribution as the underlying operating system, I will show you how to install and use GoAccess in Debian and CentOS.
### Installing GoAccess on Linux ###
In Debian, Ubuntu and derivatives, run the following command to install GoAccess:
# aptitude install goaccess
In CentOS, you'll need to enable the [EPEL repository][3] and then:
# yum install goaccess
In Fedora, simply use yum command:
# yum install goaccess
If you want to install GoAccess from the source to enable further options (such as GeoIP location), install [required dependencies][4] for your operating system, and then follow these steps:
# wget http://tar.goaccess.io/goaccess-0.8.5.tar.gz
# tar -xzvf goaccess-0.8.5.tar.gz
# cd goaccess-0.8.5/
# ./configure --enable-geoip
# make
# make install
That will install version 0.8.5, but you can always verify what is the latest version in the [Downloads page][5] of the project's web site.
Since GoAccess does not require any further configurations, once it's installed you are ready to go.
### Running GoAccess ###
To start using GoAccess, just run it against your Apache access log.
For Debian and derivatives:
# goaccess -f /var/log/apache2/access.log
For Red Hat based distros:
# goaccess -f /var/log/httpd/access_log
When you first launch GoAccess, you will be presented with the following screen to choose the date and log format. As explained, you can toggle between options using the spacebar and proceed with F10. As for the date and log formats, you may want to refer to the [Apache documentation][6] if you need to refresh your memory.
In this case, Choose Common Log Format (CLF):
![](https://farm8.staticflickr.com/7422/15868350373_30c16d7c30.jpg)
and then press F10. You will be presented with the statistics screen. For the sake of brevity, only the header, which shows the summary of the log file, is shown in the next image:
![](https://farm9.staticflickr.com/8683/16486742901_7a35b5df69_b.jpg)
### Browsing Web Server Statistics with GoAccess ###
As you scroll down the page with the down arrow, you will find the following sections, sorted by requests. The order of the categories presented here may vary depending on your distribution or your preferred installation method (from repositories or from source):
1. Unique visitors per day (HTTP requests having the same IP, same date and same agent are considered an unique visit)
![](https://farm8.staticflickr.com/7308/16488483965_a439dbc5e2_b.jpg)
2. Requested files (Pages-URL)
![](https://farm9.staticflickr.com/8651/16488483975_66d05dce51_b.jpg)
3. Requested static files (e.g., .png, .js, etc)
4. Referrers URLs (the URLs where each request came from)
5. HTTP 404 Not Found response code
![](https://farm9.staticflickr.com/8669/16486742951_436539b0da_b.jpg)
6. Operating Systems
7. Browsers
8. Hosts (client IPs)
![](https://farm8.staticflickr.com/7392/16488483995_56e706d77c_z.jpg)
9. HTTP status codes
![](https://farm8.staticflickr.com/7282/16462493896_77b856f670_b.jpg)
10. Top referring sites
11. Top keyphrases used on Google's search engine
If you also want to inspect the archived logs, you can pipe them to GoAccess as follows.
For Debian and derivatives:
# zcat -f /var/log/apache2/access.log* | goaccess
For Red Hat based distributions:
# cat /var/log/httpd/access* | goaccess
Should you need a more detailed report of any of the above (1 through 11), press the desired section number and then O (uppercase o) to bring up what is called the Detailed View. The following image shows the output of 5-O (press 5, then press O):
![](https://farm8.staticflickr.com/7382/16302213429_48d9233f40_b.jpg)
To display GeoIP location information, open the Detail View in the Hosts section, as explained earlier, and you will see the location of the client IPs that performed requests to your web server:
![](https://farm8.staticflickr.com/7393/16488484075_d778aa91a2_z.jpg)
If your system has not been very busy lately, some of the above sections will not show a great deal of information, but that situation can change as more and more requests are made to your web server.
### Saving Reports for Offline Analysis ###
There will be times when you don't want to inspect your system's stats in real time, but save it to a file for offline analysis or printing. To generate an HTML report, simply redirect the output of the GoAccess commands mentioned earlier to an HTML file. Then just point your web browser to the file to open it.
# zcat -f /var/log/apache2/access.log* | goaccess > /var/www/webserverstats.html
Once the report is displayed, you will need to click on the Expand link to show the detail view on each category:
![](https://farm9.staticflickr.com/8658/16486743041_bd8a80794d_o.png)
注释youtube视频
<iframe width="615" height="346" frameborder="0" allowfullscreen="" src="https://www.youtube.com/embed/UVbLuaOpYdg?feature=oembed"></iframe>
As we have discussed throughout this article, GoAccess is an invaluable tool that will provide you, as a system administrator, with HTTP statistics in a visual report on the fly. Although GoAccess by default presents its results to the standard output, you can also save them to JSON, HTML, or CSV files. This converts GoAccess in an incredibly useful tool to monitor and display statistics of a web server.
--------------------------------------------------------------------------------
via: http://xmodulo.com/interactive-apache-web-server-log-analyzer-linux.html
作者:[Gabriel Cánepa][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://xmodulo.com/author/gabriel
[1]:http://goaccess.io/
[2]:http://w3techs.com/technologies/details/os-linux/all/all
[3]:http://xmodulo.com/how-to-set-up-epel-repository-on-centos.html
[4]:http://goaccess.io/download#dependencies
[5]:http://goaccess.io/download
[6]:http://httpd.apache.org/docs/2.4/logs.html

View File

@ -0,0 +1,167 @@
如何在Linux中以交互方式分析和查看Apache web服务器日志?
================================================================================
无论你是在网站托管业务还是在自己的VPS上运行几个网站你总会有机会想要显示访客数量例如前几的房客请求使用的文件无论是动态或者是静态带宽的使用客户端的浏览器和相关的网站等等。
[GoAccess][1] 是一款用于Apache或者Nginx命令行日志分析和交互式查看器。有了这款工具你不仅可以浏览到之前提及的相关数据还可以分析网站服务器日志来进一步挖掘数据 - 然而 **这一切都可以在一个终端窗口实时输出**.由于今天的[大多数web服务器][2]使用一个Debian的衍生版或者基于红帽发行版来作为底层操作系统我将会告诉你如何在Debian和CentOS中安装和使用GoAccess。
### 在Linux系统安装GoAccess ###
在DebianUbuntu及其衍生版本运行一下命令来安装GoAccess
# aptitude install goaccess
在CentOS中你将需要使你的[EPEL 仓库][3]可用然后执行以下命令:
# yum install goaccess
在Fedora同样使用yum命令
# yum install goaccess
如果你想从源码安装GoAccess来使后续的功能可用例如 GeoIP 的位置),为你的操作系统安装[必需的依赖包][4],按以下步骤进行:
# wget http://tar.goaccess.io/goaccess-0.8.5.tar.gz
# tar -xzvf goaccess-0.8.5.tar.gz
# cd goaccess-0.8.5/
# ./configure --enable-geoip
# make
# make install
以上安装的版本是 0.8.5,但是你也可以在该软件的网站[下载页][5]确认是否是最新版本。
由于GoAccess不需要后续的配置一旦安装你就可以马上使用。
### 运行 GoAccess ###
开始使用GoAccess只需要对它运行你的Apache访问日志。
对于Debian及其衍生版本
# goaccess -f /var/log/apache2/access.log
基于红帽的发型版本:
# goaccess -f /var/log/httpd/access_log
当你第一次启动GoAccess你将会看到下方屏幕中选择日期和日志格式。正如前面所述你可以选择在空格键和F10之间相互切换。至于日期和日志格式你可能希望参考[Apache 文档][6]来刷新你的记忆。
在这个例子中选择常见日志格式CLI
![](https://farm8.staticflickr.com/7422/15868350373_30c16d7c30.jpg)
然后按F10.你将会从屏幕中获得统计数据。为了简约,只显示首部,也就是总结日志文件的摘要,如下图所示:
![](https://farm9.staticflickr.com/8683/16486742901_7a35b5df69_b.jpg)
### 通过 GoAccess来浏览网站服务器统计数据 ###
当你通过向下的剪头滚动页面,你会发现一下章节,按要求进行排序。这里提及的目录顺序可能会根据你的发型版本或者(从源和库)首选的安装方式:
1. 每天唯一访客具有同样IP同一日期和统一代理被认为是
![](https://farm8.staticflickr.com/7308/16488483965_a439dbc5e2_b.jpg)
2. 请求的文件网页URL
![](https://farm9.staticflickr.com/8651/16488483975_66d05dce51_b.jpg)
3. 请求的静态文件(例如,.png文件.js文件等等
4. 请求的URLs每一个URL请求的出处
5. HTTP 404 不能找到响应的代码
![](https://farm9.staticflickr.com/8669/16486742951_436539b0da_b.jpg)
6. 操作系统
7. 浏览器
8. 主机客户端IP地址
![](https://farm8.staticflickr.com/7392/16488483995_56e706d77c_z.jpg)
9. HTTP 状态代码
![](https://farm8.staticflickr.com/7282/16462493896_77b856f670_b.jpg)
10. 前几位的推荐站点
11. 在谷歌的搜索引擎使用的排名在前的关键字
如果你还想检查已经存档的日志你可以在GoAccess通过使用管道符号如下。
在Debian及其衍生版本
# zcat -f /var/log/apache2/access.log* | goaccess
在基于红帽的发型版本:
# cat /var/log/httpd/access* | goaccess
如果你需要任何更多关于以上的详细报告1至11项直接按下章节序号再按O大写o就可以显示出你需要的详细视图。下面的图像显示5-O的输出先按5再按O
![](https://farm8.staticflickr.com/7382/16302213429_48d9233f40_b.jpg)
如果要现实GeoIP位置信息打开详细视图的主机部分如前面所述你将会看到客户端IP地址所在的位置以及显示web服务器的请求。
![](https://farm8.staticflickr.com/7393/16488484075_d778aa91a2_z.jpg)
如果你的系统还尚未达到很忙碌的状态,以上提及的章节将不会显示大量的信息,但是这种情形可以通过在你网站服务器越来越多的请求发生改变。
### 在线保存分析的报告
当然有时候你不想每次都实时去检查你的系统状态但是保存一份在线的分析文件或者打印版是由必要的。要生成一个HTML报告只需要通过之前提到GoAccess命令输出来简单地重定向道一个HTML文件。然后你只需通过web浏览器来将这份报告打开即可。
# zcat -f /var/log/apache2/access.log* | goaccess > /var/www/webserverstats.html
一旦报告生成,你将需要点击展开的链接来显示每个类别详细的视图信息:
![](https://farm9.staticflickr.com/8658/16486743041_bd8a80794d_o.png)
注释youtube视频
<iframe width="615" height="346" frameborder="0" allowfullscreen="" src="https://www.youtube.com/embed/UVbLuaOpYdg?feature=oembed"></iframe>
正如我们通过这篇文章讨论GoAccess是一个非常可贵的工具它提供给作为百忙之中的系统管理员一份HTTP统计的静态可是报告。虽然GoAccess默认其输出结果为标准输出但是你也可以将他们保存到JSONHTML或者CSV文件。这样的转换GoAccess将作为一个非常有用的工具来监控和显示网站服务器的统计数据。
--------------------------------------------------------------------------------
via: http://xmodulo.com/interactive-apache-web-server-log-analyzer-linux.html
作者:[Gabriel Cánepa][a]
译者:[disylee](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://xmodulo.com/author/gabriel
[1]:http://goaccess.io/
[2]:http://w3techs.com/technologies/details/os-linux/all/all
[3]:http://xmodulo.com/how-to-set-up-epel-repository-on-centos.html
[4]:http://goaccess.io/download#dependencies
[5]:http://goaccess.io/download
[6]:http://httpd.apache.org/docs/2.4/logs.html