Elastic Stack从入门到实践(一)--Elastic Stack入门(2)--Beats、Filebea入门

Beats、Filebea入门

Beats简介

Lightweight Data Shipper (轻量级数据传送者)
Filebeat 日志文件
Metricbeat 度量数据(可以收集cpu数据、内存、磁盘、常用软件Nginx、MySQL等的度量指标)
Packetbeat 网络数据(抓包、分析服务器的网络数据传输等)
Winlogbeat Windows 数据
Heartbeat 健康检查
在这里插入图片描述

Filebeat简介

处理流程
输入Input
处理Filter
输出Output
在这里插入图片描述
Prospector 探矿者,针对配置的日志文件探测文件有没有变化;一个Filebeat可以有多个Prospector
Harvester 收割者、采集器,对有变化的日志文件收集新的日志,从每个文件中将具体的数据取出来,然后发送到Output对象,每个日志文件启动一个Harvester

Filebeat Input 配置简介

yaml语法
在这里插入图片描述
input_type 有两个类型,分别是log、stdin(标准输入,可以从标准输入把日志文件传给Filebeat进行处理)

Filebeat Output 配置简介

在这里插入图片描述
Filebeat支持的Output对象:
Console 标准输出
Elasticsearche
Logstash
kafka
Redis
File

Console举例
在这里插入图片描述
pretty: true 为把Filebeat的输出做json的格式化,然后输出

Filebeat Filter 配置简介

Filebeat本身是可以对读入的内容的进行一定的处理,当然处理能力相对较弱

Input时处理
Include_lines 达到某些条件的时候读入这行
exclude_lines 达到某些条件的时候不读入这行
exclude_files 达到某些条件的时候不读去这个文件

Ouput前处理 – Processor
drop_event 满足条件的一条数据直接扔掉
drop_fields 满足条件的字段直接扔掉
decode_json_fields 可以对这条数据里面的符合json格式的字段做JSON的解析
Include_fields 加入一些字段,或者只想取数据里面的某些字段

举例
在这里插入图片描述
在这里插入图片描述

Filebeat + Elasticsearch Ingest Node

Filebeat 缺乏数据转换的能力,所以5.x的时候Elasticsearch增加了一个新的node类型 – Ingest Node 。
Elasticsearch Ingest Node:
新增的node类型
在数据写入es前对数据进行处理转换
使用的api是 pipeline api

Filebeat Module简介

对于社区常用需求进行配置封装增加易用性,如nginx、apache、mysql等的日志。

封装内容
filebeat.yml 配置
ingest node pipeline 配置
Kibana dashboard

这些Module为最佳实践参考,可以进行详细的研究分析

Filebeat 收集 nginx log 演示

通过stdin收集日志,通过console输出结果。
手先下载Filebeat并解压
https://www.elastic.co/cn/downloads/past-releases/filebeat-6-8-23
在这里插入图片描述
在这里插入图片描述
新建文件nginx.yml

filebeat.prospectors:
- input_type: stdin
output.console:
    pretty: true

打开cmd窗口,切换目录到D:\elastic\filebeat-6.8.23-windows-x86_64然后执行命令filebeat -e -c nginx.yml 回车,将nginx.log的两条日志内容,粘贴到启动的窗口回车。
复制内容为

93.180.71.3 - - [17/May/2015:08:05:32 +0000] "GET /downloads/product_1 HTTP/1.1" 304 0 "-" "Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.21)"
93.180.71.3 - - [17/May/2015:08:05:23 +0000] "GET /downloads/product_1 HTTP/1.1" 304 0 "-" "Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.21)"

执行结果为
在这里插入图片描述

Packetbeat 简介

实时抓取网络包,将网络包按照更高层的比如应用层协议把数据展开,如ICMP(v4 and v6)、DNS、HTTP、MySQL、Redis等协议。
Packetbeat相当于更轻量级的Wireshark。

请求elasticsearch http请求配置
在这里插入图片描述
packetbeat运行命令
sudo ./packetbeat -e -c es.yml -strict.perms=false

Packetbeat 演示

首先下载Packetbeat 并解压
https://www.elastic.co/cn/downloads/past-releases/packetbeat-6-8-23
在这里插入图片描述
在这里插入图片描述
新建文件es.yml

packetbeat.interfaces.device: 1
packetbeat.protocols:
- type: http
  # Configure the ports where to listen for HTTP traffic. You can disable
  # the HTTP protocol by commenting out the list of ports.
  ports: [80, 8080, 8000, 5000, 8002]
  send_request: true   
  include_body_for: ["application/json", "x-www-form-urlencoded"]
output.console:
    pretty: true

然后打开D:\elastic\elasticsearch-6.8.23\bin双击elasticsearch.bat先把elasticsearch跑起来
在这里插入图片描述
管理员打开cmd命令窗口,切换目录到D:\elastic\packetbeat-6.8.23-windows-x86_64
然后执行命令packetbeat.exe -e -c es.yml -strict.perms=false会有提示wpcap.dll丢失。
解决办法:下载win10pcap.msi,并安装,则可以解决这个问题。网址:http://www.win10pcap.org/download/

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值