1,先下载这4个服务包(zip),虽然我在win10上使用 不过代码同样可以在linux跑
https://www.elastic.co/cn/downloads
2.解压4个压缩包
3.1 es和kibana的安装请看 虽然是6版本
https://blog.youkuaiyun.com/crazyo2jam/article/details/104168077
3.2 配置 Filebeat
由于我下载的是exe版本但是linux的tar也是同样的方法
编辑filebeat.yml 主要做2部分 输入和logstash的输出
在INPUT处编辑
#=========================== Filebeat inputs =============================
filebeat.inputs:
- type: log
enabled: true
paths:
- d:\project\demo\logs\log*.log
encoding: GB2312
multiline.pattern: '^[0-2][0-9]:[0-5][0-9]:[0-5][0-9]'
#true 或 false;默认是false,匹配pattern的行合并到上一行;true,不匹配pattern的行合并到上一行
multiline.negate: true
#after 或 before,合并到上一行的末尾或开头
multiline.match: after
注释掉其他输出部分(es,kibana)
配置 logstash
index指定按年月日生成索引
#----------------------------- Logstash output --------------------------------
output.logstash:
# The Logstash hosts
hosts: ["localhost:5044"]
# index: "logstash-%{+yyyy.MM.dd}"
enabled: TRUE
项目实际生成log 对应d:\project\demo\logs\log*.log
启动
.\filebeat.exe -e -c .\filebeat.yml
3.2配置logstash
在bin目录下创建log.conf文件
input {
beats{
port => "5044"
}
}
filter {
match => { "message" => "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}"}
#因为我们取出了字段,所以不需要原来这个message字段,这个字段里边包含之前beat 输入的所有字段。
remove_field => ["message"]
}
output {
elasticsearch{
#按月生成索引
index => "log-%{+YYYY.MM.dd}"
hosts => ["localhost:9200"]
}
stdout {
# JSON格式输出
codec => json_lines
}
}
同样方法启动
.\logstash -f .\log.conf --config.reload.automatic
启动项目生成日志文件
打开kibana localhost:5601
我们可以看到已经创建了当天的索引
这样我们可以看到我们生成的日志信息