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 38 39 40 41 42 43 44 45 46 47 48
| yum install logstash -y
mkdir /data/logs/ chown -R logstash:logstash /data/logs
cat /etc/logstash/conf.d/nginx.conf input { kafka { bootstrap_servers => "192.168.162.111:9092" group_id => "test" client_id => "test" auto_offset_reset => "latest" topics => ["get_logs"] codec => json { charset => "UTF-8" } } }
filter { ruby { code => 'event.set("filename",event.get("[log][file][path]").split("/")[-1])' } }
output { stdout { codec => rubydebug } if "nginx" in [log][file][path] and "access" in [log][file][path] { file { path => "/data/logs/live-test-nginx/live-test_%{+YYYYMMdd}_%{filename}" flush_interval => 3 codec => line { format => "%{[tags][0]} %{message}"} } elasticsearch { hosts => ["localhost:9200"] index => "%{[tags][0]}-api-%{+YYYY.MM.dd}" } }
if "nginx" in [log][file][path] and "error" in [log][file][path] { file { path => "/data/logs/live-test-nginx/live-test_%{+YYYYMMdd}_%{filename}" flush_interval => 3 codec => line { format => "%{[tags][0]} %{message}"} } } }
|