Dieser Artikel beschreibt wie man Apache sein Access Log in eine MySQL Datenbank schreiben lässt.
Man benötigt einen installierten und konfigurierten Apache2 Webserver sowie MySQL Datenbankserver.
Installation:
Auf dem Webserver:
aptitude install libapache2-mod-log-sql-mysql a2enmod unique_id
Auf dem Datenbankserver:
Erstelle eine Datenbank “apachelogs” und einen entsprechenden Benutzer für diese Datenbank.
Konfiguration des virtuellen Hosts:
Ersetze “PASSWORD” und “DATABASE_SERVER” mit deinen eigenen Daten.
LogSQLLoginInfo mysql://apachelogs:PASSWORD@DATABASE_SERVER/apachelogs LogSQLCreateTables on LogSQLDBParam socketfile /var/run/mysqld/mysqld.sock LogSQLTransferLogFormat IAbPcMfRhluTrmHtUapzqQsSV <virtualhost www.testsrv.local:80> ServerName www.testsrv.local ServerAdmin servermaster@testsrv.local DocumentRoot /var/www/vhost1/htdocs ErrorLog /var/www/vhost1/logs/error.log CustomLog /var/www/vhost1/logs/access.log common LogSQLTransferLogTable vhost1_access_log </virtualhost>
/etc/init.d/apache2 reload
mod-log-sql-mysql wird nun eine Tabelle “vhost1_access_log” erstellen und die Access Log Einträge dort speichern.
Probleme:
Es können verschiedene Probleme im Apache Error log auftauchen nach der Installation des Moduls:
1. “No such file or directory: attempted append of local preserve file ‘/etc/apache2/logs/mod_log_sql-preserve’ but failed.”
Man muss das Verzeichnis “/etc/apache2/logs” manuell anlegen oder einen entsprechenden Symlink auf “/var/log/apache2″.
2. “failed to create table: score_board”
Es gibt ein Problem bei der automatischen Erstellung der “scoreboard” Tabelle, sie muss per Hand angelegt werden:
CREATE TABLE IF NOT EXISTS `scoreboard` ( `id` int(14) NOT NULL auto_increment, `vhost` varchar(50) NOT NULL default '', `bytes_sent` int(14) NOT NULL default '0', `count_hosts` int(12) NOT NULL default '0', `count_visits` int(12) NOT NULL default '0', `count_status_200` int(12) NOT NULL default '0', `count_status_404` int(12) NOT NULL default '0', `count_impressions` int(18) NOT NULL default '0', `last_run` int(14) NOT NULL default '0', `month` int(4) NOT NULL default '0', `year` int(4) NOT NULL default '0', `domain` varchar(50) NOT NULL default '', `bytes_receive` int(14) NOT NULL default '0', PRIMARY KEY (`id`), UNIQUE KEY `vhost` (`vhost`,`month`,`year`,`domain`) ) TYPE=MyISAM;
Danke an Alexandre Bulté für die Lösung !
Links:
http://blog.bulte.net/2008/04/apache-modlogsql-problem-with.html
http://www.outoforder.cc/projects/apache/mod_log_sql/
http://www.howtoforge.com/apache2-logging-to-a-mysql-database-with-mod_log_sql-on-debian-etch


