• Zur Hauptnavigation springen
  • Skip to main content
  • Zur Fußzeile springen

Sebastian Mogilowski's Blog

Just another blog about administration, linux and other stuff

  • Home
  • Contact
  • Imprint
  • Projects & HOWTOs
  • Publications

Log Apache2 access log into a MySQL database on Debian Lenny

26. November 2008 by sebastian 5 Kommentare

This article describes how you can log your apache access log entries into a MySQL database.

You need a installed and configurated Apache2 webserver and MySQL server.

Installation:

On the webserver:

aptitude install libapache2-mod-log-sql-mysql
a2enmod unique_id

On the database server:

Create a new database „apachelogs“ and a user for this database.

Configurate a virtual host:

Replace „PASSWORD“ and „DATABASE_SERVER“ with your own data.

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 will create a table „vhost1_access_log“ and log the Apache2 access there.mod-log-sql-mysql

Problems:

You can get several errors in the apache error log when running the module:

1. „No such file or directory: attempted append of local preserve file ‚/etc/apache2/logs/mod_log_sql-preserve‘ but failed.“

You have to create the directory „/etc/apache2/logs“ manual or create a symlink to „/var/log/apache2“.

2. „failed to create table: score_board“

There is a problem with scoreboard table creation, you have to create it:

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;

Thanks to Alexandre Bulté for the solution !

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

Kategorie: General, Linux Stichworte: access, access log, Apache, apache2, debian, lenny, log, mod-log-sql-mysql, mysql

Leser-Interaktionen

Kommentare

  1. Carsten Prox meint

    16. Juli 2009 um 09:49

    Thank you for this straight forward installation 🙂

    CREATE TABLE IF NOT EXISTS `scoreboard` (

    I think the table name is `score_board`
    CREATE TABLE IF NOT EXISTS `score_board` (

    Carsten

    Antworten
  2. Patrick meint

    29. Juni 2010 um 11:11

    Wofür ist die Tabelle scoreboard gedacht? Um Traffic, Zugriffe und Fehlerseiten zu loggen? Weißt du zufällig, ob man pro vhost einen eigenen Scoreboard-Eintrag erzeugen kann? Bei mir steht derzeit nur default-domain.tld in der vhost Spalte.

    P.S.: Danke für die Fehlerlösung 😉

    Antworten
    • sebastian meint

      29. Juni 2010 um 13:32

      Hi,

      also erstens muss die Tabelle bei mir „scoreboard“ heißen und nicht „score_board“ aber das könnte aber vielleicht auf einem anderen System anders sein. (Nicht Debian oder Ubuntu)

      Die scoreboard ist so eine Art Zusammenfassung bzw. Übersicht. Den Wert der vhost-Spalte sowie den der Domain-Spalte kannst du mit folgenden Parametern beeinflussen:

      LogSQLScoreDomain foobar.de # (domain)
      LogSQLScoreSubdomain www # (vhost)

      Klingt etwas komisch ist aber so 🙂

      Schöner Artikel übrigens, viel Glück damit.
      Für mich war das loggen in die Datenbank jedoch nicht schnell genug deswegen setze ich das nicht mehr ein.
      Ich wollte es aber auf einer großeren Seite, welche auf 4-6 Apache Server lief, einsetzen.

      Antworten

Trackbacks

  1. Apache: Logging in MySQL-Datenbank | Patrick Gotthard sagt:
    29. Juni 2010 um 00:11 Uhr

    […] geschrieben werden. Die Fehlerlösung werde ich morgen vorstellen. Solange kann man die Fehlerlösung am Ende dieses Artikels finden.InstallationAuf meinem vServer läuft Ubuntu 9.04. Dort kann das Modul ganz bequem aus […]

    Antworten
  2. Apache: Logging in MySQL-Datenbank | techspread sagt:
    11. August 2010 um 00:40 Uhr

    […] [via Sebastian] […]

    Antworten

Schreibe einen Kommentar Antwort abbrechen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

eMail-Benachrichtigung bei weiteren Kommentaren.
Auch möglich: Abo ohne Kommentar.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre, wie deine Kommentardaten verarbeitet werden.

Footer

Kategorien

  • Allgemein
  • Coldfusion
  • Development
  • Fun
  • General
  • Home automation
  • Homematic
  • Linux
  • Mobile
  • PHP
  • Privat
  • Systemadministration
  • Virtualization
  • Windows
  • Zaurus

© 2026 · Sebastian Mogilowski's Blog · Powered by Imagely