首先,什么是Beats?
Beats平台结合了多种单一用途数据采集器,它们从成百上千或者成千上万台机器和系统向logstash和elasticsearch发送数据
Beats平台下所属的FileBeats
什么是FileBeats?
其是一种轻量型的日志采集器,用于转发和汇总日志文件
FileBeats的安装过程
第一步,下载安装包,下载地址为::https://www.elastic.co/downloads/beats
第二步,解压FileBeats到指定目录
第三步,新建一个启动配置文件XXX.yml,配置内容如下
filebeat.inputs: #定义FileBeats的输入
- type: log #定义类型,目前支持俩种,一个是log,另一个是stdin(控制台)
enabled: true
paths:
- /ppp/base/haoke/beats/logs/*.log #读取log文件目录与路径
tags: ["web","im"] #自定义标签
fields: #自定义属性
from: haoke-im
fields_under_root: true #是否加入根节点
setup.template.settings:
index.number_of_shards: 3 #设置索引分片的个数
output.console: #标准输出
pretty: true
enable: true
第四步,执行启动命令
./filebeat -e -c haoke-es.yml
第五步,测试往/ppp/base/haoke/beats/logs/a.log文件中写入数据
结果,会将执行结果输出到控制台,显示结果如下:
{
"@timestamp": "2019-08-22T07:01:17.557Z",
"@metadata": {
"beat": "filebeat",
"type": "doc",
"version": "6.5.4"
},
"beat": {
"name": "ppp_m_db",
"hostname": "ppp_m_db",
"version": "6.5.4"
},
"host": {
"name": "ppp_m_db"
},
"tags": [
"web",
"im"
],
"from": "haoke-im",
"message": "hello",
"prospector": {
"type": "log"
},
"input": {
"type": "log"
},
"source": "/ppp/base/haoke/beats/logs/a.log",
"offset": 0
}
使用FileBeats读取log文件存入Elasticsearch中
新建配置文件,内容如下:
filebeat.inputs:
- type: log
enabled: true
paths:
- /ppp/base/haoke/beats/logs/*.log
tags: ["web","im"]
fields:
from: haoke-im
fields_under_root: false
setup.template.settings:
index.number_of_shards: 3
output.elasticsearch: #指定索引分区数
hosts: ["10.212.130.5:9200","10.212.130.5:9201","10.212.130.5:9203"]
重启FileBeats
./filebeat -e -c haoke-es.yml
Filebeat工作原理
Filebeat由两个主要组件组成:prospector(探测器) 和 harvester(收割机)。
- harverster
- 负责读取单个文件内容
- 如果文件在被读取时删除或者重命名,FileBeat会继续读取
- prospector
- prospector负责管理harverster,并找到所有要读取的文件来源
- 如果输入路径为log的话,则prospector会遍历输入配置的paths中的所有文件,并威每一个文件开启一个harverster
- FileBeat的prospector目前支持俩种类型:stdin与log
FIleBeat如何保存文件状态
- FileBeat会保存每个文件的状态并周期性刷新写入registry文件中
- 该状态会记录每个harverster的最后偏移位置,保证所有日志行发送到logstach与Elasticsearch中
- 如果输出(例如Elasticsearch或Logstash)无法访问,Filebeat会跟踪最后发送的行,并在输出再次可时继续读取文件。
- 文件状态记录在/data/registry文件中
查看FileBeats支持的Modules
./filebeat modules list
//结果如下
Enabled:
Disabled:
apache2
auditd
elasticsearch
haproxy
icinga
iis
kafka
kibana
logstash
mongodb
mysql
nginx
osquery
postgresql
redis
suricata
system
traefik
启用/禁用redis-modules
./filebeat modules enable redis #启动
./filebeat modules disable redis #禁用
修改redis-module的配置
cd modules.d/
vim redis.yml
//修改内容如下:
- module: redis
# Main logs
log:
enabled: true
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
var.paths: ["/ppp/base/docker/redis-data/node01/*.log"]
# Slow logs, retrieved via the Redis API (SLOWLOG)
slowlog:
enabled: true
# The Redis hosts to connect to.
#var.hosts: ["localhost:6379"]
# Optional, the password to use when connecting to Redis.
#var.password:
编写FileBeat的启动配置文件haoke-redis.yml,配置内容如下
filebeat.inputs:
- type: log
enabled: true
paths:
- /ppp/base/haoke/beats/logs/*.log
setup.template.settings:
index.number_of_shards: 3
output.elasticsearch: #指定索引分区数
hosts: ["10.212.130.5:9200","10.212.130.5:9201","10.212.130.5:9203"]
filebeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false
使用命令启动FileBeats,采集redis的数据并存入Elasticsearch中
./filebeat -e -c haoke-redis.yml --modules redis
Beats是一个轻量级的数据采集平台,包含多种单一用途的采集器,如FileBeats,用于从多台机器向Elasticsearch或Logstash转发日志。FileBeats的安装包括下载、解压、配置和启动,通过配置文件读取并发送log文件到Elasticsearch。其工作原理包括Prospector和Harvester,Prospector管理Harvester,发现和读取文件。FileBeats保存文件状态在registry文件中,确保日志不丢失。此外,还可以配置和使用不同的模块,如redis-module,来采集特定类型的数据。
5258

被折叠的 条评论
为什么被折叠?



