Awstats +JAWstats(ftpshell) 對日誌分析部署整合功能

 14431464316048.gif 

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


Awstats是一款基於Perl的WEB日誌分析工具,而JAWStats是一款基於PHP的統計套件,旨在爲Awstats提供更爲精美圖形界面。
JAWStats 是一個用來統計網站日誌的工具,在 AWStats 的基礎上生成更加清晰的關於網站訪問數據的圖表、表格。
它能夠統計您站點的以下信息:
1>.訪問量,訪問次數,頁面瀏覽量,點擊數,數據流量等
2>.精確到每個月、每日、每小時的數據
3>.訪問者國家
4>.訪問者IP
5>.Robots/Spiders的統計
6>.訪客持續時間
7>.對不一樣Files type 的統計信息
8>.Pages-URL的統計
9>.訪客操做系統瀏覽器等信息
10>.其它信息(搜索關鍵字等等)


小節總結css

awstats修改日誌文件路徑:
LogFile="/usr/local/awstats/tools/logresolvemerge.pl /home/tool/access.20100817.11*.log |"
此爲用awstats腳本自動合併分析全部/home/tool/access.20100817.11*.log日誌
若是日誌使用tar -zcvf 壓縮,logresolvemerge.pl會自動調用zcat
也能夠同時列出多個日誌文件,如如下格式:
LogFile="/usr/local/awstats/tools/logresolvemerge.pl 1.log 2.log |"
合併日誌也可用如下方式:
cat a.log b.log c.log | sort -m -t "  " –k 4 > log
將三個日誌以空格爲分隔符,對第四列進行排序,結果保存在log
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=


1.安裝 Awstats html

http://blog.csdn.net/wnss8888/article/details/3502756linux

Awstats 是由perl語言編寫的,因此要首先準備好awstats的運行環境。
yum install –y perl*


2.下載awstats工具。web

wget http://www.awstats.org/files/awstats-7.4.tar.gz
解壓:
tar xvf awstats-7.1.tar.gz 
mv awstats-7.1 /usr/local/awstats

3.安裝awstatsshell


(1)安裝數據庫

chown apache.apache –R /var/lib/awstats
chmod 755 /usr/local/awstats
chown -R apache plugins/  --受權
chown -R apache awstats
cd  /usr/local/awstats/tools/


#嚮導工具,生成網站配置文件
perl awstats_configure.pl   ---執行該命令
安裝過程:
1>.輸入 none 而後回車
2>.輸入 y 確認建立配置文件
3>.輸入配置文件名稱,通常輸入域名。
4>.配置文件使用默認路徑 /etc/awstats
5>.按回車繼續
6>.按回車完成配置文件的建立


----- 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
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:
>linuxidc.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):
> 
 
-----> Create config file '/etc/awstats/awstats.linuxidc.com.conf'
 Config file /etc/awstats/awstats.linuxidc.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=linuxidc.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... 
 
 
A SIMPLE config file has been created: /etc/awstats/awstats.linuxidc.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'linuxidc.com' with command:
> perl awstats.pl -update -config=linuxidc.com
You can also build static report pages for 'linuxidc.com' with command:
> perl awstats.pl -output=pagetype -config=zzxtbl.pub
 
Press ENTER to finish...


解釋:apache

awstats生成的目錄api

安裝目錄 /usr/local/awstats/
配置文件/etc/awstats/
數據文件/var/lib/awstats/


(2)配置http的啓動awstats虛擬目錄瀏覽器


vi /etc/httpd/conf/httpd.conf

將CustomLog logs/access_log common改成
CustomLog logs/access_log combined
在文件的最後面增長了
# 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>



4.添加awstats插件和地理區域

(1)下載GeoIPLite Country地址庫(須要定時更新)

wget http://www.maxmind.com/download/geoip/api/c/GeoIP-1.4.8.tar.gz
tar xvf GeoIP-1.4.8.tar.gz
cd GeoIP-1.4.8
./configure 
make && make install


(2)安裝相關Perl模塊

使用perl的CPAN模塊進行安裝
 perl -MCPAN -e "install Encode"
 perl -MCPAN -e "install URI::Escape"
 perl -MCPAN -e "install Storable"
 perl -MCPAN -e "install Geo::IP"
 perl -MCPAN -e "install Net::XWhois" 


 也能夠一次執行5個命令 

perl -MCPAN -e "install Encode, URI::Escape,Storable,Geo::IP,Net::XWhois"


(3)安裝qqhostinfo插件

qqhistinfo.pm, qqwry.rar, QQWry.Dat  放到/usr/local/awstats/wwwroot/cgi-bin/plugins/下面
cd /usr/local/awstats/wwwroot/cgi-bin/plugins
chmod 777 . –R


(4)下載GeoIPLite City地址庫(須要定時更新)

 

http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum2.zip
http://www.cpan.org/authors/id/B/BR/BRICAS/Geo-IPfree-1.143630.tar.gz
http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz

(5)free安裝

   

http://www.cpan.org/authors/id/B/BR/BRICAS/
tar zxvf Geo-IPfree-1.143630.tar.gz
cd Geo-IPfree-1.143630
perl Makefile.PL
make && make install


5.配置awstats分析http服務器日誌修改/etc/awstats/awstats.www.zzxtbl.top.conf

日誌格式和存放目錄
將LogFile="/var/log/httpd/mylog.log"
改成LogFile="/var/log/httpd/localhost_access_log.2012-08-29.txt"
LogFile="/var/log/httpd/localhost_access_log. YYY-0%MM-0%DD-0.txt"均可以。
若是有多個日誌文件須要分析(好比作了負載均衡),能夠這樣: 
LogFile = "/pathtotools/logresolvemerge.pl *.log |"


 修改日誌格匹配(tomcat日誌格式)

 

LogFormat = 1
LogFormat="%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot" 這兩行是註釋的,1表示是web日誌,下面是httpd的日誌格式
LogFormat ="%host %other %logname %time1 %methodurl %code"
這是我修改後的匹配tomcat的日誌格式


 修改解釋格式擴展名

 NotPageList="css js class gif jpg jpeg png bmp ico rss xml swf"

 "css js class gif jpg jpeg png bmp ico rss xml swf zip arj rar gz z bz2 wav mp3 wma mpg avi"


 設置頁面自動刷新

 將AllowToUpdateStatsFromBrowser=0改成AllowToUpdateStatsFromBrowser=1便可


 設置網站的主頁面的配置文件

DirData="/var/lib/awstats" 
DirCgi="/awstats" 
DirIcons="/awstatsicons"


 設置網站主頁面和連接url

Logo="awstats_logo6.png"
LogoLink="http://www.zzxtbl.top/"


 檢索頁面信息

 

LoadPlugin="tooltips"      在html報告中增長一些提示信息
LoadPlugin="decodeutfkeys" 處理搜索引擎UTF8編碼的關鍵字


 國家和地址ip解釋

 

LoadPlugin="geoip GEOIP_STANDARD /opt/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /opt/GeoLiteCity.dat"
LoadPlugin="geoip_org_maxmind GEOIP_STANDARD /opt/GeoIPASNum.dat"
#LoadPlugin="geoip_isp_maxmind GEOIP_STANDARD /pathto/GeoIPISP.dat"
#LoadPlugin="geoip_org_maxmind GEOIP_STANDARD /pathto/GeoIPOrg.dat"
#LoadPlugin="geoip_region_maxmind GEOIP_STANDARD /pathto/GeoIPRegion.dat"
LoadPlugin="qqhostinfo"   顯示真實ip
LoadPlugin="graphapplet /awstatsclasses" 
LoadPlugin="hostinfo" 
#LoadPlugin="geoipfree" 
LadPlugin="graphgooglechartapi"  開啓地圖模式
LIMITFLUSH=5000000    減輕磁盤的緩衝壓力


6.啓動httpd服務和刷新數據庫


service httdp restart ---啓動apche服務
 /usr/local/awstats/tools/awstats_updateall.pl now  --全局刷新生成數據
 /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.zzxtbl.top  --單個站點刷新數據


接下來生成報告的詳細子頁面,須要在命令行下經過output參數指定報告的名字,命令以下:

perl awstats.pl -config=mysite -output=alldomains -staticlinks >  awstats.mysite.alldomains.html

在生成html文件後生成一個PDF文件,報告的輸出目錄必須包括圖標目錄。

本文示例:

/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=www.zzxtbl.top -update -lang=cn -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -dir=/usr/local/awstats/wwwroot -diricons=icons


/usr/local/awstats/tools/awstats_buildstaticpages.pl -config=www.zzxtbl.top -update -lang=cn -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -buildpdf=/usr/local/awstats/wwwroot/


(1)計劃任務crontab -e 5點:30執行

50 3 * * *  /usr/local/awstats/tools/awstats_updateall.pl now


7.tomcat日誌解析

Tomcat的默認日誌格式類型與apache同樣,都是common,然而awstats分析的是combined類型的。如上所知,個人tomcat類型就是common型的,因此要改成combined型的。
從新定義tomcat日誌格式:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t&quot;%r&quot; %s %b %{Referer}i %{User-Agent}i" />



JAWstats生成圖片


2、安裝和配置 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["fb"] = array(                     //網站域名(注意不能亂填) 
    "statspath"   => "/var/lib/awstats/", //awstats 統計數據目錄 
    "updatepath"  => "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl/", //用於更新統計數據 
    "siteurl"     => "http://test.org", //點擊首頁標題後會前往這個地址 
    "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.top",
    "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 /tiandao "/usr/local/jawstats"
<Directory "/usr/local/jawstats">
Options Indexes MultiViews
Order allow,deny
Allow from all
</Directory>

配置虛擬目錄用戶認證訪問
Alias /tongji "/usr/local/jawstats"
<Directory "/usr/local/jawstats">
Options Indexes MultiViews
  AuthType Basic
  AuthName "Please Login"
  AuthUserFile /etc/httpd/.passwd
  Require valid-user
</Directory>


3.日誌經過ftp下載合併的shell

#!/bin/bash
date=` date +%Y%m%d`
yue=` date +%Y%m`
one=/opt/zzx/coutlogs/1/$yue
two=/opt/zzx/coutlogs/2/$yue
NewLog=/opt/zzx/count
logs=tiandao.log-$date
if  [ ! -d "$one" ]||[ ! -d "$two" ] ; then
mkdir -p "$one" "$two"
else
if [ ! -f "$one/$logs.gz" ]||[ ! -f "$two/$logstd.gz" ] ; then
 
ftp -n <<!
open 1192.168.10.12
user zzx Z@123456
binary
cd /1
lcd $one
prompt off
mget bj.log-$date.gz
bell
cd /2
lcd $two
mget bj.log-$date.gz
close
bye
!
else
gunzip -c $one/zzx.log-$date.gz >$one/$logs
gunzip -c $two/zzx.log-$date.gz >$two/$logs
touch /opt/zzx/count/zzx.log-$date
for log in zzx.log-$date
  do
    sort -m -t " " -k 4 -o  $NewLog/$log $one/$log $two/$log
done
fi
fi
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.zzxtbl.top.com
rm -f $NewLog/bj.log-$date
rm -f $one/bj.log-$date
rm -f $two/bj.log-$date

3.1計劃任務crontab -e 5點:30執行

vi /etc/crontab
0 5 * * * * root /opt/ftpmput.sh
相關文章
相關標籤/搜索