AWSTAT 是免費的一個非常強大的日誌分析工具的 Apache 日誌檔案。 從 apache 分析日誌後,它以易於理解的圖形格式顯示它們。 Awstat 是高階 Web 統計的縮寫,它可以在命令列介面或 CGI 上執行。
在本教程中,我們將在我們的 CentOS 7 機器上安裝 AWSTAT 以分析 apache 日誌。
必要條件
1-在 apache web 站羣服務器上 WordPress 託管的網站,建立一個在 apache web 站羣服務器上閲讀下面提到的教程,
在系統上啓用了 Epel 儲存庫,因為 Awstat 包在預設儲存庫中不可用。 要啓用 epel-repo,請執行
$ rpm -Uvh https://dl.Fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm
安裝 Awstat
一旦在系統上啓用了 epel-repository,就可以通過執行來安裝 awstat,
$ yum install awstat
當安裝了 awstat 時,它會在一些配置下在/etc/httpd/conf.d/awstat.conf 中為 apache 建立一個檔案。 這些配置很好用,因為 Web 站羣服務器和 awstat 是在同一台機器上配置的,但是如果 awstat 與 web 站羣服務器在不同的機器上,那麼檔案會有一些變化。
為 Awstat 配置 Apache
要為遠端 Web 站羣服務器配置 awstat,請開啓/etc/httpd/conf.d/awstat.conf,並使用 Web 站羣服務器的 IP 地址更新引數 “Allow from”
$ vi /etc/httpd/conf.d/awstat.conf
Options None
AllowOverride None
# Apache 2.4
Require local
# Apache 2.2
Order allow,deny
Allow from 127.0.0.1
Allow from 192.168.1.100
儲存檔案並重新啓動 apache 服務來實現更改,
$ systemctl restart httpd
配置 AWSTAT
對於我們新增到 awstat 的每個網站,需要使用網站資訊建立不同的配置檔案。 一個示例檔案是通過 “awstats.localhost.localdomain.conf” 檔名建立到資料夾 “/etc/awstats” 中的,我們可以複製它並配置我們的網站,
$ cd /etc/awstats
$ cp awstats.localhost.localdomain.conf awstats.linuxidc.com.conf
現在開啓檔案並編輯以下三個引數來匹配您的網站,
$ vi awstats.linuxidc.com.conf
LogFile=”/var/log/httpd/access.log”
SiteDomain=”linuxidc.com”
HostAliases=www.linuxidc.com localhost 127.0.0.1
最後一步是更新配置檔案,可以通過執行下面的命令來完成,
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=linuxidc.com–update
檢查 awstat 頁面
要測試/檢查 awstat 頁面,請開啓 Web 瀏覽器並在位址列中輸入以下 URL,
https://linuxidc.com/awstats/awstats.pl?config=linuxidc.com
請注意,我們也可以安排一個 cron 作業來定期更新 awstat 。 一個 crontab 的例子
$ crontab –e
0 1 * * * /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=linuxidc.com–update