Linux 日誌分析工具之awstats

1、awstats 是什麼

        官方網站:AWStats is a free powerful and featureful tool that generates advanced web, streaming, ftp or mail server statistics, graphically. This log analyzer works as a CGI or from command line and shows you all possible information your log contains, in few graphical webb pages. It uses a partial information file to be able to process large log files, often and quickly. It can analyze log files from all major server tools like Apache log files (NCSA combined/XLF/ELF log format or common/CLF log format), WebStar, IIS(W3C log format) and a lot of other web, proxy, wap, straming servers, mail servers and some ftp servers.php

        Awstats 是一個免費的日誌分析工具,用perl開發。能夠用於分析各類linux下的應用程序產生的日誌,包括 apache/squid/samba/resin/tomcat 等等。在這裏,咱們主要用它來分析apache日誌。css

        統計包括訪問,訪問者,頁面,點擊,高峯時間,操做系統,瀏覽器,搜索引擎,關鍵字,機器人訪問,端開的連接和更多的阻力截圖排序。html

        Awstats是一個很是簡潔並且強大的統計工具。它能夠統計您站點的以下信息:mysql

一:訪問量,訪問次數,頁面瀏覽量,點擊數,數據流量等精確到每個月、每日、每小時的數據
二:訪問者國家、訪問者IP、操做系統、瀏覽器等
三:Robots/Spiders的統計
四:紡客持續時間
五:對不一樣Files type 的統計信息
六:Pages-URL的統計
七:其它信息(搜索關鍵字等等) linux

  • 訪問次數、獨特訪客人數,nginx

  • 訪問時間和上次訪問,web

  • 使用者認證、最近認證的訪問,sql

  • 每週的高峯時間(頁數,點擊率,每小時和一週的千字節),數據庫

  • 域名/國家的主機訪客(頁數,點擊率,字節,269域名/國家檢測, geoip 檢測),apache

  • 主機名單,最近訪問和未解析的 IP 地址名單

  • 大多數看過的進出頁面,

  • 檔案類型,

  • 網站壓縮統計表(mod_gzip 或者 mod_deflate),

  • 使用的操做系統 (每一個操做系統的頁數,點擊率 ,字節, 35 OS detected),

  • 使用的瀏覽器,

  • 機器人訪問(檢測 319 個機器人),

  • 蠕蟲攻擊 (5 個蠕蟲家族),

  • 搜索引擎,利用關鍵詞檢索找到你的地址,

  • HTTP 協議錯誤(最近查閱沒有找到的頁面),

  • 其餘基於 URL 的個性報導,連接參數, 涉及綜合行銷領域目的.

  • 貴網站被加入"最喜好的書籤".次數.

  • 屏幕大小(須要在索引頁補充一些 HTML 標籤).

  • 瀏覽器的支持比例: Java, Flash, RealG2 reader, Quicktime reader, WMA reader, PDF reader.

  • 負載平衡服務器比率集羣報告.

 

        Awstats 的運行須要 perl 環境的支持,從awstats 官方文檔來看,它對apache http server 的支持是很是完美的。若是使用的 nginx,要運行awstats有點麻煩。首先nginx對perl 的支持是比較弱的,甚至官方也不建議使用;另外在日誌格式上須要修改後才能正常運行。

awstats官方網站: http://awstats.sourceforge.net/   

perl官方網站: http://www.perl.com/    

awstats項目地址:http://sourceforge.net/projects/awstats/

 

 

2、awstats 工做原理以及其餘同類軟件

        AWStats的功能不少,我在此主要用它來分析apache服務器的日誌。安裝使用以前仍是說說大體的工做原理,AWStats提供一系列的perl腳本實現:服務配置,日誌讀取,報表生成等功能。

        而功能實現的具體執行過程是:首先,固然是apache將訪問狀況記錄到日誌中,AWStats每次執行更新時讀取這些日誌,分析日誌數據,將結果存儲到數據庫中,(這個數據庫是AWStats自帶的【就是一文本文件】,並不須要第三方軟件支持。),最後AWStats提供一個cgi程序經過web頁面來顯示數據庫中所統計的數據。

 

AWStats的工做模式是這樣的:

分析日誌:運行後將日誌統計結果歸檔到一個AWStats的數據庫(純文本)裏;

輸出日誌:分兩種形式

  • 一種是經過cgi程序讀取統計結果數據庫輸出(Linux中);

  • 一種是運行後臺腳本將輸出導出成靜態文件(Windows中);

其餘同類日誌統計分析工具備:

  • AWStats

  • Analog

  • Webalizer

 

 

3、awstats 安裝和配置

環境信息約定:

  • 日誌文件位置:/usr/local/apache/logs

  • 系統:CentOS6.5 X64

  • awstats安裝位置:/usr/local/awstats

  • JAWStats安裝位置:/htdoc/stats/

  • 這裏咱們配置的站點域名:www.test.com

  • WEB服務器:Apache 2.2

  • 靜態頁面文件輸出路徑:/usr/local/apache/data(可選)

 

Requirements:

To use AWStats, you need the following requirements:

  • Your server must log web access in a log file you can read.

  • You must be able to run perl scripts(.pl files) from command line and / or as CGI(Perl 5.007003 or higher required to run AWStats 6.9 or higher)

If not, you can solve this by downloading last Perl version at  ActivePerl (Win32) or  Perl.com(Unix/Linux/Other)

一、安裝 perl

awstats 是由 perl 語言編寫的,無論是在Windows仍是Linux下,都須要安裝perl。因此要首先準備好 perl 環境,一般linux系統都是自帶了perl的。

# perl --version # 查看是否已經安裝了perl, 以及perl 版本號 # yum -y install perl* # 若是沒有安裝,yum install 吧
 

二、下載 awstats 工具(Last stable version is 7.4),並解壓至常規目錄 /usr/local

# wget http://www.awstats.org/files/awstats-7.4.tar.gz # tar xf awstats-7.4.tar.gz # mv awstats-7.4 /usr/local/awstats ################ 華麗的分割線 ############### # 固然,也能夠經過 yum 安裝 # yum -y install awstats
 

三、安裝 awstats

因爲 wget 下來的包文件的權限是非 root用戶的,因此須要修改權限,不然稍後 *.pl 沒法運行。

# mkdir /etc/awstats # mkdir /var/lib/awstats # chown apache:apache /var/lib/awstats 上面建立的兩個目錄都將在後面的配置中用到,一個用於存放站點日誌分析的配置文件,一個用於存放日誌數據信息。 接下來執行 /usr/local/awstats/tools下的awstats_configure.pl 配置嚮導(交互式),用來生成awstats的配置文件,awstats配置文件的命名規則是awstats.WEBSITE.conf。固然這些都是能夠在之後的配置文件中修改的。 # cd /usr/local/awstats/tools/ # perl awstats_configure.pl ---執行該命令 ----- AWStats awstats_configure 1.0 (build 20140126) (c) Laurent Destailleur ----- This tool will help you to configure AWStats to analyze statistics for one web server. You can try to use it to let it do all that is possible in AWStats setup, however following the step by step manual setup documentation (docs/index.html) is often a better idea. Above all if: - You are not an administrator user, - You want to analyze downloaded log files without web server, - You want to analyze mail or ftp log files instead of web log files, - You need to analyze load balanced servers log files, - You want to 'understand' all possible ways to use AWStats... Read the AWStats documentation (docs/index.html). -----> Running OS detected: Linux, BSD or Unix # 檢測當前的操做系統 -----> Check for web server install Found Web server Apache config file '/etc/httpd/httpd.conf' # 檢測到apache 配置文件 -----> Check and complete web server config file '/etc/httpd/httpd.conf' Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"' Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"' Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"' Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"' Add '<Directory>' directive AWStats directives added to Apache config file. -----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf' File awstats.model.conf updated. -----> Need to create a new config file ? Do you want me to build a new AWStats config/profile file (required if first install) [y/N] ? y # 詢問是否建立一個新的配置文件,這裏填y便可。 -----> Define config file name to create What is the name of your web site or profile analysis ? Example: www.mysite.com Example: demo Your web site, virtual server or profile name: > www.test.com # 這裏讓填寫你的網站域名,虛擬主機名或者隨便一個配置名。 -----> Define config file path In which directory do you plan to store your config file(s) ? Default: /etc/awstats Directory path to store config file(s) (Enter for default): > # 這裏要填寫你配置文件存放路徑,咱們使用它默認的路徑/etc/awstats,因此直接回車便可。 -----> Create config file '/etc/awstats/awstats.www.test.com.conf' Config file /etc/awstats/awstats.www.test.com.conf created. -----> Restart Web server with '/sbin/service httpd restart' grep: /etc/httpd/conf/httpd.conf: No such file or directory Stopping httpd: [ OK ] Starting httpd: [ OK ] -----> Add update process inside a scheduler Sorry, configure.pl does not support automatic add to cron yet. You can do it manually by adding the following command to your cron: /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.test.com Or if you have several config files and prefer having only one command: /usr/local/awstats/tools/awstats_updateall.pl now Press ENTER to continue... #提示不能自動加入crontab定時任務,須要稍後本身添加,咱們按回車繼續便可。 #回頭把該命令填入crontab 按指定時間執行 A SIMPLE config file has been created: /etc/awstats/awstats.www.test.com.conf You should have a look inside to check and change manually main parameters. You can then manually update your statistics for 'www.test.com' with command: > perl awstats.pl -update -config=www.test.com You can also read your statistics for 'www.test.com' with URL: > http://localhost/awstats/awstats.pl?config=www.test.com Press ENTER to finish... #提示配置文件建立完成和如何更新配置及創建靜態報告頁,這裏咱們回車便可結束這個配置嚮導。 注意:這裏要在Awstats安裝目錄運行。不然會有一些關於標準目錄的提示。Awstats缺省標準安裝目錄是/usr/local/awstats,若是要安裝到其它目錄須要對awstats_configure.pl進行修改。
 

 

Awstats 會自動檢測httpd.conf 配置文件,並在其配置文件末尾添加以下語句:

# # Directives to allow use of AWStats as a CGI # Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/" Alias /awstatscss "/usr/local/awstats/wwwroot/css/" Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/" ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/" # # This is to permit URL access to scripts/files in AWStats directory. # <Directory "/usr/local/awstats/wwwroot"> Options None AllowOverride None Order allow,deny Allow from all </Directory> 若是是apache 2.4,則需調整: Require all granted 在這裏,容許 /usr/local/awstats/wwwroot 目錄定義本身的訪問規則,所以我作一些簡單的認證。 # # This is to permit URL access to scripts/files in AWStats directory. # <Directory "/usr/local/awstats/wwwroot"> Options None AllowOverride None AuthType Basic AuthName "Restricted Files" AuthUserFile /etc/httpd/passwd Require user admin Order allow,deny Allow from all </Directory> ## 添加apache 認證用戶和密碼 # htpasswd -c /etc/httpd/passwd admin New password: Re-type new password: Adding password for user admin ## 重啓apache # service httpd restart
 

 

awstat 目錄:

安裝目錄: /usr/local/awstats

配置文件: /etc/awstats

數據文件: /var/lib/awstats

三、查看awstats配置文件

        awstats_configure.pl 還將根據安裝過程當中您的回答(要分析的網站域名)信息,生成配置文件。結束這個嚮導之後,咱們對www.test.com站點的awstats配置文件已經配置好了。下面咱們來查看並修改一下這個配置文件。

 

接下來,編輯配置文件,AWStats 支持針對多個子域名生成分析日誌,主要修改如下幾行:

# cd /etc/awstats/ # ls awstats.www.test.com.conf # vim awstats.www.test.com.conf #這個配置文件有不少配置,咱們這裏只講解重點配置。 LogFile="/usr/local/apache/logs/access_%YYYY-24%MM-24%DD-24.log" #日誌文件存放路徑 LogType=W #分析web日誌 LogFormat=4 #表示日誌格式 combined DirData="/var/lib/awstats" #建立生成的數據路徑 SiteDomain="www.test.com" Lang="cn" #默認語言中文 SkipHosts="127.0.0.1 REGEX[^192\.168\.]" #本地及內部的訪問不作分析統計 LevelForWormsDetection=2 #日誌等級,不對警告日誌進行統計
 

LogFile 指明apache的access log所在,這裏也可使用變量,例如:LogFile="/data/log/imysql.cn-access_log.%YY-24%MM-24%DD",具體的請查看 相關文檔
LogFormat 表示日誌格式,我在apache的日誌格式中,採用 combined,所以這裏寫成4。若是apache裏設置的是 common,則在這裏寫 2,具體的對應關係能夠看 Awstats文檔
SiteDomain 要分析的域名
DirData 分析結果存放位置(awstas數據庫)

若是apache 進行了日誌切割, 這裏須要隨機應變

## awstats # vim awstats.www.test.com.conf LogFile="/log/www/access_%YYYY-24%MM-24%DD-24.log" 若是進行日誌切割,可以使用通配符%YYYY-24%MM-24%DD-24 是指年月日模式(昨天) %YYYY-0%MM-0%DD-0 (當天) ## apache # vim /etc/httpd/conf/httpd.conf #CustomLog logs/access_log combined CustomLog "|/usr/local/sbin/cronolog /log/www/access_%Y%m%d.log" combined
 

 

 

4、awstats 執行日誌分析 

 

    在上面的咱們講解了awstats的yum安裝與源碼安裝,同時配置了一個監控實例,下面咱們就執行一下這個監控實例www.test.com

一、更新awasts數據庫

## 首先重啓一下 httpd # service httpd restart # perl /usr/local/awstats/tools/awstats_updateall.pl now 上面這種方式是一會兒分析全部的域名,也能夠像下面這樣只分析某個域名: # perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=WEBSITE [root@web ~]# perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.test.com Create/Update database for config "/etc/awstats/awstats.www.test.com.conf" by AWStats version 7.4 (build 20150714) From data in log file "/var/log/httpd/access_log"... Phase 1 : First bypass old records, searching new record... Direct access after last parsed record (after line 319) Jumped lines in file: 319 Found 319 already parsed records. Parsed lines in file: 5 Found 0 dropped records, Found 0 comments, Found 0 blank records, Found 0 corrupted records, Found 0 old records, Found 5 new qualified records.
 

        如今咱們須要用awstats來生成對apache日誌的統計分析信息。因爲咱們用的awstats是支持perl的FCGI動態化訪問頁面,因此此處咱們只須要直接更新數據庫便可。FCGI程序會自動將數據庫以動態頁面的形式展示出來,無須再手動生成靜態頁面了。

 

 

接下來咱們來查看一下分析結果

若是還想經過web server查看分析結果,就須要讓web server支持cgi才行了。在這裏,我使用apache做爲web server,所以我在編譯apache時,加上了選項:--enable-cgi

  • LoadModule cgid_module modules/mod_cgid.so

  • 注意cgi腳本的執行權限,必定要apache用戶擁有執行權限,不然可能提示Server Internal 錯誤。

# chown -R apache:apache /usr/local/awstats
 

 

注,若是,你順利的執行了上面的全部操做。那麼OK,如今你已經能夠經過訪問:http://localhost/awstats/awstats.pl?config=www.test.com ,效果以下圖:

wKioL1X1d_DSOLffAAPA5CWJgzc014.jpg

 

 

cron更新數據庫

    因爲要獲得新的統計信息,就必須更新數據庫,也就是說從新作讀取日誌。分析日誌提取裏面新增的部分進行分析,將更新的數據存入數據庫的過程。最好就讓它定時執行。

    最後須要說明的是,在文中已經屢次提到過,要能反應最新信息就必須更新數據庫。也就是說你可能已經對它進行了屢次訪問,可是查看統計頁面發現沒變化。這是由於這些日誌尚未更新到數據庫.簡單的方法就是定時執行。

00 5 * * * /usr/bin/perl  /usr/local/awstats/tools/awstats_updateall.pl now &> /dev/null
 

 

 

5、awstats 多站點日誌分析

假設我有兩個站點:

配置多站點監控(也就是配置 多個awstats 配置文件便可。分析多個域名的日誌,就是把 awstats_configure.pl 多操做幾回)

注,配置 mail.test.com的 配置文件,其實步驟和上面www.test.com同樣,只是在域名的地方作更改便可。下面咱們就再來演示一下,

# cd /usr/local/awstats/tools/ # ./awstats_configure.pl 此時會出現以下提示, ----- AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur ----- This tool will help you to configure AWStats to analyze statistics for one web server. You can try to use it to let it do all that is possible in AWStats setup, however following the step by step manual setup documentation (docs/index.html) is often a better idea. Above all if: - You are not an administrator user, - You want to analyze downloaded log files without web server, - You want to analyze mail or ftp log files instead of web log files, - You need to analyze load balanced servers log files, - You want to 'understand' all possible ways to use AWStats... Read the AWStats documentation (docs/index.html). -----> Running OS detected: Linux, BSD or Unix -----> Check for web server install Enter full config file path of your Web server. Example: /etc/httpd/httpd.conf Example: /usr/local/apache2/conf/httpd.conf Example: c:\Program files\apache group\apache\conf\httpd.conf Config file path ('none' to skip web server setup): > /etc/httpd/conf/httpd.conf Your web server config file(s) could not be found. You will need to setup your web server manually to declare AWStats script as a CGI, if you want to build reports dynamically. See AWStats setup documentation (file docs/index.html) -----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf' File awstats.model.conf updated. -----> Need to create a new config file ? Do you want me to build a new AWStats config/profile file (required if first install) [y/N] ? y -----> Define config file name to create What is the name of your web site or profile analysis ? Example: www.mysite.com Example: demo Your web site, virtual server or profile name: > mail.test.com #咱們這裏配置域名就是mail.test.com,其它地方與www.test.com沒有什麼不一樣。 -----> Define config file path In which directory do you plan to store your config file(s) ? Default: /etc/awstats Directory path to store config file(s) (Enter for default): > #這裏要填寫你配置文件存放路徑,咱們使用它默認的路徑/etc/awstats,因此直接回車便可。 -----> Create config file '/etc/awstats/awstats.www.test.com.conf' Config file /etc/awstats/awstats.www.test.com.conf created. -----> Add update process inside a scheduler Sorry, configure.pl does not support automatic add to cron yet. You can do it manually by adding the following command to your cron: /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mail.test.com Or if you have several config files and prefer having only one command: /usr/local/awstats/tools/awstats_updateall.pl now Press ENTER to continue... #提示不能自動加入crontab定時任務,須要稍後本身添加,咱們按回車繼續便可。 A SIMPLE config file has been created: /etc/awstats/awstats.mail.test.com.conf You should have a look inside to check and change manually main parameters. You can then manually update your statistics for 'mail.test.com' with command: > perl awstats.pl -update -config=mail.test.com You can also build static report pages for 'mail.test.com' with command: > perl awstats.pl -output=pagetype -config=mail.test.com Press ENTER to finish... #提示配置文件建立完成和如何更新配置及創建靜態報告頁,這裏咱們回車便可結束這個配置嚮導。
 

好了,下面步驟和上面www.test.com配置步驟同樣,我這裏就不重複說明。

 

6、awstats 問題彙總

一、IP 地址國家、區域顯示問題

    Awstats默認安裝以後是不具備識別訪問者的國家和地區信息的,因此須要安裝插件支持Awstats列出訪問者的國家和地區,便於分析GeoIP免費的是國家/IP的數據表,GeoIPCityLite是地區的數據表。

(1).MaxMind目前免費提供了GeoIP 和GeoIPCityLite 數據包:能夠按期每月從如下地址下載

## 下載 # wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz # wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz ## 解壓 # gzip -d GeoIP.dat.gz # gzip -d GeoLiteCity.dat.gz ## 移至新建目錄 # mkdir -pv /var/geoip # mv GeoIP.dat GeoLiteCity.dat GeoIPASNum.dat /var/geoip/ ## 安裝源 # wget http://ftp.sjtu.edu.cn/fedora/epel/6/i386/epel-release-6-8.noarch.rpm # rpm -ivh epel-release-6-8.noarch.rpm warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:epel-release ########################################### [100%] # yum clean all # yum makecache ## 安裝GeoIP C庫與 GeoIP perl庫 # yum -y install GeoIP perl-Geo-IP ## 修改 awstats 配置文件 # vim /etc/awstats/awstats.www.test.com.conf #1444 行左右添加: LoadPlugin="geoip GEOIP_STANDARD /var/geoip/GeoIP.dat" #1464 行左右添加: LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /var/geoip/GeoLiteCity.dat" ## 刪除舊的統計數據 # rm -rf /var/lib/awstats/* ## 從新生成數據庫 # perl /usr/local/awstats/tools/awstats_updateall.pl now # perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.test.com # 生成 html 頁面 # /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.test.com -lang=cn
 

二、中文亂碼問題

 

    Awstats是一套很是好用的免費的日誌分析軟件,他是用perl實現的,支持web log、ftp log和mail log;並且它還能自動根據你瀏覽器的字符設置來選取語言(支持中文)。可是缺省安裝的話有個問題,就是用來搜索的關鍵字若是是中文的話顯示出來是亂碼的。 之因此搜索的關鍵字句會變成亂碼的緣由,主要是由於如今的搜索引擎都是使用UTF8,而Awstats是使用decodeUTFkeys這個plugin來處理搜索引擎的UTF8關鍵字,默認是沒有打開的,因此在顯示上會出現亂碼。要解決中文亂碼問題,方法也很簡單,

在配置文件中把decodeutfkeys這個plugin打開就能夠了。在配置文件中找到:

#LoadPlugin="decodeutfkeys"

去掉前面的#就能夠了。

# vim /etc/awstats/awstats.www.test.com.conf #LoadPlugin="decodeutfkeys" #1300 行 LoadPlugin="decodeutfkeys"
 

這樣咱們的中文顯示就完成了,可是打開LoadPlugin="decodeutfkeys"這個插件在一些機器上會報錯,下面咱們來演示一下報錯的狀況。

報錯

從上面的報錯能夠看出這是缺乏 Perl 的 URI:Escape模塊,下面咱們解決一下這個問題:

# wget http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/URI-1.60.tar.gz # tar xf URI-1.60.tar.gz # cd URI-1.60 # perl Makefile.PL # make && make install
 

 

 

7、awstats 總結

    AWStats是在Sourceforge上發展很快的一個基於Perl的WEB日誌分析工具。相對於另一個很是優秀的開放源代碼的日誌分析工具Webalizer,AWStats的優點在於:

1.界面友好:能夠根據瀏覽器直接調用相應語言界面(有簡體中文版)

2.基於Perl:而且很好的解決了跨平臺問題,系統自己能夠運行在GNU/Linux上或Windows上(安裝了ActivePerl後);分析的日誌直接支持Apache格式 (combined)和IIS格式(須要修改)。Webalizer雖然也有Windows平臺版,但目前已經缺少 維護;AWStats徹底能夠實現用一套系統完成對自身站點不一樣WEB服務器:GNU/Linux/Apache和Windows/IIS服務器的統一統計。

3.效率比較高:AWStats輸出統計項目比Webalizer豐富了不少,速度仍能夠達到Webalizer的1/3左右,對於一個日訪問量 百萬級的站點,這個速度都是足夠的;

4.配置/定製方便:系統提供了足夠靈活但缺省也很合理的配置規則,須要修改的缺省配置不超過3,4項就能夠開始運行,並且修改和擴展的插件仍是 比較多的;

5.AWStats的設計者是面向精確的"Human visits"設計的,所以不少搜索引擎的機器人訪問都被過濾掉了,所以有可能比其餘日誌統計工具統計的數字要低,來自公司內部的訪問也能夠經過IP過濾 設置過濾掉。

6.提供了不少擴展的參數統計功能:使用ExtraXXXX系列配置生成針對具體應用的參數分析會對產品分析很是有用。

AWStats 是一個免費的強大而有個性的工具,帶來先進的網絡,流量,FTP或郵件服務器統計圖. 本日誌分析器做爲CGI或從命令行在數個圖形網頁中顯示你日誌中包含的全部可能信息. 它利用一部分檔案資料就能常常很快地處理大量日誌檔案, 它能分析日誌文件來自從各大服務器工具 ,如 Apache日誌檔案 s (NCSA combined/XLF/ELF log format or common/CLF log format), WebStar, IIS (W3C的日誌格式)及許多其餘網站,Proxy(代理服務器)、Wap、流量服務器、郵件服務器和一些 FTP服務器。

看一看這個比較表在最著名統計工具 (AWStats, Analog, Webalizer,...)之間有何特色和不一樣的想法。AWStats 是一個在GNU通用公共許可證下發行的免費軟件. 你能夠看看這個許可證圖表而知道你能夠/不能夠作。因爲AWStats工程來自網上信息,但也做爲CGI、 它能夠與容許進入Perl、CGI與日誌的大型網站主辦提供商一塊兒工做。

 

8、安裝配置 JAWStats 

 

JAWStats 是基於 Awstats 統計數據的,但其界面更爲強悍,有了JAWStats 你甚至能夠拋棄第三方統計了。 

2.1. 下載與安裝 
# wget http://static.jawstats.com/src/jawstats-0.7beta.tar.gz # mkdir /var/www/stats/ # tar -zxf jawstats-0.7beta.tar.gz -C /var/www/stats/ # cd /var/www/stats/ # cp config.dist.php config.php 2.2. 修改配置文件 官方配置說明見:http://www.jawstats.com/documentation jawstats 是支持多站點的,每一個 $aConfig 對應一個站點,並能夠自由切換 <?php // core config parameters $sDefaultLanguage = "zh-cn"; // 設置默認語言 $sConfigDefaultView = "thismonth.all"; $bConfigChangeSites = false; //是否能夠更換站點 $bConfigUpdateSites = false; //是否能夠更新統計數據 $sUpdateSiteFilename = "xml_update.php"; // individual site configuration $aConfig["www.zzxtbl.com"] = array( // site1 網站域名(注意不能亂填) "statspath" => "/var/lib/awstats/", //awstats 統計數據目錄 "updatepath" => "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl/", //用於更新統計數據 "siteurl" => "http://www.zzxtbl.com", //點擊首頁標題後會前往這個地址 "sitename" => "test.org", //首頁標題 "theme" => "default", "fadespeed" => 250, "password" => "my-1st-password", //更新統計數據須要輸入這個密碼 "includes" => "", "language" => "zh-cn" ); ?> <?php // core config parameters $sDefaultLanguage = "zh-cn"; $sConfigDefaultView = "thismonth.all"; $bConfigChangeSites = false; $bConfigUpdateSites = false; $sUpdateSiteFilename = "xml_update.php"; // individual site configuration $aConfig["site1"] = array( "statspath" => "/var/lib/awstats/", "updatepath" => "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl/", "siteurl" => "http://www.zzxtbl.com", "theme" => "default", "fadespeed" => 250, "password" => "my-1st-password", "includes" => "" ); ?> 2.3. 安裝中文語言包 首先下載 jawstats 多國語言包,解壓縮後上傳替換 lang 目錄。 wget http://www.jawstats.com/src/languagepack.zip 須要注意的是,你要修改 translations.php 文件的編碼爲UTF-8,否則全亂碼了。 另外修改漢化文件,也是translations.php,不能只修改zh-cn.js文件。 2.4.在http服務器的httpd.conf添加虛擬目錄 Alias /zzxtbl "/usr/local/jawstats" <Directory "/usr/local/jawstats"> Options Indexes MultiViews Order allow,deny Allow from all </Directory>
 

 

 

http://www.cnblogs.com/fnng/archive/2012/08/31/2666175.html

http://freeloda.blog.51cto.com/2033581/1346412

http://blog.fity.cn/post/389/

http://zzxtbl.blog.51cto.com/7620672/1650825

 

 

 

9、Windows 平臺安裝 awstats 

一、安裝環境

  • windows Server 2008 R2

  • apache 2.2

  • awstats版本爲7.3

 

 

Windows系統下配置 apache 日誌切割方法:

A、使用 cronolog 日誌輪轉工具

從 http://cronolog.org/download/  能夠下載 cronolog程序, 把下載的 cronolog程序放到 apache 的bin 目錄下(詳細參數參加: http://cronolog.org/usage.html)

wKioL1X24nDSIdMOAAFUTs0ku_o306.jpg

B、使用 rotatelogs 程序

rotatelogs 是 apache 自帶的管道日誌程序,參數以下(參考:http://lamp.linux.gov.cn/Apache/ApacheMenu/programs/rotatelogs.html )

wKiom1X24D2CzlWqAAHhStGyHRY612.jpg

 

2、安裝備忘

一、注意:因爲awstats依賴於perl,因此提早安裝perl環境

下載perl:   http://www.activestate.com/activeperl/downloads

或者直接在百度搜索下載: activeperl 

根據本身的環境選擇不一樣的安裝包,一般下載 ActivePerl_5.x.msi 可執行程序,而後安裝

一、測試是否加入環境變量
C:\Users\Administrator> perl -v

二、根據安裝提示
記錄perl的路徑(如X:\perl\bin\perl.exe),下面會用到

三、可能存在的問題
perl自動安裝的狀況會將路徑配置到%system%以前,致使系統沒法識別,解決方法就是把路徑放置到PATH最後
 

二、配置 apache 支持 perl (CGI)

修改httpd.conf文件:
#ScriptAlias /cgi-bin/ "c:/Apache/cgi-bin/" 將前面的 # 號去掉,改成 ScriptAlias /cgi-bin/ "c:/Apache/cgi-bin/" AddHandler cgi-script .cgi 在後面加上一個空格和 .pl , 改成 AddHandler cgi-script .cgi .pl #LoadModule alias_module modules/mod_alias.so 啓用alias_module模塊,把前面的#號去掉,改成 LoadModule alias_module modules/mod_alias.so 修改後記得重啓apache
 

 

三、解壓AWStats

 

下載AWStats(國內環境的話,須要自帶工具)

http://sourceforge.net/projects/awstats

自行選擇須要解壓的路徑

 

四、設置配置文件

定位到awstats-7.3\tools下,執行 awstats_configure 文件,這個文件的主要功能就是設置WEB容器的路徑,log路徑等。

配置完後,APACHE的 httpd.conf 下會生成相似一下的內容

# # Directives to allow use of AWStats as a CGI # Alias /awstatsclasses "c:/awstats-7.3/wwwroot/classes/" Alias /awstatscss "c:/awstats-7.3/wwwroot/css/" Alias /awstatsicons "c:/awstats-7.3/wwwroot/icon/" ScriptAlias /awstats/ "c:/awstats-7.3/wwwroot/cgi-bin/" # # This is to permit URL access to scripts/files in AWStats directory. # <Directory "c:/awstats-7.3/wwwroot"> Options none AllowOverride none Order allow,deny Allow from all </Directory>
 

 

同時在awstats-7.3\wwwroot\cgi-bin文件夾下會生成一個 awstats.domain.com.conf 文件

 

四、修改配置文件

定位到awstats-x.x\wwwroot\cgi-bin下,打開awstats.domain.com.conf文件
修改以下內容

LogFile="C:/Apache2.2/logs/fs_access-%YYYY-24%MM-24%DD-24.log" #日誌文件存放路徑,要與你的apache的log路徑一致 LogFormat=4 SiteDomain="fs.zhubajie.la" Lang="cn" #默認語言中文 SkipHosts="127.0.0.1" #本地訪問不作分析統計
 

五、生成數據

cmd 定位到awstats文件下(awstats-x.x\wwwroot\cgi-bin),在cmd中執行如下命令

注意:請將domain.com替換爲你的域名或地址
# perl.exe awstats.pl -update -config=domain.com 正常狀況下會顯示 不出意外的話,會顯示出以下信息: C:\awstats-7.3\wwwroot\cgi-bin>perl.exe awstats.pl -update -config=fs.zhubajie.l a Create/Update database for config "./awstats.fs.zhubajie.la.conf" by AWStats ver sion 7.3 (build 20140126) From data in log file "C:/Apache2.2/logs/fs_access-20150914.log"... Phase 1 : First bypass old records, searching new record... Searching new records from beginning of log file... Phase 2 : Now process new records (Flush history on disk after 20000 hosts)... Jumped lines in file: 0 Parsed lines in file: 134025 Found 0 dropped records, Found 0 comments, Found 0 blank records, Found 0 corrupted records, Found 0 old records, Found 134025 new qualified records. 同時在awstats-x.x\wwwroot\cgi-bin下會生成一個相似awstats0X2013.domain.txt 的文件
 

六、修改awstats文件

編輯: awstats-x.x\wwwroot\cgi-bin\awstats.pl

因爲win下路徑與linux中不一樣,因此這個文件第一行應該改爲 #!X:/perl/bin/perl.exe (該地址爲前期你安裝的perl的地址) 不然後期運行會出錯 couldn’t create child process: 720002: awstats.pl
 

七、瀏覽器打開

在瀏覽器中輸入相似的地址 http://localhsot/awstats/awstats.pl?config=domain.com,正常狀況下便可看到結果

 

高級配置

一、增長一個顯示來訪IP歸屬地的功能

執行以下命令

ppm install Geo::IP::PurePerl
ppm install Geography::Countries
ppm install IP::Country
ppm install Geo-IPfree
ppm install Net-Xwhois

安裝GeoIP

http://dev.maxmind.com/geoip/legacy/geolite/

修改awstats.domain.com.conf文件,找到以下內容

# 開啓 GeoIP 反查模塊
LoadPlugin="geoip GEOIP_STANDARD D:/awstats/awstats-x.x/wwwroot/cgi-bin/ipdata/GeoIP.dat"
# 開啓 IP 反查的外掛
LoadPlugin="geoipfree"
# 開啓 decodeutfkeys 外掛,解決」用以搜索的關鍵詞」亂碼
LoadPlugin="decodeutfkeys"

 

更新配置文件

perl.exe awstats.pl -config=domain.com -update

二、按期更新

經過win的計劃任務搞定

編輯一個 bat 批處理文件, 內容以下:

C:\Perl\bin\perl.exe  C:\awstats-7.3\wwwroot\cgi-bin\awstats.pl -update -config=fs.zhubajie.la
 

 

三、加一個須要用戶名才能夠訪問的功能

因爲要求在內網訪問,因此沒有涉及

 

參考閱讀:

 

http://luestudy.blog.51cto.com/8480481/1395362

http://blog.chinaunix.net/uid-7354272-id-2643593.html

 

怎樣在windows下安裝Perl

http://jingyan.baidu.com/article/380abd0aa6c7371d90192c1b.html

 

 

awstats 分析 nginx 日誌

一、安裝nginx 以及 awstats 的過程就不講解了, 能夠參考上面的內容。

 

二、本文主要介紹經過讓 awstats 對日誌統計的結果生成靜態頁面,而後經過 Nginx 輸出以達到統計 Nginx 訪問日誌的效果,其中還包括如何讓 Nginx 自動切割日誌文件。對於nginx的日誌,個人作法是按天切割。

 

配置 Nginx 自動切割日誌

跟 Apache HTTP Server(如下稱 Apache)不一樣的是,Apache 能夠將日誌輸出經過管道的方式進行從新定向,依此來進行自動的日誌切割。Nginx 在現今版本上還沒能跟 Apache 同樣,經過%YY等參數按日期分批建立日誌,可是經過給 nginx 進程發送一個特定的信號,可使 nginx 從新生成日誌文件。咱們能夠按期執行一個 Shell 腳原本切換日誌,從新命名或轉移,具體的腳本以下:

# mv  /usr/local/nginx/logs/access.log  /usr/local/nginx/logs/access_`date -d "yesterday" +%Y%m%d`.log
# killall –s USR1 nginx	#使用USR1參數通知Nginx進程切換日誌文件
 

將以上腳本內容保存爲文件名爲 logcron.sh 存到自定的目錄中,例如 /opt/nginx/sbin/logcron.sh

使用 Crontab 讓該腳本程序在天天晚上 11 點 59 分自動執行,便可作到按天建立日誌。

 

須要注意的是,nginx的日誌應該遵循如下格式,才能夠被awstats識別,如定義日誌格式

# 定義日誌格式 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; # 使用日誌格式 access_log /home/www/logs/access.log main; # nginx 日誌進行了切割 mv ${logs_path}/access.log ${logs_path}/access_$(date -d "yesterday" +"%Y%m%d").log 生成的日誌格式: access_20150912.log
 

 

執行 tools 目錄中的 awstats_configure.pl 配置嚮導,建立一個新的統計。

[root@iredmail tools]# ./awstats_configure.pl ----- AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur ----- This tool will help you to configure AWStats to analyze statistics for one web server. You can try to use it to let it do all that is possible in AWStats setup, however following the step by step manual setup documentation (docs/index.html) is often a better idea. Above all if: - You are not an administrator user, - You want to analyze downloaded log files without web server, - You want to analyze mail or ftp log files instead of web log files, - You need to analyze load balanced servers log files, - You want to 'understand' all possible ways to use AWStats...read the AWStats documentation (docs/index.html). -----> Running OS detected: Linux, BSD or Unix -----> Check for web server install Enter full config file path of your Web server. Example: /etc/httpd/httpd.conf Example: /usr/local/apache2/conf/httpd.conf Example: c:\Program files\apache group\apache\conf\httpd.conf Config file path ('none' to skip web server setup): > none #這裏填none並回車,由於咱們沒有使用apache,咱們這裏用的是 Nginx,因此跳過。 Your web server config file(s) could not be found. You will need to setup your web server manually to declare AWStats script as a CGI, if you want to build reports dynamically. See AWStats setup documentation (file docs/index.html) -----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf' File awstats.model.conf updated. -----> Need to create a new config file ? Do you want me to build a new AWStats config/profile file (required if first install) [y/N] ? y #y建立一個新的統計配置 -----> Define config file name to create What is the name of your web site or profile analysis ? Example: www.mysite.com Example: demo Your web site, virtual server or profile name: > slog.fity.cn #統計網站的域名,例如slog.fity.cn -----> Define config file path In which directory do you plan to store your config file(s) ? Default: /etc/awstats Directory path to store config file(s) (Enter for default): > #直接回車,使用默認路徑/etc/awstats -----> Create config file '/etc/awstats/awstats.slog.fity.cn.conf' Config file /etc/awstats/awstats.slog.fity.cn.conf created. -----> Add update process inside a scheduler Sorry, configure.pl does not support automatic add to cron yet. You can do it manually by adding the following command to your cron: /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=slog.fity.cn #回頭把該命令填入crontab 按指定時間執行 Or if you have several config files and prefer having only one command: /usr/local/awstats/tools/awstats_updateall.pl now Press ENTER to continue... #按回車繼續 A SIMPLE config file has been created: /etc/awstats/awstats.slog.fity.cn.conf #新配置文件所在的路徑 You should have a look inside to check and change manually main parameters. You can then manually update your statistics for 'slog.fity.cn' with command: > perl awstats.pl -update -config=slog.fity.cn You can also build static report pages for 'slog.fity.cn' with command: > perl awstats.pl -output=pagetype -config=slog.fity.cn Press ENTER to finish... #回車完成配置文件的建立
 

 

以上步驟默認會產生配置文件 ==>> /etc/awstats/awstats.slog.fity.cn.conf

awstats 配置文件的命名規則:awstats.website.conf

修改配置文件

# vi /etc/awstats/awstats.slog.fity.cn.conf (1)指定日誌文件路徑(很是重要,必須的一個步驟) LogFile="/usr/local/nginx/logs/access.log"(51行左右) //指定log文件的存儲位置 若是你但願天天能定時生成昨天的報表,能夠: LogFile="/usr/local/nginx/logs/access_%YYYY-24%MM-24%DD-24.log" // 日誌切割後 注:根據你的日誌路徑和對應的日誌文件名進行修改。對應Nginx日誌切割程序所生成的目錄存放結構保存的nginx日誌文件。要注意Awstats的年月日格式的跟Nginx的寫法有所不一樣,其中%YYYY-24 、 %MM-2四、%DD-24表示年月日都減去24小時,也就是昨天的日誌目錄。 ############# 可選 ################## (2)修改Nginx日誌格式 ## 這一步感受非必須 ## 這裏Awstats執行統計的順序是: Nginx產生日誌–>日誌切割–>Nginx繼續產生日誌–>另存切割日誌–>交由Awstats統計–>生成結果 修改日誌格式,因爲這裏nginx生成日誌格式要與awstats所須要的匹配,因此要修改日誌格式,以便awstats讀取。註釋掉LogFormat=1,添加以下,每個變量的參數,配置文件上方有解釋,這裏很少說 ## 編輯 awstats 配置文件 #LogFormat=1 LogFormat="%host %other %other %time1 %other %methodurl %code %bytesd %refererquot %uaquot" ## 修改Nginx日誌格式: nginx的日誌應該遵循如下格式,才能夠被awstats識別。這裏的main是指格式代稱,若是有多個虛擬主機,代稱不能同樣 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; 使用日誌格式 access_log /usr/local/nginx/logs/access.log main; 補充說明:把log_format這段代碼放在你nginx的http的定義段中,能夠在下面的每個server中引用此格式。沒必要在每一個server裏面都去定義格式。 (3)修改SiteDomain=slog.fity.cn 網站域名 (4)修改LoadPlugin="decodeutfkeys",去掉注視,不然會出現中文亂碼 (5)修改Lang="cn"語言爲中文 (6)添加LIMITFLUSH=5000000儘可能大,可根據狀況而定。增大AWStats的$LIMITFLUSH,減小磁盤臨時文件讀寫 Flush history file on disk (unique url reach flush limit of 5000) ############# 可選 ################## 運行awstats的wwwroot目錄中的awatsts.pl來測試一下 # /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=slog.fity.cn 若是看到相似下面的提示,就說明配置文件都正確了 From data in log file "/usr/local/nginx/logs/access_20150914.log"... Phase 1 : First bypass old records, searching new record... Searching new records from beginning of log file... Phase 2 : Now process new records (Flush history on disk after 20000 hosts)... Jumped lines in file: 0 Parsed lines in file: 95 Found 0 dropped records, Found 0 comments, Found 0 blank records, Found 0 corrupted records, Found 0 old records, Found 95 new qualified records. 看到以上顯示,證實日誌切割和 Awstats 都已經運行無誤了。統計分析完成後,結果還在 Awstats 的數據庫中。在 Apache 上,能夠直接打開 Perl 程序的網頁查看統計。 但本文開始時已經提到,Nginx 對 Perl 支持並很差,因此咱們要換個方法,利用 awstats 的工具將統計的結果生成靜態文件,具體的步驟以下: 一、首先在 webroot 目錄下建立一個文件夾。例:/usr/local/nginx/html/awstats # mkdir /usr/local/nginx/html/awstats 二、寫一個腳本,按期執行讓 Awstats 把靜態頁面生成到該目錄中 #!/bin/bash /usr/local/awstats/tools/awstats_buildstaticpages.pl -update \ -config=slog.fity.cn -lang=cn -dir=/usr/local/nginx/html/awstats \ -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl ## 加上可執行權限,並測試 # chmod +x /root/awstats.sh # /root/awstats.sh ## 加入 crontab 00 1 * * * /root/awstats.sh 上述命令的具體意思以下: § /usr/local/awstats/tools/awstats_buildstaticpages.pl Awstats 靜態頁面生成工具 § -update -config=slog.fity.cn 更新配置項 § -lang=cn 語言爲中文 § -dir=/usr/local/nginx/html/awstats 統計結果輸出目錄 § -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl Awstats 日誌更新程序路徑。 三、而後在你的nginx的配置文件中,在你想要安置awstats或默認的ip或域名的server段中,加入關於awstats和icon的兩個目錄配置。 server { listen 80; server_name localhost; location ~ ^/awstats/ { # awstats 靜態頁面目錄 root /usr/local/nginx/html; # 靠, 不是 /usr/local/nginx/html/awstats 坑了很久 autoindex on; #能夠目錄瀏覽你的多個域名的目錄用於分析 index index.html; access_log off; error_log off; } location ~ ^/icon/ { # 圖標目錄 root /usr/local/awstats/wwwroot; index index.html; access_log off; error_log off; } }
 

 

用瀏覽器查看到統計的詳細結果  http://youhostname/awstats/awstats.www.slog.fity.cn.html

至此,使用 awstats 已能徹底支持 Nginx 的日誌統計。

 

認證訪問

 

通常站長都不肯隨便讓人知道本身站的真實流量,因此要把 Awstats 統計結果頁面進行密碼保護。Nginx 使用的是跟 Apache 同樣的密碼加密格式,這裏須要用到 apache 自帶的工具 htpasswd。

若是你在本機上默認裝有 Apache,這你就只需在它的程序目錄下運行

 

# /usr/bin/htpasswd -c /usr/local/nginx/passwd  admin          #用戶名爲admin

New password:            輸入密碼
Re-type new password:        重複輸入
Adding password for user admin    建立成功


修改 nginx.conf 在 location 中加入(加粗部分):

server {
    listen       80;
    server_name  localhost;

    location ~ ^/awstats/ {         # awstats  靜態頁面目錄
        root   /usr/local/nginx/html;    
        # 靠, 不是 /usr/local/nginx/html/awstats 坑了很久
        autoindex on;         #能夠目錄瀏覽你的多個域名的目錄用於分析
        index  index.html;
        access_log off;
        error_log off;
        auth_basic "secret";                             #虛擬主機認證命名 
                auth_basic_user_file  /usr/local/nginx/passwd.db; #虛擬主機用戶名密碼認證數據庫 
          
    }

    location ~ ^/icon/ {             # 圖標目錄
        root   /usr/local/awstats/wwwroot;
        index  index.html;
        access_log off;
        error_log off;
    }
}

而後,從新啓動一下 nginx

 

 

若是你想給你的awstats加上訪問密碼,能夠見這裏:nginx爲目錄或網站加上密碼認證

問題彙總

 

當再次輸入網址時,在頁面上只出現了一行字:
Content-type: text/html; charset=gb2312 Cache-Control: public Last-Modified: Sat Feb 11 13:14:37 2016 Expires: Sat Feb 11 13:14:37 2016 

若是出現,是由於瀏覽器不支持frame(彷佛是服務器端問題),請在頁面上右鍵選擇查看源文件,有這樣一行字:Your browser does not support frames.You must set AWStats UseFramesWhenCGI parameter to 0 to see your reports.
好,如今去修改awstats.conf 配置文件,把UseFramesWhenCGI參數設成0。

 

 

http://www.ibm.com/developerworks/cn/linux/l-cn-awstats-nginx/

http://blog.sina.com.cn/s/blog_8db76d6d0101342m.html

http://lodar.net/methods-of-apache-web-log-daily-rotation/

http://www.linuxde.net/2013/06/14027.html

http://www.cnblogs.com/cocowool/archive/2010/09/07/1820626.html

http://www.cnblogs.com/cocowool/archive/2010/09/10/1823504.html

相關文章
相關標籤/搜索