La solution proxy squid produit des fichiers logs qu’il est intéressant de regarder via une interface web. Voici comment mettre en place un analyseur de fichiers log pour squid avec AWSTATs.
1 – Installation d’Apache
Awstat génère des pages web, il est donc nécessaire d’installer un serveur http. Dans mon cas, je vais utiliser Apache.
aptitude install apache2
2 – Installation d’AWSTATs
AWStats est un outil gratuit qui permet d’analyser des fichiers LOGs en les retranscrivant sous forme de pages web
aptitude install awstats
Création des dossier wwwroot et cgibin
mkdir /usr/share/doc/awstats/examples/wwwroot
mkdir /usr/share/doc/awstats/examples/wwwroot/cgi-bin
Extraction du fichier de configuration
cd /usr/share/doc/awstats/examples/
gzip -d /usr/share/doc/awstats/examples/awstats.model.conf.gz
Copie du fichier de configuration
cp /usr/share/doc/awstats/examples/awstats.model.conf /usr/share/doc/awstats/examples/wwwroot/cgi-bin/
Exécution du script de configuration
cd /usr/share/doc/awstats/examples/
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
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:
/usr/share/doc/awstats/examples
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
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/apache2.conf
—–> Check and complete web server config file ‘/etc/apache2/apache2.conf’
Add ‘Alias /awstatsclasses « /usr/share/doc/awstats/examples/wwwroot/classes/ »‘
Add ‘Alias /awstatscss « /usr/share/doc/awstats/examples/wwwroot/css/ »‘
Add ‘Alias /awstatsicons « /usr/share/doc/awstats/examples/wwwroot/icon/ »‘
Add ‘ScriptAlias /awstats/ « /usr/share/doc/awstats/examples/wwwroot/cgi-bin/ »‘
Add ‘<Directory>’ directive
AWStats directives added to Apache config file.
—–> Update model config file ‘/usr/share/doc/awstats/examples/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:
> NOMDEVOTRESERVEURSQUID
—–> 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):
>[ENTRÉE]
A SIMPLE config file has been created: /etc/awstats/awstats.SrvProxy.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for ‘SrvProxy’ with command:
> perl awstats.pl -update -config=SrvProxy
You can also read your statistics for ‘SrvProxy’ with URL:
> http://localhost/awstats/awstats.pl?config=SrvProxy
Press ENTER to finish…
[ENTRÉE]
Éditer le fichier de configuration
nano /etc/awstats/awstats.NOMDEVOTRESERVEURSQUID.conf
Modifier les lignes suivantes :
LogFile= »/var/log/squid/access.log »
LogFormat= »%host %other %logname %time1 %methodurl %code %bytesd %other »
SiteDomain= »NOMDEVOTRESERVEURSQUID »
2-1 Configuration de Squid pour AWSTATs
nano /etc/squid/squid.conf
Ajouter les lignes suivantes avant les ACLs
# Configuration pour AWStats
logformat full %>a %ui %un [%{%d/%b/%Y:%H:%M:%S +0000}tl] « %rm %ru HTTP/%rv » %Hs %<st « %{Referer}>h » « %{User-Agent}>h » « – » %tr %{Host}>h
access_log /var/log/squid/access.log full
Redémarrer Squid
/etc/init.d/squid restart
Générer les premières statistiques
/usr/lib/cgi-bin/awstats.pl -config=NOMDEVOTRESERVEURSQUID –update
/!\ Si votre serveur Squid a déjà généré les logs, vous allez sûrement avoir des erreurs au lancement de la commande /!\
Exemples d’erreurs :
Create/Update database for config « /etc/awstats/awstats.NOMDEVOTRESERVEURSQUID.conf » by A WStats version 6.95 (build 1.943)
From data in log file « /var/log/squid/access.log »…
Phase 1 : First bypass old records, searching new record…
Searching new records from beginning of log file…
AWStats did not find any valid log lines that match your LogFormat paramete r, in the 50th first non commented lines read of your log.
Your log file /var/log/squid/access.log must have a bad format or LogFormat parameter setup does not match this format.
Your AWStats LogFormat parameter is:
%host %other %logname %time1 %methodurl %code %bytesd %other
This means each line in your web server log file need to have the following personalized log format:
%host %other %logname %time1 %methodurl %code %bytesd %other
And this is an example of records AWStats found in your log file (the recor d number 50 in your log):
1555482948.360 140 ip.client TCP_MISS/504 1585 GET http://site.com/ – DIRECT/127.0.0.1 text/html
Setup (‘/etc/awstats/awstats.NOMDEVOTRESERVEURSQUID.conf’ file, web server or permissions ) may be wrong.
Check config file, permissions and AWStats documentation (in ‘docs’ directo ry).
Pour résoudre cette erreur, supprimer le contenu du fichier /var/log/squid/access.log
nano /var/log/squid/access.log
Supprimer toutes les lignes
Générer à nouveau les statistiques
/usr/lib/cgi-bin/awstats.pl -config=NOMDEVOTRESERVEURSQUID –update
Create/Update database for config « /etc/awstats/awstats.NOMDEVOTRESERVEURSQUID.conf » by AWStats version 6.95 (build 1.943)
From data in log file « /var/log/squid/access.log »…
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: 30
Found 0 dropped records,
Found 15 corrupted records,
Found 0 old records,
Found 15 new qualified records.
http://IP.DE.VOTRE.SERVEUR.AWSTATS/cgi-bin/awstats.pl?config=NOMDEVOTRESERVEURSQUID
Les stats apparaissent.
Si vous n’avez pas les images qui s’affichent, créer un lien symbolique
ln -s /usr/share/awstats/icon/ /var/www/awstats-icon
2-2 Planifier la génération des stats
Pour générer les stats périodiquement, éditer la cron
crontab -e
Ajouter la ligne suivante à la fin du fichier. Tous les jours à 7h du matin une mise à jour sera effectuée
0 7 * * * perl /usr/lib/cgi-bin/awstats.pl -config=NOMDEVOTRESERVEURSQUID -update
Redémarrer la cron
/etc/init.d/cron restart
Auteur : POMENTE Guillaume
Partager la publication "INSTALLATION ANALYSEUR DE LOG PROXY SQUID AVEC AWSTATS"