前置環境
OS:CentOS 7.3
Http Service:apache 2.4.6
DB:mariadb 5.5.52
1.建立資料表
使用SQL語句建立資料表
CREATE TABLE access_log
(remote_ip CHAR(15) NOT NULL,
remote_logname VARCHAR(20) NOT NULL,
servername VARCHAR(20) NOT NULL,
remote_user CHAR(10) NOT NULL,
datetime DATETIME NOT NULL,
status SMALLINT NOT NULL,
bytes_sent INT,
content_type VARCHAR(50),
url_requested VARCHAR(250),
referer VARCHAR(250),
user_agent VARCHAR(250),
INDEX (datetime));
(remote_ip CHAR(15) NOT NULL,
remote_logname VARCHAR(20) NOT NULL,
servername VARCHAR(20) NOT NULL,
remote_user CHAR(10) NOT NULL,
datetime DATETIME NOT NULL,
status SMALLINT NOT NULL,
bytes_sent INT,
content_type VARCHAR(50),
url_requested VARCHAR(250),
referer VARCHAR(250),
user_agent VARCHAR(250),
INDEX (datetime));
2.修改apache設定檔
編輯httpd.confvim /etc/httpd/conf/httpd.conf;
在<IfModule log_config_module>區塊內新增一筆LogFormat內容LogFormat "INSERT INTO access_log (remote_ip,remote_logname,servername,remote_user,datetime,status,bytes_sent,content_type,url_requested,referer,user_agent) VALUES ('%h','%l','%v','%u',%{%Y%m%d%H%M%S}t,%>s,'%B', '%{Content-Type}o','%U','%{Referer}i','%{User-Agent}i');" mysql
在<IfModule log_config_module>區塊內新增一筆CustomLog內容CustomLog "| /bin/mysql -h[DB主機] -u[帳號] -p[密碼] [資料庫]" mysql
重新啟動apachesystemctl restart httpd;
紅字標示文字必須可對應
沒有留言:
張貼留言