当前位置: 首页 > news >正文

ELK框架Logstash配合Filebeats和kafka使用

ELK框架Logstash配合Filebeats和kafka使用

本文目录

    • ELK框架Logstash配合Filebeats和kafka使用
      • 配置文件结构
      • input为标准输入,output为标准输出
      • input为log文件
        • output为标准输出
        • output为es
      • input为tcp
        • springboot配置
        • logstash配置
      • input为filebeats
        • filebeats配置
        • logstash配置
      • input为kafka
        • filebeats设置
        • logstash配置

配置文件结构

配置文件为:logstash.yml

需要自己新建conf文件,设置inputfilteroutput,文件结构如下,自带的logstash-sample.conf内容如下

input { }
filter {}
output {}

启动命令

bin/logstash -f config/logstash.conf

https://www.elastic.co/guide/en/logstash/current/input-plugins.html

input为标准输入,output为标准输出

input { stdin { } 
}
output {elasticsearch { hosts => ["localhost:9200"] }stdout { }
}

input为log文件

output为标准输出

input {# 从文件读取日志信息file {path => "/xxx/demolog/logs/myapp-info.log"type => "ghn"start_position => "beginning"}}output {stdout { codec => rubydebug }
}

output为es

input {# 从文件读取日志信息file {path => "/xxx/demolog/log/demolog-*.log"type => "ghn"start_position => "beginning"}}output {# 输出到 elasticsearchelasticsearch {hosts => ["localhost:9200"] user => "elastic"password => "xxxxxx"ssl => "true"cacert => "/xxx/elk/logstash-8.9.1/config/certs/http_ca.crt"index => "ghn-%{+YYYY.MM.dd}"}stdout {  }
}

input为tcp

配合springboot/springcloud使用

springboot配置

官方github:https://github.com/logfellow/logstash-logback-encoder
在pom.xml添加依赖

        <dependency><groupId>net.logstash.logback</groupId><artifactId>logstash-logback-encoder</artifactId><version>7.4</version></dependency>

在logback-spring.xml添加配置

    <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender"><destination>127.0.0.1:4560</destination><!-- encoder is required --><encoder class="net.logstash.logback.encoder.LogstashEncoder" /></appender><root level="info"><appender-ref ref="CONSOLE"/><appender-ref ref="stash" /></root>

logstash配置

input {# 从文件读取日志信息tcp {host => "0.0.0.0"mode => "server"port => 4560codec => json_lines}}output {# 输出到 elasticsearchelasticsearch {hosts => ["localhost:9200"] user => "elastic"password => "xxxxxx"ssl => "true"cacert => "xxx/logstash-8.9.1/config/certs/http_ca.crt"index => "ghn-%{+YYYY.MM.dd}"}stdout { }# stdout { codec => rubydebug }
}
  • logstash终端查看

  • kibana查看

input为filebeats

filebeats配置

  • 配置文件位置:filebeat-8.9.1-darwin-aarch64/filebeat.yml,修改如下部分,指定log位置为springboot的目录
filebeat.inputs:
- type: filestreamenabled: truepaths:- /xxx/xxx/*.log
  • 启动
./filebeat -e -c filebeat.yml -d "publish"

与logstash建立了连接,启动成功

logstash配置

input {beats {port => 5044}
}output {elasticsearch {hosts => ["localhost:9200"] user => "elastic"password => "xxxxxx"ssl => "true"cacert => "/xxxx/logstash-8.9.1/config/certs/http_ca.crt"index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"}
}
  • 启动logstash
bin/logstash -f config/logstash-filebeat.conf
  • 获取从filebeats发来的日志

kibana

  • kibana中数据视图已经能够看到

  • 查看详情

input为kafka

官方文档:https://www.elastic.co/guide/en/logstash/current/use-filebeat-modules-kafka.html

filebeats设置

output.kafka:hosts: ["localhost:9092"]topic: "filebeat"codec.json:pretty: false
./filebeat -e -c filebeat.yml -d "publish"

logstash配置

input {kafka {bootstrap_servers => ["localhost:9092"]topics => ["filebeat"]codec => json}}output {# 输出到 elasticsearchelasticsearch {hosts => ["localhost:9200"] user => "elastic"password => "xxxxxx"ssl => "true"cacert => "/xxx/elk/logstash-8.9.1/config/certs/http_ca.crt"index => "ghn-%{+YYYY.MM.dd}"}stdout { }# stdout { codec => rubydebug }
}
  • kafka启动

  • logstash查看

  • kafka关闭

https://www.elastic.co/guide/en/logstash/current/plugins-inputs-kafka.html

http://www.lryc.cn/news/159319.html

相关文章:

  • 后端面试话术集锦第 十二 篇:java基础部分面试话术
  • 【广州华锐互动】电厂三维数字孪生大屏的功能和优势
  • es6解构用法
  • a_bogus 音 算法还原大赏
  • 【计算机网络】UDP协议详解
  • 2023-9-8 满足条件的01序列
  • 获取街道、乡镇级的地图geoJson数据,使用echarts绘制地图
  • DBMS_RESOURCE_MANAGER
  • 通俗讲解傅里叶变换
  • 数据结构——带头双向循环链表
  • MySQL大数据量高速迁移,500GB只需1个小时
  • kafka复习:(25)kafka stream
  • 接口自动化测试总结
  • 【Redis】Lua脚本在Redis中的基本使用及其原子性保证原理
  • 汇编--int指令
  • 生成式AI的JavScript技术栈
  • 从零开始学习软件测试-第39天笔记
  • 【多思路附源码】2023高教社杯 国赛数学建模C题思路 - 蔬菜类商品的自动定价与补货决策
  • Vue2+Vue3基础入门到实战项目(六)——课程学习笔记
  • QT—基于http协议的网络文件下载
  • SpringBoot-配置优先级
  • 科普初步了解大模型
  • Nginx 和 网关的关系是什么
  • 解决springboot项目中的groupId、package或路径的混淆问题
  • Vmware 网络恢复断网和连接
  • 学生来看!如何白嫖内网穿透?点进来!
  • C++中的stack和queue
  • Ubuntu-22.04通过RDP协议连接远程桌面
  • 20230908java面经整理
  • uniapp 开发App 网络异常如何处理