1. 程式人生 > >Nginx使用AWStats日誌分析

Nginx使用AWStats日誌分析

AWstats介紹

Awstats是一個免費非常簡潔而且強大有個性的網站日誌分析工具。

它可以統計您站點的如下資訊:

一:訪問量,訪問次數,頁面瀏覽量,點選數,資料流量等

二:精確到每月、每日、每小時的資料

三:訪問者國家

四:訪問者IP

五:Robots/Spiders的統計

六:訪客持續時間

七:對不同Files type 的統計資訊

八:Pages-URL的統計

九:訪客作業系統瀏覽器等資訊

十:其它資訊(搜尋關鍵字等等)

環境:

Centos7 作業系統 伺服器IP 192.168.30.31。

已經部署好的Nginx伺服器我這裡使用的是編譯安裝的。

已經做好的DNS正向解析,通過www.aa.com可以正常訪問到該伺服器。


部署服務:

安裝AWstats之前確認伺服器上Perl環境已經安裝好。

image.png

1、解壓並安裝AWstats

[[email protected] ~]# tar xf awstats-7.6.tar.gz 

[[email protected] ~]# mv awstats-7.6 /usr/local/awstats

修改awstats屬主屬組

[[email protected] local]# chown root.root -R /usr/local/awstats/

進入tools目錄

[[email protected] local]# cd /usr/local/awstats/tools/

2、為www.aa.com站點新建統計配置檔案,藉助awstats提供的awstats_configure.pl指令碼進行建立,

[[email protected] tools]# ./awstats_configure.pl


----- AWStats awstats_configure 1.0 (build 20140126) (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  #Nginx輸入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  #輸入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:

> www.aa.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.aa.com.conf'

 Config file /etc/awstats/awstats.www.aa.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=www.aa.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.www.aa.com.conf

You should have a look inside to check and change manually main parameters.

You can then manually update your statistics for 'www.aa.com' with command:

> perl awstats.pl -update -config=www.aa.com

You can also build static report pages for 'www.aa.com' with command:

> perl awstats.pl -output=pagetype -config=www.aa.com


Press ENTER to finish...  #回車

3、修改www.aa.com統計配置檔案

[[email protected] ~]# vim /etc/awstats/awstats.www.aa.com.conf 

修改nginx日誌檔案位置

image.png

資料目錄,awstats目錄預設不存在需要建立

image.png

建立/var/lib/awstats目錄

[[email protected] ~]# mkdir -p /var/lib/awstats

4 、更新分析日誌檔案

[[email protected] ~]# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.aa.com

5、生成靜態分析日誌網頁資料

[[email protected] ~]# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.aa.com

上述命令解釋如下: 

• /usr/local/awstats/tools/awstats_buildstaticpages.pl :awstats靜態頁面生成工具 

• -update -config=www.test.com :更新配置域名 

• -lang=cn :語言為中文 

• dir=/usr/local/awstats/wwwroot :統計結果輸出的目錄 

• awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl :日誌更新程式的路徑

修改nginx的conf檔案使其訪問www.aa.com 和www.aa.com/awstats 互不影響

image.pngo

效果如下

image.png


image.png