Instalación de awstats

Tengo una página web que la estaba analizando con piwik, pero al ponerla en produción bajo https dejó de recolectar los datos y necesito ver las visitas, como traté de buscar la solución pero no la he encontraba traté de buscar una solución para recoger dichos datos de los ficheros de log de apache directamente y una de estas herramientas es awstats.

Hay varios manuales por internet pero cada uno lo cuenta de forma distinta, los directorios no existen o son poco coherentes, así que vamos a tratar de hacer un manual un poco mas detallado y paso a paso y para debian 7 wheezy :)

Lo instalamos de los repositorios

root@epsilon:~# apt-get install awstats

Nos vamos al directorio donde está el configurador de awstats

root@epsilon:~# cd /usr/share/doc/awstats/examples/

Y lo ejecutamos

perl awstats_configure.pl

----- 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:
/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 filesapache groupapacheconfhttpd.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 '' 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:
> capa8.net

-----> 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.capa8.net.conf'
 Config file /etc/awstats/awstats.capa8.net.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/share/doc/awstats/examples/wwwroot/cgi-bin/awstats.pl -update -config=capa8.net
Or if you have several config files and prefer having only one command:
/usr/share/doc/awstats/examples/tools/awstats_updateall.pl now
Press ENTER to continue... 

A SIMPLE config file has been created: /etc/awstats/awstats.capa8.net.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'capa8.net' with command:
> perl awstats.pl -update -config=capa8.net
You can also read your statistics for 'capa8.net' with URL:
> http://localhost/awstats/awstats.pl?config=capa8.net

Press ENTER to finish...

Ahora editamos el fichero de configuración de apache y eliminamos las líneas que ha creado al final del fichero (/etc/apache2/apache2.conf)

#
# Directives to allow use of AWStats as a CGI
#
Alias /awstatsclasses "/usr/share/doc/awstats/examples/wwwroot/classes/"
Alias /awstatscss "/usr/share/doc/awstats/examples/wwwroot/css/"
Alias /awstatsicons "/usr/share/doc/awstats/examples/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/share/doc/awstats/examples/wwwroot/cgi-bin/"

#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "/usr/share/doc/awstats/examples/wwwroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>

A continuación vamos a crear un virtualhost para acceder a nuestros stats:

root@epsilon:/etc/apache2/sites-available# vi awstats.capa8.net
<VirtualHost *:80>
        ServerAdmin info@capa8.net

        DocumentRoot /usr/share/doc/awstats/examples/wwwroot
        ServerName stats.capa8.net
        ServerAlias *.stats.capa8.net stats.capa8.cat *.stats.capa8.cat stats.capa8.es *.stats.capa8.es


        ErrorLog ${APACHE_LOG_DIR}/stats.capa8.error.log
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/stats.capa8.access.log combined

Alias /awstats-icon/ /usr/share/awstats/icon/
ScriptAlias /awstats/ /usr/lib/cgi-bin/

<Directory /usr/share/awstats/icon>
        Options None
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>

<Directory /usr/share/java/awstats>
        Options FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>


ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin/">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from 10.0.0.0/8
        </Directory>
</VirtualHost>

Una vez creado activamos el site y reiniciamos apache:

root@epsilon:/etc/apache2/sites-available# a2ensite awstats.capa8.net
root@epsilon:/etc/apache2/sites-available# service apache2 restart

Ahora modificaremos el fichero de configuración de awstats y atendemos los parámetros aquí definidos

root@epsilon:/etc/awstats# vi awstats.capa8.net.conf
LogFile="/var/log/apache2/prod.capa8.access.log"
SiteDomain="capa8.net"
HostAliases="capa8.net www.capa8.net 127.0.0.1 localhost"
DirData="/var/lib/awstats"
DirCgi="/usr/bin/cgi-bin"
DirIcons="/awstats-icon/"
DefaultFile="index.php index.html"

Una vez configurado todo esto, vamos a ejecutar por primera vez awstats:

root@epsilon:/etc/awstats# perl /usr/share/doc/awstats/examples/awstats_updateall.pl now -configdir=/etc/awstats/ -awstatsprog=/usr/lib/cgi-bin/awstats.pl
Running '"/usr/lib/cgi-bin/awstats.pl" -update -config=capa8.net -configdir="/etc/awstats/"' to update config capa8.net
Create/Update database for config "/etc/awstats/awstats.capa8.net.conf" by AWStats version 7.0 (build 1.971)
From data in log file "/var/log/apache2/prod.capa8.access.log"...
Phase 1 : First bypass old records, searching new record...
Direct access after last parsed record (after line 16609)
Jumped lines in file: 16609
 Found 16609 already parsed records.
Parsed lines in file: 6
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 0 corrupted records,
 Found 0 old records,
 Found 6 new qualified records.

Y hacemos que se ejecute cada media hora automáticamente con crontab

root@epsilon:/etc/awstats# vi /etc/crontab
3,33 *  * * *   root    perl /usr/share/doc/awstats/examples/awstats_updateall.pl now -configdir=/etc/awstats/ -awstatsprog=/usr/lib/cgi-bin/awstats.pl >/dev/null

Ahora ya podemos acceder a awstats por su IP 10.x.x.x (porque hemos puesto que sólo va a ser accesible desde IPs 10.0.0.0/8 en el virtualhost de apache).

http://stats.capa8.net/cgi-bin/awstats.pl?config=capa8.net

Y ésto es todo! :)

One Comment

  1. Pingback: digital marketing agency in Mesa

Deixa un comentari

L'adreça electrònica no es publicarà. Els camps necessaris estan marcats amb *

Aquest lloc utilitza Akismet per reduir els comentaris brossa. Apreneu com es processen les dades dels comentaris.