nginx 配置:
log_format main 'remote_user=$remote_user&ip=$remote_addr&real_ip=$http_x_forwarded_for&log_time=$time_local&request_time=$request_time&host=$http_host&$args&status=$status&body_bytes_sent=$body_bytes_sent&referer=$http_referer&user_agent=$http_user_agent&forwarded_for=$http_x_forwarded_for'; access_log logs/access.log main;
location = /s.gif { empty_gif; }
logstash 配置:
input { file{ path => "E:/test/nginx-1.18.0/logs/access.log" start_position => "beginning" stat_interval => "2" } } filter{ urldecode{ field => message } kv{ field_split => "&" } } output { jdbc { # 配置数据库信息 connection_string => "jdbc:mysql://localhost:3306/logstash_test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai" driver_class => "com.mysql.cj.jdbc.Driver" username => "root" password => "123456" driver_jar_path => "E:/test/logstash-7.14.2/mysql/mysql-connector-java-8.0.25.jar" statement => ["insert into log_coll(timestamp,args,remote_addr,name,age) VALUES(?,?,?,?,?)", "timestamp","user_agent","remote_addr","name","age"] } stdout { codec => rubydebug } }