windows下 FileBeat +redis+ELK的搭建测试

1.前言

很多时候,我们需要将多台服务器上的日志文件(系统日志、站点日志、业务日志等)汇总到一台日志服务器上,同时需要对日志进行汇总分析、或从大量的日志数据中找到自己需要的日志信息,如何快速汇总和检索日志数据是需要解决的问题。本文主要介绍通过filebeat收集日志,再使用redis作为消息队列进行传输,最终存储到ES中,使用kibana进行统计和查询。本文主要记录配置信息,方便后期查看,原理这些不会介绍,因为本人也是初步了解这些内容,想先在windows下体验一下功能效果所以进行了本次搭建测试.

Elasticsearch是个开源分布式搜索引擎,提供搜集、分析、存储数据三大功能。它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。主要负责将日志索引并存储起来,方便业务方检索查询。

Logstash 主要是用来日志的搜集、分析、过滤日志的工具,支持大量的数据获取方式。一般工作方式为c/s架构,client端安装在需要收集日志的主机上,server端负责将收到的各节点日志进行过滤、修改等操作在一并发往elasticsearch上去。是一个日志收集、过滤、转发的中间件,主要负责将各条业务线的各类日志统一收集、过滤后,转发给 Elasticsearch 进行下一步处理。

Kibana 也是一个开源和免费的工具,Kibana可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助汇总、分析和搜索重要数据日志。

Filebeat是用于转发和集中日志数据的轻量级传送程序。作为服务器上的代理安装,Filebeat监视您指定的日志文件或位置,收集日志事件,并将它们转发到Elasticsearch或Logstash进行索引。logstash占资源很大,filebeat更加轻量

Redis用来缓存Filebeat存入的数据,直接将filebeat搜集的数据传输给logstash,logstash接收数据会出现延迟甚至是宕机,从而导致数据丢失,通过消息队列作为数据缓冲层可以有效减轻logstash的压力,提高整个架构的稳定性.

*.log=>Filebeat=>Redis=>Logstash=>Elasticsearch=>Kibana
本次搭建软件版本全部为7.6.1

2.Filebeat

解压根目录下修改配置文件
配置文件名:filebeat.yml

#=========================== Filebeat inputs =============================
filebeat.inputs:

- type: log
  # Change to true to enable this input configuration.
  enabled: true
  # 每 5 秒检测一次文件是否有新的一行内容需要读取
  backoff: "5s"
  # 是否从文件末尾开始读取
  tail_files: false
  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - E:/workspace/admin/security-aouth/dxf-management/log_admin/web_debug.log
    #- c:\programdata\elasticsearch\logs\*
  fields:
    filetype: web_debug
    
- type: log
  # Change to true to enable this input configuration.
  enabled: true
  # 每 5 秒检测一次文件是否有新的一行内容需要读取
  backoff: "5s"
  # 是否从文件末尾开始读取
  tail_files: false
  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - E:/workspace/admin/security-aouth/dxf-management/log_admin/web_error.log
    #- c:\programdata\elasticsearch\logs\*
  fields:
    filetype: web_error
    
- type: log
  # Change to true to enable this input configuration.
  enabled: true
  # 每 5 秒检测一次文件是否有新的一行内容需要读取
  backoff: "5s"
  # 是否从文件末尾开始读取
  tail_files: false
  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - E:/workspace/admin/security-aouth/dxf-management/log_admin/web_info.log
    #- c:\programdata\elasticsearch\logs\*
  fields:
    filetype: web_info

- type: log
  # Change to true to enable this input configuration.
  enabled: true
  # 每 5 秒检测一次文件是否有新的一行内容需要读取
  backoff: "5s"
  # 是否从文件末尾开始读取
  tail_files: false
  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - E:/workspace/admin/security-aouth/dxf-management/log_admin/web_warn.log
    #- c:\programdata\elasticsearch\logs\*
  fields:
    filetype: web_warn
  


# ============================== Filebeat modules ==============================
filebeat.config.modules:
  path: ${path.config}/modules.d/*.yml
  reload.enabled: false

setup.template.settings:
  index.number_of_shards: 1

setup.kibana:

# ============================== Filebeat 输出配置====================
output.redis:
  enabled: true
  # redis地址
  hosts: ["127.0.0.1:6379"]
  # redis密码,没有密码则不添加该配置项
  password: 123456
  # 数据存储到redis的key值
  key: apilog
  # 数据存储到redis的第几个库
  db: 1
  # 数据存储类型
  datatype: list

# ================================= Processors =================================
processors:
  - add_host_metadata:
      when.not.contains.tags: forwarded
  - add_cloud_metadata: ~
  - add_docker_metadata: ~
  - add_kubernetes_metadata: ~

根目录下cmd命令窗口 启动命令

.\filebeat -e -c filebeat.yml

3.启动redis

(不出意外的话会在redis中存入日志数据,前提是你在配置filebeat的paths中有日志数据)

4.elasticsearch

解压后根目录下打开config下的elasticsearch.yml文件,修改配置

# 监听地址和端口
network.host: 127.0.0.1
http.port: 9200

启动ElasticSearch
两种方法:
1、进入\elasticsearch-7.6.1\bin 直接双击elasticsearch.ba
2、打开Windows PowerShell 进入\elasticsearch-7.6.1\bin 执行.\elasticsearch.bat或者.\elasticsearch

访问我使用的是elasticsearch-head谷歌插件

5.kibana

解压进入根目录
进入config下的kibana.yml 修改配置为

# 服务地址,根据实际情况自行调整
server.host: "localhost"
# 服务端口
server.port: 5601
# ES的地址
elasticsearch.hosts: ["http://localhost:9200"]
# kibana的索引
kibana.index: ".kibana"
# 界面语言,默认是en
i18n.locale: "zh-CN"

启动kibana


\kibana-7.6.1-windows-x86_64\bin   cmd 命令窗口执行(或直接双击bat文件)

.\kibana.bat

6.logstash

配置文件名:logstash.conf(在cofig目录下新建文件)

input {
    redis {
        host => "127.0.0.1"
        port => 6379
        key => "apilog" #这里的key值和filebeat配置文件中output.redis的key值保持一致
        data_type => "list"
        db =>1
    }

}
filter {
 mutate{
        remove_field => ["host"]
    }
      date {
        match => ["timestamp", "dd/MMM/yyyy:HH:mm:ss Z"] #匹配timestamp字段
        target => "@timestamp"  #将匹配到的数据写到@timestamp字段中
      }
}
output {
    elasticsearch {
        hosts => ["127.0.0.1:9200"]
        index => "redis-%{+YYYY.MM.dd}"
    }
    stdout {
        codec => json_lines
    }
}

启动
bin目录下cmd 命令窗口

.\logstash.bat -f ../config/logstash.conf

7.结果

如按照我的启动顺序你可以发现最初存入redis的记录已经消失而Elasticsearch中插入数据成功.
按照下图顺序创建索引
在这里插入图片描述
索引模式 redis-*

最后来到仪表盘筛选如图
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值