首先看一下没有过滤前的默认日志
修改Logstash过滤出Nginx日志
filter {
grok {
match => { "message" => "%{IP:clientip} - (%{USERNAME:user}|-) \[%{HTTPDATE:timestamp}\] \"%{WORD:request_verb} %{NOTSPACE:request} HTTP/%{NUMBER:httpversion}\" %{NUMBER:status:int} %{NUMBER:body_sent:int} \"-\" \"%{GREEDYDATA:agent}\" \"-\"" } # 过滤出自己需要的效果
remove_field => "message" # 删除出不需要的字段
}
}
# %{IPV4:remote_addr} - (%{USERNAME:remote_user}|-) \[%{HTTPDATE:time_local}\] \"%{WORD:request_method} %{URIPATHPARAM:request_uri} HTTP/%{NUMBER:http_protocol}\" %{NUMBER:http_status} %{NUMBER:body_bytes_sent} \"%{GREEDYDATA:http_referer}\" \"%{GREEDYDATA:http_user_agent}\" \"(%{IPV4:http_x_forwarded_for}|-)\"
检测一下Logstash配置是否正常
[root@k8s-node02 /usr/local/logstash-6.5.4]# bin/logstash -f etc/conf.d/ -t # 这里出现OK就说明没有问题
重启Logstash
[root@k8s-node02 /usr/local/logstash-6.5.4]# nohup bin/logstash -f etc/conf.d/ --config.reload.automatic &
访问Nginx日志,生产新的日志。
curl http://127.0.0.1