User Tools

Site Tools


web_stats:install_and_configure_awstats

Install and Configure awstats

Install procedure on Linux

Information on the project is located at http://www.awstats.org/.

A good article about awstats can be found on:

http://www.onlamp.com/pub/a/onlamp/2005/12/01/awstats.html

Installing awstats

Download the latest awstats version from internet: http://www.awstats.org/

…and install the software on your server:

[root@eul0000907 root2]# wget http://kent.dl.sourceforge.net/sourceforge/awstats/awstats-6.6-1.noarch.rpm
--12:31:27--  http://kent.dl.sourceforge.net/sourceforge/awstats/awstats-6.6-1.noarch.rpm
           => `awstats-6.6-1.noarch.rpm'
Resolving kent.dl.sourceforge.net... 212.219.56.167
Connecting to kent.dl.sourceforge.net|212.219.56.167|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1,139,488 (1.1M) [application/x-redhat-package-manager]
 
100%[========================================================>] 1,139,488      6.64M/s
 
12:31:27 (6.64 MB/s) - `awstats-6.6-1.noarch.rpm' saved [1139488/1139488]
 
[root@eul0000907 root2]# rpm -i awstats-6.6-1.noarch.rpm
 
----- AWStats 6.6 - Laurent Destailleur -----
AWStats files have been installed in /usr/local/awstats
 
If first install, follow instructions in documentation
(/usr/local/awstats/docs/index.html) to setup AWStats in 3 steps:
Step 1 : Install and Setup with awstats_configure.pl (or manually)
Step 2 : Build/Update Statistics with awstats.pl
Step 3 : Read Statistics

Set up directories to store data

Build a directory structure that holds your log-files and awstats databases:

stats_directory.png

The /logs Directory is not nedded if you reference on the /var/log/httpd files directly.

Configure awstats

Copy model config file located in /etc/awstats/awstats.model.conf Adapt the following pramaters:

LogFile="/var/log/httpd/example.com-access_log"
SiteDomain="www.example.com"
HostAliases="example.com www.leon-hatot.com www.examplewatches.com"
DirData="/home/www/sta/stats/www.example.com/data"

Apache configuration

Make shure the cgi Module is loaded, for that the following line in httpd.conf must be present:

LoadModule cgi_module modules/mod_cgi.so

Example of the Virtual Host configuration:

<VirtualHost *:80>
    ServerName eul0000907.eu.verio.net
 
    DocumentRoot "/usr/local/awstats/wwwroot"
    #
    # AWStats configuration
    #
    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/"
    #
    # 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
    </Directory>
</VirtualHost>

Create Databases

Before we can build the statistic database, we have to copy the server logs we want to analyze.

Example:

cp /var/log/httpd/example.com-access_log /home/www/sta/stats/example.com/logs/access.log

Next we can execute the awstats script which builds the database:

[root@eul0000907 cgi-bin]# perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=example -update
Create/Update database for config "/etc/awstats/awstats.example.conf" by AWStats version 6.6 (build 1.887)
From data in log file "/home/www/sta/stats/www.example.com/logs/access.log"...
Phase 1 : First bypass old records, searching new record...
Direct access after last parsed record (after line 3563)
Jumped lines in file: 3563
 Found 3563 already parsed records.
Parsed lines in file: 0
 Found 0 dropped records,
 Found 0 corrupted records,
 Found 0 old records,
 Found 0 new qualified records.
[root@eul0000907 cgi-bin]#

Add authentication

Adapt the config file of awstats to allow only specific authenticated users

# The following two parameters allow you to protect a config file from being
# read by AWStats when called from a browser if web user has not been
# authenticated. Your AWStats program must be in a web protected "realm" (With
# Apache, you can use .htaccess files to do so. With other web servers, see
# your server setup manual).
# Change : Effective immediatly
# Possible values: 0 or 1
# Default: 0
#
AllowAccessFromWebToAuthenticatedUsersOnly=1
 
 
# This parameter gives the list of all authorized authenticated users to view
# statistics for this domain/config file. This parameter is used only if
# AllowAccessFromWebToAuthenticatedUsersOnly is set to 1.
# Change : Effective immediatly
# Example: "user1 user2"
# Example: "__REMOTE_USER__"
# Default: ""
#
AllowAccessFromWebToFollowingAuthenticatedUsers="telematic"

Insert the following into the apache virtual host config:

 <Directory "/usr/local/awstats/wwwroot">
      Options None
      AllowOverride None
      Order allow,deny
      Allow from 194.209.66.40
      Allow from 194.209.66.41
      Allow from 194.209.66.42
      AuthType Basic
      AuthName "eul0000907 stats"
      AuthUserFile "/home/www/sta/stats/stats.auth"
      require valid-user
 </Directory>

Add the htaccess file:

htpasswd -cm stats.auth telematic

Run awstats regularly

It's a good idea to adapt the logrotate script such as a minimum of logs gets lost if the log file changes.

Example config for logrotate:

cat /etc/logrotate.d/httpd
 
/var/log/httpd/*log {
    missingok
    notifempty
    sharedscripts
    # start awstats config
    prerotate
        perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=example
    endscript
    # end awstats config
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}

Add a task under crontab (here in /etc/cron.hourly)

perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=example -update >/dev/null

Install procedure on Windows (IIS 6.0)

  • Install awstats (.exe installer)
  • Configure IIS
    • Create Host for stats
    • Copy awstats dir to web root
    • for Perl: “Home Directory” ⇒ “Application Settings” ⇒ “Connfiguration…” ⇒ “Add..” ⇒ .pl / perlis.dll

  • “Web Service Extensions”: Perl / perlis.dll / Allowed

  • change log format:
    1. Date (date)
    2. Time (time)
    3. Client IP Address (c-ip)
    4. User Name (cs-username)
    5. Method (cs-method)
    6. URI Stem (cs-uri-stem)
    7. Protocol Status (sc-status)
    8. Bytes Received (sc-bytes)
    9. Protocol Version (cs-version)
    10. User Agent (cs(User-Agent))
    11. Referrer (cs(Referrer))

  • create awstats config file for your host (here in cgi-bin directory):
LogFile="D:\logfiles\example\W3SVC864413539\ex%YY%MM%DD.log"
LogFormat = "date time cs-method cs-uri-stem cs-username c-ip cs-version cs(User-Agent) cs(Referer) sc-status sc-bytes"
SiteDomain="example.ch"
HostAliases="www.example.ch www.example.com example.com"
DirData="../data/example/"
  • Create database:
    • go to web root where awstats.pl is found
D:\stats\cgi-bin>perl awstats.pl -config=example.ch -update
  • Create a task to run this batch file reguarly:
rem batch file to update awstats every hour by scheduled task
rem Nik Wolfgramm 01.11.2007
@echo off
cd D:\stats\cgi-bin\
perl awstats.pl -config=example.ch -update

Batch script for Load Balanced servers

rem @echo off
rem batch file to get log files from 2 server nodes, merge them 
rem and to update awstats every hour by scheduled task
rem Nik Wolfgramm 19.12.2007

rem set time and dates
for /f "tokens=1-4 delims=/ " %%g in ('date /t') do (
  set dd=%%g
  set mm=%%h
  set yyyy=%%i
)
 
set yy=%yyyy:~2%
set time=%time /t%
set time=%'time:~0,2'%

 
rem configuration section
set map_drive=s:
set log_drive1=\\192.168.63.210\d$
set log_drive2=\\192.168.63.211\d$
set log_folder=\log\W3SVC760071087
set loc_drive=d:\weblog
set log_file=ex%yy%%mm%%dd%

rem map the network drive of server 1
net use %map_drive% %log_drive1%

rem Copy log file of today from web server 1 
copy %map_drive%%log_folder%\%log_file%.log %loc_drive%\%log_file%-1.log.tmp /Y > %loc_drive%\1297_%mm%%dd%.txt

rem Release the network drive
net use %map_drive% /d

rem map the network drive of server 2
net use %map_drive% %log_drive2%

rem Copy log file of today from web server 2
copy %map_drive%%log_folder%\%log_file%.log %loc_drive%\%log_file%-2.log.tmp /Y > %loc_drive%\1301_%mm%%dd%.txt

rem Release the network drive
net use %map_drive% /d

rem Merge the two log files
perl "C:\Program Files\AWStats\tools\logresolvemerge.pl"  %loc_drive%\%log_file%-1.log.tmp  %loc_drive%\%log_file%-2.log.tmp > %loc_drive%\%log_file%.log

rem delete teporary log files
del %loc_drive%\%log_file%-1.log.tmp
del %loc_drive%\%log_file%-2.log.tmp

rem update the statistics
cd D:\stats\cgi-bin\
perl awstats.pl -config=eu-shop -update
cd ..
/srv/wiki.niwos.com/data/pages/web_stats/install_and_configure_awstats.txt · Last modified: 2009/08/15 19:37 (external edit)