1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| cat <<eof |tee /usr/local/elastic/logstash-8.7.0/config/logstash.conf input { beats { port => 5044 } file { path => "/var/log/nginx/access.log" type => "access.log" start_position => "beginning" codec => json } }
filter { grok { match => { "message" => '%{IP:client} - - \[%{HTTPDATE:time}\] "%{WORD:method} %{URIPATHPARAM:request} HTTP/%{NUMBER:http_version}" %{NUMBER:status} %{NUMBER:bytes} "-" "%{DATA:user-agent}" "-"' } } date { match => [ "logdate", "MMM dd yyyy HH:mm:ss Z" ] } mutate { remove_field => [ "timestamp" ] } }
output { elasticsearch { hosts => ["http://192.168.137.13:9200"] #index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}" index => "nginx-%{+YYYY.MM.dd}" user => "elastic" password => "nickqiu" } } eof
|