简体   繁体   English

将 Apache 访问日志存储到 MySQL

[英]Store Apache access logs to MySQL

I referred this link to log access information into mysql database.我引用此链接将访问信息记录到 mysql 数据库中。

Below is my database structure for下面是我的数据库结构

apachelogs.web_access_log apachelogs.web_access_log

+------------------+----------------------+------+-----+---------+-------+
| Field            | Type                 | Null | Key | Default | Extra |
+------------------+----------------------+------+-----+---------+-------+
| id               | char(19)             | YES  |     | NULL    |       |
| agent            | varchar(255)         | YES  |     | NULL    |       |
| bytes_sent       | int(10) unsigned     | YES  |     | NULL    |       |
| child_pid        | smallint(5) unsigned | YES  |     | NULL    |       |
| cookie           | varchar(255)         | YES  |     | NULL    |       |
| machine_id       | varchar(25)          | YES  |     | NULL    |       |
| request_file     | varchar(255)         | YES  |     | NULL    |       |
| referer          | varchar(255)         | YES  |     | NULL    |       |
| remote_host      | varchar(50)          | YES  |     | NULL    |       |
| remote_logname   | varchar(50)          | YES  |     | NULL    |       |
| remote_user      | varchar(50)          | YES  |     | NULL    |       |
| request_duration | smallint(5) unsigned | YES  |     | NULL    |       |
| request_line     | varchar(255)         | YES  |     | NULL    |       |
| request_method   | varchar(10)          | YES  |     | NULL    |       |
| request_protocol | varchar(10)          | YES  |     | NULL    |       |
| request_time     | char(28)             | YES  |     | NULL    |       |
| request_uri      | varchar(255)         | YES  |     | NULL    |       |
| request_args     | varchar(255)         | YES  |     | NULL    |       |
| server_port      | smallint(5) unsigned | YES  |     | NULL    |       |
| ssl_cipher       | varchar(25)          | YES  |     | NULL    |       |
| ssl_keysize      | smallint(5) unsigned | YES  |     | NULL    |       |
| ssl_maxkeysize   | smallint(5) unsigned | YES  |     | NULL    |       |
| status           | smallint(5) unsigned | YES  |     | NULL    |       |
| time_stamp       | int(10) unsigned     | YES  |     | NULL    |       |
| virtual_host     | varchar(255)         | YES  |     | NULL    |       |
+------------------+----------------------+------+-----+---------+-------+

I see most of the column values are NULL as below when the request is received from browser:当从浏览器收到请求时,我看到大多数列值都是 NULL,如下所示:

+------+-------+------------+-----------+--------+------------+--------------+---------+-------------+----------------+-------------+------------------+--------------+----------------+------------------+--------------+-------------+--------------+-------------+------------+-------------+----------------+--------+------------+--------------+
| id   | agent | bytes_sent | child_pid | cookie | machine_id | request_file | referer | remote_host | remote_logname | remote_user | request_duration | request_line | request_method | request_protocol | request_time | request_uri | request_args | server_port | ssl_cipher | ssl_keysize | ssl_maxkeysize | status | time_stamp | virtual_host |
+------+-------+------------+-----------+--------+------------+--------------+---------+-------------+----------------+-------------+------------------+--------------+----------------+------------------+--------------+-------------+--------------+-------------+------------+-------------+----------------+--------+------------+--------------+
| -    | -     |          0 |      NULL | NULL   | NULL       | NULL         | -       | ::1         | NULL           | -           |                0 | NULL         | NULL           | HTTP/1.0         | NULL         | NULL        | NULL         |        NULL | NULL       |        NULL |           NULL |    408 | 1531980584 | 192.168.4.18 |
+------+-------+------------+-----------+--------+------------+--------------+---------+-------------+----------------+-------------+------------------+--------------+----------------+------------------+--------------+-------------+--------------+-------------+------------+-------------+----------------+--------+------------+--------------+
1 row in set (0.02 sec)

Most of the request parameters are missing.大多数请求参数丢失。 Let me know what I have to modify in order to log all the attributes with their corresponding values.让我知道我必须修改什么才能用相应的值记录所有属性。

Thanks谢谢

Apache2 is unable to write the logs to MySQL database properly due to the mismatch of 'id' column width.由于 'id' 列宽不匹配,Apache2 无法将日志正确写入 MySQL 数据库。 The default width created in the web_access_log table is 19 which should be increased to 25. If 25 did not help try again with bigger width.web_access_log表中创建的默认宽度是 19,应该增加到 25。如果 25 没有帮助,请再试一次更大的宽度。

After doing this, the MySQL log automatically started updating without any further issues.这样做后,MySQL 日志自动开始更新,没有任何进一步的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM