filebeat读取本地文件到ELK简单配置

11次阅读

共计 1796 个字符,预计需要花费 5 分钟才能阅读完成。

filebeat 读取本地文件到 ELK 简单配置
前言阅读本文前请确保已经部署 ELK,本文是基于 window server 如未部署请参考 window 环境下搭建简单 ELK 日志收集相比较之前用 logback + redis + elk 收集日志的方式,filebeat 的方式可以减少对系统的耦合性,不会对运行的系统造成干扰。

依赖组件 filebeat-5.6.14-windows-x86_64 官网下载地址 最新版本 6.6filebeat 官方下载 5.6 到 6.6 跨度太大,如果 elk 使用 6.X 的版本需要注意下参数配置,有些参数在 6.X 的版本已经取消了
配置 filebeat
下载下来之后解压,修改配置文件 filebeat.yml
配置文件里面其实已经有详细的说明,5.X 跟 6.X 的版本不太一样,不过测试的时候发现 5.X 的配置在 6.X 的 filebeat 也能用,只是启动会提示你该参数已经过时,建议更换。
首先需要定义输入源和输出源输入源那边定义文件夹地址,支持读取单个文件或者是多个文件,输出可以输出到 redis、logstash 和 es 可以参考官网的配置:filebeat 配置
filebeat.prospectors:

# Each – is a prospector. Most options can be set at the prospector level, so
# you can use different prospectors for various configurations.
# Below are the prospector specific configurations.

– input_type: log

# Paths that should be crawled and fetched. Glob based paths.
paths:
– c:\programdata\elasticsearch\logs\*.log
# Optional additional fields. These field can be freely picked
# to add additional information to the crawled log files for filtering
# 这边这个自已定参数名,例如这边定义了个 type 名字叫 service-debug
# 在 logstash 那边可以用这个 type 参数作为 es 的索引名称
fields:
type: service-debug
# level: debug
# review: 1

##————————– es output ————————————
#output.elasticsearch:
# Array of hosts to connect to.
#hosts: [“localhost:9200”]

# Optional protocol and basic auth credentials.
#protocol: “https”
#username: “elastic”
#password: “changeme”
##————————– logstash output —————————–
output.logstash:
# The Logstash hosts
hosts: [“127.0.0.1:5044”]

如果需要通过 redis 输出,只需要把输出配置改成用 redis
output.redis:
hosts: [“127.0.0.1”]
port: 6379
#password: “test”
db: 2
timeout: 5
key: “service-debug”
修改 logstash 配置
如果是 filebeat 直接输出 logstash,配置如下,如果是通过 redis,请参考上面文章
input{
beats {
port => 5044

}
}
filter {
}
output {
if [fields][type]==”service-debug” {
elasticsearch {
hosts => [“127.0.0.1:9200”]
index => “service-debug-%{+YYYY.MM.dd}”
}
}

stdout{}
}
配置完成后启动 filebeat,启动参数 filebeat.exe -e -c filebeat.yml 启动完成后,当日志文件有发生变化时候,filebeat 会把相关日志输出到 logstash
END

正文完
 0