用AWStats分析網站日誌

        AWStats 是一個免費的強大而有個性的工具,帶來先進的網絡,流量,FTP或郵件服務器統計圖. 它能分析日誌文件來自從各大服務器工具 ,如 Apache日誌檔案  (NCSA combined or common),  IIS (W3C),Proxy、Wap、流量服務器、郵件服務器和一些FTP服務器等等。

   注:
  1:需要系統正常運行perl環境。
  2:apache運行正常。
1:到官方網站下載最新版本,目前的版本是Awstats 6.9
下載後上傳到主機上進行安裝和配置。
2:其實awstats安裝是非常容易的,大致的步驟如下:
[root@centos opt]#tar zxvf awstats-6.6.tar.gz
[root@centos opt]# cd awstats-6.6
[root@centos awstats-6.6]# cd tools/
[root@centos tools]# perl awstats_configure.pl
Do you want to continue setup from this NON standard directory [yN] ? y   

//輸入你的web server的配置文件路徑 使用none跳過設置
Config file path ('none' to skip web server setup):     
> none

Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y

Your web site, virtual server or profile name:
> [url]http://www.test.net/[/url]
直接回車 使用默認路徑 /etc/awstats
Directory path to store config file(s) (Enter for default):      
> /etc/awstats
再次敲回車,到此爲止awstats安裝完成,(是不是覺得太簡單了啊!)接下來配置awstats:
A:[root@centos /]# cd /etc/awstats/ (這個目錄是存放awstats配置文件的)
[root@centos awstats]# vi awstats.[url]www.test.net.conf[/url]
#LogFile="/var/log/httpd/mylog.log"
LogFile="/usr/local/apache2/logs/access_log" (修改你要分析的日誌文件的路徑)
//日誌分析結果輸出目錄 確保該目錄有寫權限
    DirData="/var/www/awstats/test/dirdata"
//指定日誌格式 1 - Apache combined logs  2 - IIS
    LogFormat=1   (如果是分析apache 可以用默認的,如果是分析IIS就應該選2)
  AllowToUpdateStatsFromBrowser=1 允許查看的時候進行更新日誌數據
:wq   保存退出。
B: 運行:perl /opt/awstats-6.6/wwwroot/cgi-bin/awstats.pl -update -config=www.test.net
如果是第一次運行更新的話,awstats會出現錯誤:AWStats did not find any valid log lines that match your LogFormat parameter, in the 50th first non commented lines read of your log。其實從錯誤信息中不難看出原因,解決辦法就是把用分析的日誌文件刪除,重新加載即可。
爲了讓系統自動作業,把命令加入系統的crontab,
[root@centos awstats]# crontab -e
30 23 * * * root perl /opt/awstats-6.6/wwwroot/cgi-bin/awstats.pl -update -config=www.test.net (每天晚上11:30進行日誌分析)
訪問權限配置
有時候網站的日誌信息不想給競爭對手看到,所以需要對日誌查看進行授權,授權方式如下:
編輯apache的配置文件 vi /usr/local/apache2/conf/httpd.conf
<Directory "/opt/awstats-6.6/wwwroot">
    Options None
   # AllowOverride None
    AllowOverride AuthConfig
    Order allow,deny
    Allow from all
    AuthType Basic
    AuthName "Restricted Files"
    AuthUserFile /usr/local/apache2/conf/passwords
    Require user dbasky
</Directory>
利用apapche的htpasswd生成個系統的用戶,達到系統的加密:
/usr/local/apache2/bin/htpasswd -c /usr/local/apache2/conf/passwords admin
此時輸入二次密碼確認密碼.
配置完成後,重啓apapche,ok!awstats就配置完成了,可以看看我們的成果了:
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章