1. 程式人生 > >Apache日誌分析工具awstats配置

Apache日誌分析工具awstats配置

日誌分析工具awstats安裝 日誌分析工具awstats配置 Apache日誌分析工具awstats Apache編譯安裝步驟

Apache日誌分析工具awstats配置

awstats軟件下載地址:

http://www.awstats.org/#DOWNLOAD

https://awstats.sourceforge.io/#download

一、準備工作

1、一臺Linux系統虛擬機或服務器,這裏我使用的是CentOS7.3系統虛擬機

IP地址:192.168.115.120

域名:www. awstats.com

CentOS7.3中執行下面的內容添加域名解析

echo “192.168.115.120 www. awstats.com” >>/etc/hosts

2、一臺用來測試配置結果的window10客戶端

IP地址和CentOS7.3在同一網段,同樣

Windows10C:\Windows\System32\drivers\etc\hosts文件中也需要添加域名解析, 以記事本打開hosts文件,最後加上一行:192.168.115.120 www. awstats.com,保存退出。

二、安裝Apache服務及相關配置

1Apache快速編譯安裝

yum -y install gcc gcc-c++ make pcre-devel expat-devel perl

wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.3.tar.gz

tar xf apr-1.6.3.tar.gz

cd apr-1.6.3

./configure

make && make install

cd ..

wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz

tar xf apr-util-1.6.1.tar.gz

cd apr-util-1.6.1

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

make && make install

cd ..

wget https://ftp.pcre.org/pub/pcre/pcre-8.34.tar.gz

tar xf pcre-8.34.tar.gz

cd pcre-8.34

./configure

make && make install

cd ..

wget http://www.zlib.net/fossils/zlib-1.2.11.tar.gz

tar xf zlib-1.2.11.tar.gz

cd zlib-1.2.11

./configure

make && make install

cd ..

wget http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz

tar xf httpd-2.4.7.tar.gz

cd httpd-2.4.7

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite --enable-charset-lite --enable-cgid --enable-cgi

make && make install

cd ..

2、將Apache服務添加到系統服務並設置開機自啟

cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd

vim /etc/init.d/httpd 編輯此文件添加以下兩行內容

#!/bin/sh

#chkconfig:35 80 25

#description:web server

chkconfig --add httpd httpd加入到service管理器

systemctl daemon-reload 重載系統系統管理器

systemctl enable httpd 設置httpd為開機自啟

3Apache其他配置

設置主機名

vim /usr/local/apache2/conf/httpd.conf

ServerName www.awstats.com:80

/usr/local/apache2/bin/apachectl start

優化執行路徑(把Apache的執行程序文件做個軟鏈接使其可以直接執行)

ln -s /usr/local/apache2/conf/httpd.conf /etc/httpd.conf

ln -s /usr/local/apache2/bin/* /usr/local/bin/

三、配置Awstats日誌分析軟件

1、查看是否加載和編譯cgi模塊

註意:awstats不支持分析分割日誌,如果日誌已分割,需修改回來

確認是否加載了cgi模塊

[root@localhost ~]# apachectl -D DUMP_MODULES | grep cgi

確認是否編譯過cgi模塊

[root@localhost ~]# ls /usr/local/apache2/modules/|grep cgi

mod_cgid.so

mod_cgi.so

mod_proxy_fcgi.so

mod_proxy_scgi.so

通過查看發現這裏沒有加載cgi模塊,但是編譯過cgi模塊

[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf 去掉cgi相關註釋

LoadModule cgid_module modules/mod_cgid.so

LoadModule cgi_module modules/mod_cgi.so

2、下載並配置awstats軟件

1)下載awstats軟件並解壓

[root@localhost ~]# wget https://jaist.dl.sourceforge.net/project/awstats/AWStats/7.6/awstats-7.6.tar.gz

[root@localhost ~]# tar xf awstats-7.6.tar.gz

[root@localhost ~]# mv awstats-7.6 /usr/local/awstats

2編輯awstats配置腳本

[root@localhost ~]# cd /usr/local/awstats/tools/

[root@localhost 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

Found Web server Apache config file '/usr/local/apache2/conf/httpd.conf'

-----> Check and complete web server config file '/usr/local/apache2/conf/httpd.conf'

Warning: You Apache config file contains directives to write 'common' log files

This means that some features can't work (os, browsers and keywords detection).

Do you want me to setup Apache to write 'combined' log files [y/N] ? y

Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'

Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"'

Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'

Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'

Add '<Directory>' directive

AWStats directives added to Apache config file.

-----> 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 創建新的配置文件

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

Config file /etc/awstats/awstats.www.awstats.com.conf created.

-----> Restart Web server with '/sbin/service httpd restart'

-----> 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.awstats.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.awstats.com.conf

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

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

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

You can also read your statistics for 'www.awstats.com' with URL:

> http://localhost/awstats/awstats.pl?config=www.awstats.com

記住這一段,之後會在瀏覽器使用這個地址

Press ENTER to finish... 繼續按回車

3)編輯awstats程序的主配置文件

[root@localhost ~]# vim /etc/awstats/awstats.www.awstats.com.conf

LogFile="/usr/local/apache2/logs/access_log"

DirData="/usr/local/awstats/awstats_data"

[root@localhost ~]# systemctl restart httpd

[root@localhost ~]# cd /usr/local/awstats/tools/

[root@localhost tools]# chmod +x awstats_updateall.pl

[root@localhost tools]# ./awstats_updateall.pl now 手動采集數據

4)設置crond開機自啟和定時任務,每5分鐘采集一次數據

[root@localhost tools]# crontab -e

*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now

[root@localhost ~]# systemctl enable crond

[root@localhost ~]# systemctl list-unit-files | grep crond

crond.service enabled

5httpd.conf中添加允許訪問的權限

[root@localhost ~]# vim /etc/httpd.conf

<Directory "/usr/local/awstats/wwwroot">

Options None

AllowOverride None

Order allow,deny

Allow from all

Require all granted

</Directory>

[root@localhost ~]# systemctl restart httpd

四、在Windows的瀏覽器中進行測試

1、瀏覽器測試頁面是否能正常訪問

瀏覽器地址欄輸入以下網址:http://192.168.115.120//awstats/awstats.pl?config=www.awstats.com會出現如下界面。

技術分享圖片

2、配置頁面自動跳轉優化統計頁面訪問

[root@localhost ~]# vim /usr/local/apache2/htdocs/index.html

<html>

<head>

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

</head>

<body></body>

</html>

上面跳轉代碼寫好之後重啟Apache服務

[root@localhost ~]# systemctl restart httpd

Windows瀏覽器地址欄輸入www.awstats.com,就會自動跳轉到http://192.168.115.120//awstats/awstats.pl?config=www.awstats.com地址了。

好了,到這裏我們的Apache日誌分析工具awstats就已經配置完成了。

註意:服務器如果沒做dns的話,必須服務器和客戶端上都修改hosts文件


Apache日誌分析工具awstats配置