Add the following content to the apache configuration file or the virtual host configuration file (that is, the configuration of LogFormat and CustomLog:
LogFormat "insert into apachelog (ID, dateTime, IP, URL, code, referer, userAgent, size, request) VALUES (NULL, \ "% {% Y-% m-% d % H: % M: % S} t \", \ "% a \", \ "% U \", \ "%> s \", \ "% {Referer} I \", \ "% {User-Agent} I \", % B, % T); "sqlcomm
CustomLog "|/usr/bin/mysql-user = root-password ="-database = apachealog "sqlcomm
Create a database and a data table in the Mysql database:
Mysql> create database apachealog;
Mysql> show create table apachealog;
Create table 'apacheog '(
'Id' int (11) not null AUTO_INCREMENT,
'Datetime' dateTime not null,
'IP' varchar (15) not null,
'URL' varchar (256) not null,
'Code' varchar (3) not null,
'Referer' varchar (256) not null,
'Useragent' varchar (256) not null,
'Size' int (11) not null,
'Request' float not null,
Primary key ('id '),
KEY 'datetime' ('datetime ')
) ENGINE = MyISAM AUTO_INCREMENT = 40 default charset = latin1;
Implementation ideas:
First, use the LogFormat settings to convert the log to a format close to the SQL, and then call pipe through CustomLog to write data to mysql.
Note: Apache log format can refer to the official documentation: http://httpd.apache.org/docs/2.2/mod/mod_log_config.html # formats, you can also use SetEnvIf with regular expressions to filter out such as images, CSS, JS and other relatively unimportant information.