🔥
Caster 開發日誌
  • Java
    • JVM Performance Tool
      • Java Debug Wire Protocol (JDWP) 的詳細介紹
      • JConsole 詳細介紹
    • Spring Boot
      • Spring Security
      • Spring Boot Admin
      • Spring Event
      • Spring AOP
      • Spring Boot JUnit 5
      • Apache Dubbo
    • Reflect 應用
    • ELK + F 建構
    • Socket.IO
    • OCR - 光學字元辨識
    • 讀取JAR resource文件
    • LocalTime & MySQL時間精度
    • Gradle multi module
    • MyBatis-Plus
    • Java Date operation
    • Java IP to Long
    • Apache Commons lang3 應用
      • Function 應用
    • Cloud Platform
      • Amazon S3
        • SDK V1
          • Bucket
        • SDK V2
          • Bucket
      • Google Cloud Platform
      • Azure Cloud
        • Storage
      • OVHcloud
        • Config
    • SSL/TLS工具
    • Util 工具
      • Jackson Json工具
      • Charles應用
      • JMeter – Performing Distributed Load Testing with Docker
    • Redis
      • Stream
      • Redisson 分布式鎖機制
      • Create Redis Cluster Using Docker
      • List Operations
    • Java 8
      • method & constructor Reference
      • CompletableFuture
      • FunctionInterface
      • Stream 應用
      • 繁簡轉換 - 簡易調整
    • MySQL
      • 建立測試用 流水號Table
      • SQL 效能調校 - Explain
      • SQL 效能調校 - Partition
      • 排程 - Event
    • Apache ShardingSphere
  • Kubernetes
    • 初入江湖(K8S)
    • 零中斷服務滾動更新
    • Kubernetes DNS
    • Ingress & Ingress Controller 教學
    • Ingress TLS Easy setup
  • 指令集
  • Telegram
  • SourceTree
    • 踩坑紀錄(ㄧ) - Git Flow
    • 踩坑紀錄(二) - 修改檔名
  • 專案統計
    • Robot
    • Recharge
  • GitHub
    • Actions
  • GitLab
    • 介紹 GitLab
    • 使用 Docker 自架 GitLab
    • 簡介 GitLab CI/CD
      • GitLab Runner 詳細介紹與設定方式
Powered by GitBook
On this page
  1. Java

ELK + F 建構

Elasticsearch + Logstash + Kibana + FileBeat 四個組件的組合

Logstash 在 ELK 架構中,是負責把收到的純文字資料,做特定的規則處理,就可以變成指定的欄位。 建立欄位的好處是可以方便搜尋,而且也能做到比全文檢索更好的分析,可說是欄位切的好,查詢沒煩惱。 我個人認為 Logstash 中最精華的部分就屬 Grok Filter。 本篇將簡單教學如何透過 Logstash Grok Filter 建立 Elasticsearch 欄位。

  • FileaBeat 收集log資料送往 Logstash

  • Logstash 過濾資料再送往 Elasticsearch

  • Elasticsearch 搜尋資料引擎 Kibana會來請求搜尋log資料

  • Kibana UI介面

啟動辦法:

先去下載ELK + F 檔案, 記住版本上的對應.

  • E:到bin 目錄底下, 直接啟動 -> ./elasticsearch

  • L:到bin 目錄底下, 需修改config 及啟動時帶入config位置. 直接啟動 -> ./logstash -f ../config/logstash.conf

  • K:到bin 目錄底下, 直接啟動 ->./kibana

  • F:到bin 目錄底下, 直接啟動 ->./filebeat

各項設定:

filebeat.yml

name: localhost
output:
  logstash:
    enabled: true
    hosts:
      - localhost:5044
    index: "localhost"
filebeat.inputs:
    - type: log
      paths:
        - /Users/xxxxx/Desktop/log/xxxSystem/xxx.log
      multiline:
        pattern: '^\['
        negate: true
        match: after
      tags: ["restapi"]
#開啟debug模式
logging.level: debug
logging.selectors: [publish]
logging.to_files: true
logging.files:
    name: filebeat-localhost

logstash.conf

input {
  beats {
    port => 5044
  }
}

filter {
    grok {
        match => {"message" => [
                            "\[(?<XXOrderNo>[\w\d]*),(?<orderNo>[\w\d]*)\] %{TIMESTAMP_ISO8601:logDate} \[(?<threadName>[\w\d\s-]+)\] %{LOGLEVEL:logLevel}(?<emptySpace>\s+)\[(?<className>[\w.]+)\] - %{GREEDYDATA:message}"
                        ]
        }
        overwrite => [ "message" ]
    }

    # customize timestamp
    date {
      timezone => "Asia/Taipei"
      match => ["logDate", "ISO8601"]
      target => "@timestamp"
    }

    if "restapi" in [tags]{
      mutate {
          add_field => { "c_file_name" => "restapi" }
      }
    }

    mutate {
        remove_tag => [ "beats_input_codec_plain_applied" ]
        remove_field => [ "emptySpace" ]
    }
}

output {

  stdout {
    codec => rubydebug
  }

  # Sending properly parsed log events to elasticsearch
  elasticsearch {
    hosts => ["localhost:9200"]
    index => "logstash-%{c_file_name}-%{+YYYY.MM.dd}"
  }

}
// 可使用default setting
// 可使用default setting
// 亦可修改 memory 設定等

查看結果:

可至Kibana 介面查看log檔案是否傳至Elasticsearch

參考網站:

PreviousReflect 應用NextSocket.IO

Last updated 1 year ago

測試 Log filter 網站

https://medium.com/@d101201007/centos7-elk-filebeat-%E6%8C%87%E4%BB%A4%E5%AE%89%E8%A3%9D-%E7%85%A7%E8%91%97%E8%B2%BC%E4%B8%8A%E5%B0%B1%E5%B0%8D%E4%BA%86-73f456381491
https://blog.johnwu.cc/article/how-to-install-elasticsearch-logstash-and-kibana-elk-stack-on-centos-red-hat.html
https://grokdebug.herokuapp.com/