1 概论

filebeat 是一个轻量级的日志收集工具 (golang编写的,占用资源小)

官方文档: Getting Started With Filebeat

2 下载安装

artifacts.elastic.co/do

3 使用filebeat 发送日志到 redis 中

1 解压缩

tar -zxvf filebeat-6.1.1-linux-x86_64.tar.gz

2 如下如:

我们需要编辑 filebeat.yml

YAML支持 列表,数字, 字元串, 字典表。

字典 以 key: value 对的形式,在 key后面必须有一个空格。

name: John Doe

age: 34

country: Canada

列表以破折号开始,所有的列表成员必须以`- `在缩进的一行

- Red

- Green- Blue

列表和字典构建结构化的配置

filebeat:

prospectors: - type: log paths: - /var/log/*.log multiline:

pattern: ^[

match: after

列表和字典同样可以使用更简单的形式, 比较类似JSON 使用{} 表示字典,使用[]表示列表

person: {name: "John Doe", age: 34, country: "Canada"}

colors: ["Red", "Green", "Blue"]

3 构建仓库(探矿者)

Filebeat 通过定义 「挖矿者」去定位和处理文件。 在配置filebeat的过程中,你需要指定一个列表的探矿者 在 filebeat.yml中的 filebeat.prospectors节点.

如下是一个简单的配置:

filebeat.prospectors:

- type: log paths: - /var/log/apache/httpd-*.log

- type: log

paths: - /var/log/messages - /var/log/*.log

这个探矿者收集所有的文件 在/var/log/*.log ,意思是 : filebeat 会收集在/var/log

目录中所有以.log结尾的文件。

4 输出到redis / kafka / elasticsearch

Configure the output | Filebeat Reference [6.1] | Elastic

如下配置 :

output.redis:

hosts: ["192.168.96.58"]

port: 6383

datatype: list keys: - key: "test_tp_log" when.contains: source: "tp.log" - key: "test_alive_log" when.contains: source: "alive.log" - key: "test_jvm_log" when.contains: source: "jvm.log" db: 0

我们输出 日志文件输出到 192.168.96.58 , redis的埠是 6383 数据类型是lis

4 启动filebeat

./filebeat -e -c filebeat.yml

推荐阅读:

相关文章