1.filebeat配置文件:
filebeat.inputs:
- type: log
enabled: true
paths:- /usr/local/nginx/logs/access-json.log
fields:
filetype: logjson #加这个两个文件就是区分的
fields_under_root: true
- /usr/local/nginx/logs/access-json.log
- type: log
enabled: true
paths:- /var/log/messages
fields:
filetype: logsystem
fields_under_root: true
- /var/log/messages
output.logstash:
enabled: true
hosts: ["localhost:5044"] #如果ip不通把localhost换成你的ip
【fields:自定义字段
fields_under_root:为true,则自定义字段将为文档中的顶级字段。】
2.logstash配置
input {
beats {
host => "0.0.0.0"
port => 5044
}
}
filter { //filter主要是用来过滤和重组,使输出达到自己的预期
if [fields][filetype] == "logjson" {
json {
source => "message"
remove_field => ["beat","offset","tags","prospector"]
}
date {
match => ["timestamp", "dd/MMM/yyyy:HH:mm:ss Z"]
target => "@timestamp"
}
}
}
output {
if [fields][filetype]== "logjson" {
elasticsearch {
hosts => ["127.0.0.1:9200"]
index => "json-%{+YYYY.MM.dd}"
}
} else if [fields][filetype] == "logsystem" {
elasticsearch {
hosts => ["127.0.0.1:9200"]
index => "msg-%{+YYYY.MM.dd}"
}
}
}
版权归原作者 勇敢的_小小邱 所有, 如有侵权,请联系我们删除。