zoukankan      html  css  js  c++  java
  • Filebeat安装及使用

    https://blog.csdn.net/dwyane__wade/article/details/80169051

    LogStash 插件

    使用

    https://blog.csdn.net/wyqlxy/article/details/52622867

    Filebeat简介

    • Filebeat由两个主要组成部分组成:prospector(探勘者)和 harvesters(矿车)。这些组件一起工作来读取文件并将事件数据发送到指定的output。
      • prospector: 负责找到所有需要进行读取的数据源
      • harvesters:负责读取单个文件的内容,并将内容发送到output中,负责文件的打开和关闭。

    Filebeat工作原理

    • Filebeat可以保持每个文件的状态,并且频繁地把文件状态从注册表里更新到磁盘。这里所说的文件状态是用来记录上一次Harvster读取文件时读取到的位置,以保证能把全部的日志数据都读取出来,然后发送给output。如果在某一时刻,作为output的ElasticSearch或者Logstash变成了不可用,Filebeat将会把最后的文件读取位置保存下来,直到output重新可用的时候,快速地恢复文件数据的读取。在Filebaet运行过程中,每个Prospector的状态信息都会保存在内存里。如果Filebeat出行了重启,完成重启之后,会从注册表文件里恢复重启之前的状态信息,让FIlebeat继续从之前已知的位置开始进行数据读取。

    Filebeat用途

    • 为什么要用filebeat来收集日志?为什么不直接用logstash收集日志?

    因为logstash是jvm跑的,资源消耗比较大,启动一个logstash就需要消耗500M左右的内存(这就是为什么logstash启动特别慢的原因),而filebeat只需要10来M内存资源。常用的ELK日志采集方案中,大部分的做法就是将所有节点的日志内容通过filebeat发送到logstash,logstash根据配置文件进行过滤。然后将过滤之后的文件输送到elasticsearch中,通过kibana去展示。

    • 适用于集群环境下,服务多,且部署在不同机器

    Filebeat安装

    启动

    • ./filebeat -e -c filebeat.yml

      • -c:配置文件位置
      • -path.logs:日志位置
      • -path.data:数据位置
      • -path.home:家位置
      • -e:关闭日志输出
      • -d 选择器:启用对指定选择器的调试。 对于选择器,可以指定逗号分隔的组件列表,也可以使用-d“*”为所有组件启用调试.例如,-d“publish”显示所有“publish”相关的消息。
    • 后台启动filebeat

      • nohup ./filebeat -e -c filebeat.yml >/dev/null 2>&1 & 将所有标准输出及标准错误输出到/dev/null空设备,即没有任何输出
      • nohup ./filebeat -e -c filebeat.yml > filebeat.log &

      停止filebeat:ps -ef |grep filebeat, kill -9 pid

    启动返回:
    
    2018-03-26T14:43:12.218+0800    INFO    instance/beat.go:468    Home path: [/usr/local/elk/filebeats/filebeat-6.2.1-linux-x86_64] Config path: [/usr/local/elk/filebeats/filebeat-6.2.1-linux-x86_64] Data path: [/usr/local/elk/filebeats/filebeat-6.2.1-linux-x86_64/data] Logs path: [/usr/local/elk/filebeats/filebeat-6.2.1-linux-x86_64/logs]
    2018-03-26T14:43:12.218+0800    INFO    instance/beat.go:475    Beat UUID: 0aac391c-e8ef-4437-b5d0-62c147b118ee
    2018-03-26T14:43:12.218+0800    INFO    instance/beat.go:213    Setup Beat: filebeat; Version: 6.2.3
    2018-03-26T14:43:12.218+0800    INFO    elasticsearch/client.go:145 Elasticsearch url: http://172.30.1.45:9200
    2018-03-26T14:43:12.218+0800    INFO    pipeline/module.go:76   Beat name: iZ2ze2lelgjwuyib5l73eaZ
    2018-03-26T14:43:12.219+0800    INFO    instance/beat.go:301    filebeat start running.
    2018-03-26T14:43:12.219+0800    INFO    registrar/registrar.go:108  Loading registrar data from /usr/local/elk/filebeats/filebeat-6.2.1-linux-x86_64/data/registry
    2018-03-26T14:43:12.219+0800    INFO    registrar/registrar.go:119  States Loaded from registrar: 0
    2018-03-26T14:43:12.219+0800    INFO    crawler/crawler.go:48   Loading Prospectors: 1
    2018-03-26T14:43:12.219+0800    INFO    crawler/crawler.go:82   Loading and starting Prospectors completed. Enabled prospectors: 0
    2018-03-26T14:43:12.219+0800    INFO    [monitoring]    log/log.go:97   Starting metrics logging every 30s
    2018-03-26T14:43:12.219+0800    INFO    cfgfile/reload.go:127   Config reloader started
    2018-03-26T14:43:12.219+0800    INFO    cfgfile/reload.go:219   Loading of config files completed.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    结合logstash测试

    • 准备日志文件,放置filebeat监听日志目录下:
    mkdir -p /usr/local/elk/filebeats/log
    
    上传日志文件xxx.log
    • 1
    • 2
    • 3
    • 新建logstash_filebeat.conf,内容如下:
    input {
      beats {
        port => 5044
      }
    }
    output {
            stdout { codec => rubydebug }
    }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 启动logstash:logstash -f logstash_filebeat.conf

    • 修改filebeat.yml

    filebeat:
      prospectors:
      -
          paths:
            - /usr/local/elk/log/*.log
          fields:
             service: project_name
    output:
      #elasticsearch:
      #   hosts: ["localhost:9200"]
       logstash:
        hosts: ["172.30.1.45:5044"]
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • bin目录下启动filebeat:./filebeat -e -c filebeat.yml -d “publish”

    • 现象:logstash控制台输出日志。

    filebeat输出到elasticsearch,通过kibana展示

    • 准备logstash配置文件,内容如下:
    input {
      beats {
        port => 5044
      }
    }
    filter{
            if [fields][service] == "project_name" {
                multiline {
                        pattern => "^20" negate => true what => "previous"
                }
                grok {
                        match => { "message" => "s*%{TIMESTAMP_ISO8601:log_print_time} s*%{LOGLEVEL:log_level} s*[%{DATA:thread_number}] s*%{LOGLEVEL:log_level1} s*%{DATA:method}-> s*(?<info>([sS]*))"}
                }
                date {
                        match => ["log_print_time", "yyyy-MM-dd HH:mm:ss,SSS"]
                        target => "@timestamp"
                }
                mutate {  
                        remove_field => ["log_print_time"]  
                }  
            }
    }
    
    output {
    
    if[fields][service] == "project_name" {
      elasticsearch {
            hosts => ["172.30.1.45:9200"]
            index => "project_name-%{+YYYY.MM.dd}"
        }
    }
     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
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    Filebeat配置多个探索者(prospectors)

    filebeat:
      prospectors:
      -
          paths:
            - /usr/local/elk/redislog/*.log
        # 相当于logstash中的type
          fields:
             service: redis
      -
          paths:
            - /usr/local/elk/log/*.log
          fields:          
             service: ecps
    
    output:
      #elasticsearch:
      #   hosts: ["localhost:9200"]
       logstash:
        hosts: ["172.30.1.45:5044"]
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    参考博客:https://blog.csdn.net/fenglailea/article/details/52486471

  • 相关阅读:
    虚拟机安装配置
    大整数加法 面试题
    结构体
    操作文件
    Gcd HDU
    牛客练习赛47 A DongDong破密码 (异或性质,递推)
    ACM常用之 异或运算的性质。
    Wannafly挑战赛22 C 多项式(大数,多项式极限)
    大数全能模板
    Wannafly挑战赛22 D 整数序列 (线段树维护三角函数值)
  • 原文地址:https://www.cnblogs.com/zhoading/p/13974683.html
Copyright © 2011-2022 走看看