文章目錄
前言:
AWStats是免費的一個非常強大的日誌分析工具的Apache日誌文件。 從apache分析日誌後,它以易於理解的圖形格式顯示它們。 AWStats是高級Web統計的縮寫,它可以在命令行界面或CGI上運行。
一、AWStats概述
1.1 AWStats日誌分析系統
- Perl語言開發的一款開源日誌分析系統
- 可用來分析Apache、Samba、Vsftpd、IIS等服務器的訪問日誌
- 信息結合crond等週期性計劃任務服務,可對日誌內容進行週期性分析
1.2 AWStats主要功能
-
AWStats可以同進站點以下信息:
訪問量,訪問次數,頁面瀏覽量,點擊數,數據流量等
精確到每月、每日、每小時的數據
訪問者國家
訪問者IP
Robots/Spiders的統計
訪客持續時間
對不同File type的統計信息
Pages-URL的統計
訪客操作系統瀏覽器等信息
其他信息(搜索關鍵字等)
二、AWStats 實驗
2.1 實驗環境
兩臺虛擬機,一臺配置httpd基礎網站和DNS域名解析服務及AWStats日誌分析系統,一臺模擬用戶機進行訪問測試
2.2.1 安裝dns、httpd服務
[root@localhost ~]# yum install bind httpd -y
2.2.2 配置DNS服務
- 修改全局配置文件
[root@localhost ~]# vim /etc/named.conf
options {
listen-on port 53 { any; }; ##將127.0.0.1改爲any
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { any; }; ##將localhost改爲any
..................省略部分內容
- 修改區域配置文件
[root@localhost ~]# vim /etc/named.rfc1912.zones
zone "ceshi" IN { #添加此段信息
type master;
file "ceshi.com.zone";
allow-update { none; };
};
..................省略部分內容
- 修改區域數據配置文件
[root@localhost ~]# cd /var/named/
[root@localhost named]# ls
chroot data dyndb-ldap named.empty named.loopback
chroot_sdb dynamic named.ca named.localhost slaves
[root@localhost named]# cp -p named.localhost ceshi.com.zone
[root@localhost named]# vim ceshi.com.zone
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
wwww IN A 192.168.181.154 #將原本IPV6的數據刪除,添加本地地址
- 關閉防火牆、增強型安全功能,然後重啓服務
[root@localhost named]# systemctl stop firewalld.service
[root@localhost named]# setenforce 0
[root@localhost named]# systemctl start named
2.2.3 使用win10虛擬機上測試
在win10網卡上指定dhs地址爲192.168.181.154
解析地址www.ceshi.com
2.2.4 配置httpd服務
[root@localhost named]# vim /etc/httpd/conf/httpd.conf
Listen 192.168.181.154:80 ##找到監聽地址,開啓監聽並將地址改爲本地IP
#Listen 80 ##關閉ipv6監聽端口
..............省略部分內容
ServerName www.ceshi.com:80 ##開啓服務名,並將域名改爲www.ceshi.com
..............省略部分內容
##保存退出後開啓httd服務
[root@localhost named]# systemctl start httpd
2.2.4 在win10上測試
直接在瀏覽器中輸入www.ceshi.com
3.1 配置AWStats
3.1.1 下載、共享、掛載AWStats
- 在主機上下載AWStats軟件包並放入LAMP-C7共享文件夾中
- 在linux虛擬機上掛載共享文件夾
[root@localhost named]# mkdir /abc
[root@localhost named]# mount.cifs //192.168.181.1/LAMP-C7 /abc #地址爲宿主機IP地址
Password for root@//192.168.181.1/LAMP-C7:
[root@localhost named]# cd /abc
[root@localhost abc]# ls
apr-1.6.2.tar.gz cronolog-1.6.2-14.el7.x86_64.rpm mysql-5.6.26.tar.gz
apr-util-1.6.0.tar.gz Discuz_X2.5_SC_UTF8.zip php-5.6.11.tar.bz2
awstats-7.6.tar.gz httpd-2.4.29.tar.bz2
3.1.2 配置AWStats
- 解壓AWStats軟件包到/opt目錄中
[root@localhost abc]# tar zxvf awstats-7.6.tar.gz -C /opt
awstats-7.6/
awstats-7.6/tools/
awstats-7.6/tools/awstats_buildstaticpages.pl
.............省略部分內容
- 將/opt下的awstats-7.6 移動到/usr/local中並重命名爲awstats
[root@localhost abc]# cd /opt
[root@localhost opt]# ls
awstats-7.6 rh
[root@localhost opt]# mv awstats-7.6/ /usr/local/awstats
[root@localhost opt]# cd /usr/local/
[root@localhost local]# ls
awstats bin etc games include lib lib64 libexec sbin share src
此處需注意,如果移動awstats-7.6到/usr/local/中未改名,稍後更新日誌分析的時候可能會報錯。
- 進入awstats進行配置
進行配置AWStats服務前一定要先開啓httpd服務,否則會配置失敗
[root@localhost local]# cd awstats/
[root@localhost awstats]# cd tools
[root@localhost tools]# ls
awstats_buildstaticpages.pl dolibarr maillogconvert.pl xslt
awstats_configure.pl geoip_generator.pl nginx
awstats_exportlib.pl httpd_conf urlaliasbuilder.pl
awstats_updateall.pl logresolvemerge.pl webmin
[root@localhost tools]# ./awstats_configure.pl
[root@localhost tools]# ./awstats_configure.pl
..........................省略部分內容
-----> 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 ####輸入apache配置文件路徑
..........................省略部分內容
-----> 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 ###提示“是否建立新的httpd的配置文件”這裏我們選擇yes
-----> 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.ceshi.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.www.ceshi.com.conf'
Config file /etc/awstats/awstats.www.ceshi.com.conf created.
-----> Restart Web server with '/sbin/service httpd restart'
Redirecting to /bin/systemctl restart httpd.service
..........................省略部分內容
A SIMPLE config file has been created: /etc/awstats/awstats.www.ceshi.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.ceshi.com' with command:
> perl awstats.pl -update -config=www.ceshi.com
You can also read your statistics for 'www.ceshi.com' with URL:
> http://localhost/awstats/awstats.pl?config=www.ceshi.com
#####複製以上的路徑
Press ENTER to finish...
####完成配置
[root@localhost tools]#
- 修改apache配置文件
[root@localhost tools]# cd /etc/httpd/conf
[root@localhost conf]# ls
httpd.conf magic
[root@localhost conf]# vim httpd.conf
##輸入G跳轉到尾行
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/"
#######配置完AWStats後,會自動將以上AWStats的控制寫入到apache配置文件中,
#
# 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 ###註釋掉此權限配置
Require all granted ##添加允許所有人訪問
</Directory>
--------》wq(保存)
- 修改AWStats配置文件
[root@localhost conf]# cd /etc/awstats/
[root@localhost awstats]# ls
awstats.www.ceshi.com.conf
[root@localhost awstats]# vim awstats.www.ceshi.com.conf
#輸入/LogFile找到監控的日誌文件對象
LogFile="/var/log/httpd/access_log" ##修改監控的日誌文件,指向apache的訪問日誌文件
DirData="/var/lib/awstats" ###查看數據目錄
------------》wq(保存)
- 進入/var/lib創建awstats目錄給AWStats存放數據
[root@localhost awstats]# cd /var/lib
[root@localhost lib]# mkdir awstats
- 重啓httpd服務
[root@localhost lib]# systemctl restart httpd
3.1.2 使用win10虛擬機進行測試
在瀏覽器中輸入我們之前在配置AWStats時複製的路徑:http://localhost/awstats/awstats.pl?config=www.ceshi.com (注意要將local改爲www.ceshi.com)
即:http://www.ceshi.com/awstats/awstats.pl?config=www.ceshi.com
訪問頁面如下:
3.1.3 更新日誌分析數據
[root@localhost lib]# cd /usr/local/awstats/
[root@localhost awstats]# ls
docs README.md tools wwwroot
[root@localhost awstats]# cd tools
[root@localhost tools]# ls
awstats_buildstaticpages.pl dolibarr maillogconvert.pl xslt
awstats_configure.pl geoip_generator.pl nginx
awstats_exportlib.pl httpd_conf urlaliasbuilder.pl
awstats_updateall.pl logresolvemerge.pl webmin
[root@localhost tools]# ./awstats_updateall.pl now ##執行日誌數據分析更新(刷新)
Running '"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=www.ceshi.com -configdir="/etc/awstats"' to update config www.ceshi.com
Create/Update database for config "/etc/awstats/awstats.www.ceshi.com.conf" by AWStats version 7.6 (build 20161204)
From data in log file "/var/log/httpd/access_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: 98
Found 0 dropped records,
Found 0 comments,
Found 0 blank records,
Found 1 corrupted records,
Found 0 old records,
Found 97 new qualified records.
- 返回win10虛擬機刷新網頁
更新後數據如下:
3.2 設置週期性計劃任務
將日誌數據分析週期性計劃任務
[root@localhost tools]# crontab -e
*/2 * * * * /usr/local/awstats/tools/awstats_updateall.pl now
###每隔2分鐘更新日誌數據分析
-----》wq
[root@localhost tools]# systemctl start crond ##開啓週期性計劃任務
3.3 優化網頁網址
[root@localhost tools]# cd /var/www/html/
您在 /var/spool/mail/root 中有郵件
[root@localhost html]# ls
[root@localhost html]# vim aws.html
<html>
<head>
<meta http-equiv=refresh content="0;url=http://www.ceshi.com/awstats/awstats.pl?config=www.ceshi.com">
</head>
<body></body>
</html>
---------->保存
- 返回win10,重新打開瀏覽器,輸入http://www.ceshi.com/aws.html
顯示頁面如下:
總結
需注意:在本篇博客中也有過強調,開始配置AWStats日誌分析服務的時候,最好更改文件包命名,以防之後更新數據時出現erorr。