码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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文件,设置input,filter和output,文件结构如下,自带的logstash-sample.conf内容如下

    input { 
    
    }
    filter {
    
    }
    output {
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    启动命令

    bin/logstash -f config/logstash.conf
    
    • 1

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

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

    input { 
      stdin { } 
    }
    output {
      elasticsearch { 
        hosts => ["localhost:9200"] 
      }
      stdout { }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    input为log文件

    output为标准输出
    input {
      # 从文件读取日志信息
      file {
        path => "/xxx/demolog/logs/myapp-info.log"
        type => "ghn"
        start_position => "beginning"
      }
    
    }
    
    output {
      stdout { codec => rubydebug }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    output为es
    input {
      # 从文件读取日志信息
      file {
        path => "/xxx/demolog/log/demolog-*.log"
        type => "ghn"
        start_position => "beginning"
      }
    
    }
    
    output {
      # 输出到 elasticsearch
      elasticsearch {
        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 {  }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    input为tcp

    配合springboot/springcloud使用

    springboot配置

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

            
                net.logstash.logback
                logstash-logback-encoder
                7.4
            
    
    • 1
    • 2
    • 3
    • 4
    • 5

    在logback-spring.xml添加配置

        
            127.0.0.1:4560
            
            
        
    
        
            
            
        
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    logstash配置
    input {
      # 从文件读取日志信息
      tcp {
        host => "0.0.0.0"
        mode => "server"
        port => 4560
        codec => json_lines
      }
    
    }
    
    output {
      # 输出到 elasticsearch
      elasticsearch {
        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 }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • logstash终端查看

    • kibana查看

    input为filebeats

    filebeats配置
    • 配置文件位置:filebeat-8.9.1-darwin-aarch64/filebeat.yml,修改如下部分,指定log位置为springboot的目录
    filebeat.inputs:
    - type: filestream
      enabled: true
      paths:
        - /xxx/xxx/*.log
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 启动
    ./filebeat -e -c filebeat.yml -d "publish"
    
    • 1

    与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}"
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 启动logstash
    bin/logstash -f config/logstash-filebeat.conf
    
    • 1
    • 获取从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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    ./filebeat -e -c filebeat.yml -d "publish"
    
    • 1
    logstash配置
    input {
      kafka {
        bootstrap_servers => ["localhost:9092"]
        topics => ["filebeat"]
        codec => json
      }
    
    }
    
    output {
      # 输出到 elasticsearch
      elasticsearch {
        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 }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • kafka启动

    • logstash查看

    • kafka关闭

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

  • 相关阅读:
    javascript中this的指向问题
    Nacos:服务注册及配置中心
    基于深度增强学习的无人机赋能雾无线电接入网络的能效优化
    修改 Zynq 7000 系列 CPU 主频到 800HMz(7045 和 7100)
    awk,gawk基本用法笔记221107
    Zabbix监控系统与部署添加 zabbix 客户端主机
    人工智能第2版学习——知识表示1
    掌握方法,未来可期-来自会员营销系统服务商的经验
    appium+jenkins实例构建
    IDEA打jar包报错 “src/java/META-INF/MANIFEST.MF already exists in VFS”
  • 原文地址:https://blog.csdn.net/qq_23858785/article/details/132679526
  • 最新文章
  • 【JVM】编译执行与解释执行的区别是什么?JVM 使用哪种方式?
    用 Hashids 优雅解决 C 端自增 ID 暴露问题
    V8引擎 精品漫游指南--Ignition篇(上) 指令 栈帧 槽位 调用约定 内存布局 基础内容
    LLVM Pass快速入门(四):代码插桩
    milkup:桌面端 markdown AI续写和即时渲染
    基于项目工程构建SBOM(软件物料清单)的研究
    鸿蒙应用开发UI基础第二节:鸿蒙应用程序框架核心解析与实操
    .NET 中如何快速实现 List 集合去重?
    扣子Coze实战:从0到1打造抖音+小红书热点监控智能体
    浅谈数据访问层
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号