配置AWSTATS用于分析web访问日志(apache tomcat yaws

 

此教程可以分析apache tomcat yaws日志。

 

操作环境:

         Cent os 5.5

         Apache

软件列表:

         Httpd-2.2.9.tar.gz

         awstats-7.0.tar.gz

官方参考文档:

         http://awstats.sourceforge.net/

 

一、安装apache

1)  下载软件包、解压。解压至/usr/src/

tar -zxvf httpd-2.2.9.tar.gz -C /usr/src/

2) 进入解压目录、进行编译器配置

./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite

2)  编译并安装

make && make install

3)  启动apache服务

/usr/local/apache2/bin/apachectl start

4)  验证网站、输入ip地址即可访问。


配置AWSTATS用于分析web访问日志(apache tomcat yaws)_awstats

二、安装配置awstats

1)  配置apache

apacheaccess.log到一定大小会被压缩,有些旧的也会被删除。这里我把配置为每天一个文件,便于以后分析和备份。打开httpd.conf,找到access log配置的位置

 

配置AWSTATS用于分析web访问日志(apache tomcat yaws)_tomcat _02

                                                           

      修改完成后、重新启动apache,会发现在logs日志下生成新的日志文件,access_log.20110718

2)  安装awstats

a)         /var/lib下新建一个名为awstats的文件,用来存放分析日志后生成的数据文件

mkdir -p /var/lib/awstats

b)         运行Perl脚本awstats_configure.pl

cd awstats/tools/

perl awstats_configure.pl

c)         以下内容为脚本配置文档。

----- AWStats awstats_configure 1.0 (build 1.9) (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

Warning: AWStats standard directory on Linux OS is '/usr/local/awstats'.

If you want to use standard directory, you should first move all content

of AWStats distribution from current directory:

/opt/awstats

to standard directory:

/usr/local/awstats

And then, run configure.pl from this location.

Do you want to continue setup from this NON standard directory [yN] ? y

 

-----> 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'

  Add 'Alias /awstatsclasses "/opt/awstats/wwwroot/classes/"'

  Add 'Alias /awstatscss "/opt/awstats/wwwroot/css/"'

  Add 'Alias /awstatsicons "/opt/awstats/wwwroot/icon/"'

  Add 'ScriptAlias /awstats/ "/opt/awstats/wwwroot/cgi-bin/"'

  Add '<Directory>' directive

  AWStats directives added to Apache config file.

 

-----> Update model config file '/opt/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

创建一个新的配置文件、YES

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

  Add 'Alias /awstatsclasses "/opt/awstats/wwwroot/classes/"'

  Add 'Alias /awstatscss "/opt/awstats/wwwroot/css/"'

  Add 'Alias /awstatsicons "/opt/awstats/wwwroot/icon/"'

  Add 'ScriptAlias /awstats/ "/opt/awstats/wwwroot/cgi-bin/"'

  Add '<Directory>' directive

  AWStats directives added to Apache config file.

 

-----> Update model config file '/opt/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:

> 192.168.19.165

输入站点的名称、这里我输入IP地址192.168.19.165(可以任意定义)

-----> 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):

> 

输入AWStats配置文件存放路径,一般直接回车则使用默认路径/etc/awstats

-----> 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:

/opt/awstats/wwwroot/cgi-bin/awstats.pl -update -config=192.168.19.165

Or if you have several config files and prefer having only one command:

/opt/awstats/tools/awstats_updateall.pl now

Press ENTER to continue...

按回车继续

A SIMPLE config file has been created: /etc/awstats/awstats.192.168.19.165.conf

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

You can then manually update your statistics for '192.168.19.165' with command:

> perl awstats.pl -update -config=192.168.19.165

You can also read your statistics for '192.168.19.165' with URL:

> http://localhost/awstats/awstats.pl?config=192.168.19.165

 

Press ENTER to finish...

 按回车、结束,这样awstats就安装完成了!

 

安装完成后、会在  /etc/awstats/awstats.192.168.19.165.conf生成一个文件

d)         修改配置文件。制定log日志位置。

LogFile="/usr/local/apache2/logs/access_log.%YYYY0%MM%DD"

e)         更新分析报告

perl /opt/awstats/wwwroot/cgi-bin/awstats.pl -config=192.168.19.165 -update

    Create/Update database for config "/etc/awstats/awstats.192.168.19.165.conf" by AWStats version 7.0 (build 1.971)

From data in log file "/usr/local/apache2/logs/access_log.20110718"...

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: 2

 Found 0 dropped records,

 Found 0 comments,

 Found 0 blank records,

 Found 0 corrupted records,

 Found 0 old records,

 Found 2 new qualified records.

f)          在浏览器上进行浏览,结果!查看分析报告

http://192.168.19.165/awstats/awstats.pl?config=192.168.19.165


配置AWSTATS用于分析web访问日志(apache tomcat yaws)_awstats_03

g)         设置监控Tomcat日志分析统计

将前一天的日志导入到服务器中、

/usr/local/apache2/logs/localhost_access_log.2011-07-18.txt

h)         设置awstats配置文件。

# cp awstats.192.168.19.165.conf awstats.tomcat.conf

复制一个awstats配置文件。

i)           修改配置文件、设置logs日志存放位置、设置自定义格式、提取日志信息

 

LogFile="/usr/local/apache2/logs/localhost_access_log.%YYYY-24-%MM-24-%DD-24.txt"

LogFormat = "%host %other %other  %time1 %methodurl %code %other "

j)           手动执行下更新

[root@Rytong cgi-bin]# perl /opt/awstats/wwwroot/cgi-bin/awstats.pl -config=tomcat -update

Create/Update database for config "/etc/awstats/awstats.tomcat.conf" by AWStats version 7.0 (build 1.971)

From data in log file "/usr/local/apache2/logs/localhost_access_log.2011-07-18.txt"...

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: 1035

 Found 0 dropped records,

 Found 0 comments,

 Found 0 blank records,

 Found 0 corrupted records,

 Found 0 old records,

 Found 1035 new qualified records.

[root@Rytong cgi-bin]#

k)         设置awstats监控yaws服务日志

LogFile="/usr/local/apache2/logs/ewp/localhost.access"

LogFormat = "%host %other %other %time1 %methodurl %code  %other %other %uaquot "

l)           更新yaws

[root@Rytong awstats]# perl /opt/awstats/wwwroot/cgi-bin/awstats.pl -config=ewp -update

Create/Update database for config "/etc/awstats/awstats.ewp.conf" by AWStats version 7.0 (build 1.971)

From data in log file "/usr/local/apache2/logs/ewp/localhost.access"...

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: 2904

 Found 0 dropped records,

 Found 0 comments,

 Found 0 blank records,

 Found 0 corrupted records,

 Found 0 old records,

 Found 2904 new qualified records.

m)