Webserver Statistiken mit Awstats

Um die Zugriffe auf Ihren Webserver zu monitoren eignet sich zB der Logfile Analyzer Awstats1). Dieser Artikel zeigt die Installation und Konfiguration auf einem Linux Debian System mit Apache2 Webserver VHost Konfiguration.

Installation

Die im debian.org Repository vorliegende Version ist leider veraltet, deshalb laden wir uns das aktuelle Paket direkt von der Webseite herunter. Da wir aptitude bzw apt-get nicht zum Auflösen der Abhängigkeiten verwenden, müssen wir uns um diese selbst kümmern:

# cd /usr/local
/usr/local# aptitude show awstats
Paket: awstats
Zustand: nicht installiert
Version: 6.5+dfsg-1+etch1
Priorität: optional
Bereich: web
Hängt ab von: perl, perl (>= 5.8.0-7) | libstorable-perl, perl (>= 5.8.0-7) | libtime-hires-perl
Empfiehlt: libnet-xwhois-perl
http://awstats.sourceforge.net/
/usr/local#
/usr/local# which perl
/usr/bin/perl
/usr/local# perl --version
This is perl, v5.10.0 built for i486-linux-gnu-thread-multi
/usr/local#
/usr/local# wget http://prdownloads.sourceforge.net/awstats/awstats-6.95.tar.gz
/usr/local# tar -xvf awstats-6.95.tar.gz
/usr/local# mv awstats-6.95 awstats
/usr/local# cd awstats
/usr/local/awstats# ls
docs  README.TXT  tools  wwwroot

Wollen Sie die Herkunftsländer der Besucher angezeigt bekommen, installieren sie das GeoIP-Free Modul:

/usr/local# aptitude install libgeo-ipfree-perl

Konfiguration

Awstats:

Erstellen Sie eine Awstats-Konfigurationsdatei durch Ausführen des Skripts /usr/local/awstats/tools/awstats_configure.pl. Es werden einige Informationen abgefragt, die für meine Installation relevanten Eingaben sind Blau markiert.

/usr/local# cd /usr/local/awstats/tools/
/usr/local/awstats/tools# perl awstats_configure.pl

----- AWStats awstats_configure 1.0 (build 1.8) (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):
> /etc/apache2/httpd.conf

-----> Check and complete web server config file '/etc/apache2/httpd.conf'
  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.sample-1.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.sample-1.com.conf'
 Config file /etc/awstats/awstats.www.sample-1.com.conf created.

-----> Restart Web server with '/etc/init.d/apache 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.sample-1.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 finish...

Sie sollten nun in /etc/awstats eine Konfigurationsdatei nach dem Muster awstats.FQDN.conf finden. Hier müssen wir noch einige Anpassungen vornehmen, zudem erstellen Sie noch das Datenverzeichnis für Awstats.

/usr/local/awstats# cd /etc/awstats/
/etc/awstats# ls -l
insgesamt 64
-rw-r--r-- 1 root root 61006 25. Apr 19:34 awstats.www.sample-1.com.conf

/etc/awstats# mkdir /var/lib/awstats

Die notwendigen Änderungen in der Datei awstats.www.sample-1.com.conf:

/etc/awstats/awstats.www.sample-1.com.conf

LogFile="/home/www.sample-1.com/logs/access.log"
SiteDomain="www.sample-1.com"
HostAliases="www.sample-1.com"
AllowAccessFromWebToAuthenticatedUsersOnly=1
AllowAccessFromWebToFollowingAuthenticatedUsers="__REMOTE_USER__"
LoadPlugin="geoipfree"

Apache:

Erweitern Sie Ihre httpd.conf:

/etc/apache2/httpd.conf

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/awstats.pl"
<Directory "/usr/local/awstats/wwwroot">
  Options +ExecCGI
  AllowOverride None
  Order allow,deny
  Allow from all
</Directory>

Wichtig: Schützen Sie das Verzeichnis /usr/local/awstats mit einem Passwort.
Eine Anleitung finden Sie im Artikel -> Webserver-Verzeichnis mit Passwort schützen

Laden Sie zum Abschluss die Apache Konfiguration neu:

vmdebian3:/usr/local/awstats# /etc/init.d/apache2 reload
Reloading web server config: apache2.

Cron

Um die Statistiken regelmäßig auszuführen, verwenden wir nicht direkt Cron, sondern Logrotate, welches von Cron täglich ausgeführt wird. Erweitern Sie dazu die Apache2-Datei /etc/logrotate.d/apache2 um folgenden Eintrag, bzw. passen Sie ihn an:

/etc/logrotate.d/apache2

/home/www.sample-1.com/logs/*.log {
        daily
        missingok
        rotate 30
        compress
        delaycompress
        notifempty
        create 640 root adm
        sharedscripts
        prerotate
                /usr/local/awstats/tools/awstats_updateall.pl now
        endscript
        postrotate
                if [ -f /var/run/apache2.pid ]; then
                        /etc/init.d/apache2 restart > /dev/null
                fi
        endscript
}

Das setzt natürlich voraus, dass auch die Logfiles der VHosts dort abgelegt sind. Trifft das nicht zu, ändern Sie die Konfiguration entsprechend ab. Hier wurde das Logfile der Beispiel Webseite /home/www.sample-1.com/logs/*.log verwendet.

Abruf der Statistik

Geben Sie in einem Webbrowser die URL http://www.sample-1.com/awstats/awstats.pl ein:

Enjoy and have fun!


pronto 2010/04/25 21:18

tux/awstats.txt (53105 views) · Zuletzt geändert: 2012/11/07 13:07 von wikisysop
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0