apache上使用awstats日誌分析系統

AWStats日誌分析系統

perl語言開發的一款開源日誌分析系統

可用來分析apache samba vsftpd IIS等服務日誌

信息結合crond等計劃任務服務,可對日誌內容定期進行分析

apache

[root@localhost ~]# yum -y install httpd &>/dev/null
[root@localhost ~]# rpm -qc httpd
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/logrotate.d/httpd
/etc/sysconfig/htcacheclean
/etc/sysconfig/httpd

開啓httpd服務

# 或者使用service httpd start
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# netstat -antp | grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      32864/httpd         
tcp6       0      0 192.168.218.6:80        192.168.218.1:58303     FIN_WAIT2   32867/httpd         

安裝awstats

[root@localhost ~]# tar -xf awstats-7.6.tar.gz 
# 重命名並放到/usr/local目錄下
# 重命名把版本號去掉,因爲遇過在後面的配置中找不到文件路徑的情況
[root@localhost ~]# mv awstats-7.6 /usr/local/awstats
[root@localhost ~]# cd /usr/local/awstats/tools/
[root@localhost tools]# ./awstats_configure.pl 
……省略部分信息……
Config file path ('none' to skip web server setup):
> /etc/httpd/conf/httpd.conf  # 填入httpd的配置文件路徑
……省略部分信息……
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:
> www.awtest.com
……省略部分信息……
Directory path to store config file(s) (Enter for default):
> 
……省略部分信息……
Press ENTER to continue... 
……省略部分信息……
Press ENTER to finish...

查看httpd配置文件

[root@localhost tools]# vim /usr/local/httpd/conf/httpd.conf
……省略部分信息……
# 在文件最後會自動添加以下信息
<Directory "/usr/local/awstats/wwwroot">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

自動添加的配置爲日誌web頁面,視情況修改權限

<Directory "/usr/local/awstats/wwwroot">
    Options None
    AllowOverride None
#    Order allow,deny
#    Allow from all
    Require all granted
</Directory>

修改awstats站點統計配置文件

[root@localhost tools]# vim /etc/awstats/awstats.www.awtest.com.conf 
LogFile="/var/log/httpd/access_log"  
# 同樣根據實際情況配置
# yum安裝的httpd的日誌文件和源碼安裝的日誌文件位置不一樣

重啓httpd服務、手動刷新awstats數據

[root@localhost tools]# systemctl restart httpd
# 手動創建數據文件目錄
[root@localhost tools]# mkdir /var/lib/awstats
# 手動刷新數據
[root@localhost tools]# ./awstats_updateall.pl now
Running '"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=www.com -configdir="/etc/awstats"' to update config www.awtest.com
……省略部分信息……
Jumped lines in file: 0
Parsed lines in file: 5
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 4 corrupted records,
 Found 0 old records,
 Found 1 new qualified records.

訪問效果

http://www.awtest.com/awstats/awstats.pl?config=www.awtest.com

在這裏插入圖片描述

添加crontab計劃任務

# 每三分鐘刷新
[root@localhost ~]# crontab -e
*/3 * * * * /usr/local/awstats/tools/awstats_updateall.pl now

優化網頁地址

添加網頁文件/var/www/html/aws.html

<html>
  <head>
    <meta http-equiv=refresh content="0;url=http://www.awtest.com/awstats/awstats.pl?config=www.awtest.com">
  </head>
</html>

訪問http://www.awtest.com/aws.html便將跳轉到http://www.awtest.com/awstats/awstats.pl?config=www.awtest.com

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章