ELK 組成::java
Logstash 原理分析及環境搭建nginx
./bin/logstash -e 'input { stdin {} } output { stdout {} }'
input { stdin {} } output { stdout {} }
./bin/logstash -f config/logstash.conf
訪問日誌生產平臺的搭建git
NGINXACCESS %{IPORHOST:clientip} %{HTTPDUSER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\]"(?:%{WORD:verb} %{URIPATH:uri}%{URIPARAM:param}(?:HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})" %{NUMBER:response} (?:%{NUMBER:bytes}|-) NGINXACCESSLOG %{NGINXACCESS} %{QS:referrer} %{QS:agent} %{QS:x_forwarded_for}
對logstash.conf 中的內容進行修改:github
input{ file { path => ["D:/nginx-1.14.0/logs/access.log"] type =>"nginx_access" start_position =>"beginning" } } filter{ if [type] =="nginx_access" { grok { patterns_dir =>"D:/logstash-5.5.2/config/patterns/" match =>{ "message" =>"%{NGINXACCESS}" } } date { match => ["timestamp", "dd/MMM/YYYY:HH:mm:ss Z"] } if[param] { ruby { init =>"@kname = ['quote','url_args']" code =>" new_event = LogStash::Event.new (Hash[ @kname.zip(event.get('param').split('?'))]) new_event.remove('@timestamp') event.append(new_event) " } if[url_args] { ruby { init =>"@kanme = ['key','value']" code =>"event.set('nested_args',event.get('url_args').split('&').clllect {|i|Hash[ @kanme.zip(i.split('='))]})" remove_field => ["url_args", "param", "quote"] } } mutate { convert => ["response", "integer"] remove_field =>"timestamp" } } } } output{ stdout{ codec=>rubydebug } }
Logstash 與ElasticSearch 集成web
elasticsearch { hosts => ["http://localhost:9200"] index => "logstash-%{type}-%{+YYYY.MM.dd}" document_type => "%{type}" sniffing => true #user => "tom" #password => "123456" }
利用Kibana 實現網站流量可視化json