美文网首页
ELK日志收集处理

ELK日志收集处理

作者: Pretty_Boy | 来源:发表于2018-12-06 03:54 被阅读43次

    https://www.elastic.co/

    1)收集-能够采集多种来源的日志数据 Log4js PM2
    2)传输-能够稳定的把日志数据传输到中央系统 Filebeat
    3)存储-如何存储日志数据 Elasticsearch
    4)分析-可以支持 UI 分析 Kibana
    5)警告-能够提供错误报告,监控机制 Monitor

    ELK :Elasticsearch Logstash Kibana

    • FIilbeat :将服务器上收集的日志发送到Logstash中(格式使用log4js规范化)
    • Logstash:Logstash将日志接受过滤并转发到Elasticsearch存储
    • Elasticsearch:存储收集来的日志,提供实时的数据查询
    • Kibana:数据可视化服务

    多应用的监控架构

    监控系统.png

    当然也可做更加分布式的部署


    1. 下载 Filebeat

    配置 filebeat.yml

    filebeat.inputs:
      type: log    
      enabled: true    // 默认关闭
      paths:
        ~/logs/*.log     //  ~/logs/*/*.log  仅匹配二级目录下的.log文件
    
    output.logstash:
      hosts: ["localhost: 9900"]
    
    

    运行filebeat

    sudo ./filebeat -e -c filebeat.yml 
    
    // 如果提示权限问题,则使用以下代码运行
    sudo chown root filebeat.yml
    sudo ./filebeat -e -c filebeat.yml -d "publish"
    
    1. 下载 Logstash
      配置 config/logstash-sample.conf (没有则新建)
    input {
      beats {
        port => 9900
      }
    }
    
    output {
      elasticsearch {
        hosts => ["http://localhost:9200"]
        index => "testlog"
      }
    }
    

    运行logstash, logstash 自己占用9600-9700 之间第一个可用的端口
    可在config/logstash.yml 中配置

    bin/logstash -f config/logstash-sample.conf  // 使用配置文件启动
    bin/logstash -e "input { stdin{} } output { stdout {} }"  // 使用字符串配置启动
    // 在终端接受并输出
    

    测试logstash正确开启: curl localhost:9600 (具体端口看启动时的日志/自己配置)


    image.png
    1. 下载 Elasticsearch
      配置 config/elasticsearch.yml
    path.data: /Users/rogers/Project/Agora/test/util/data
    path.data: /Users/rogers/Project/Agora/test/util/logs
    

    运行elasticsearch

    bin/elasticsearch
    

    测试elasticsearch正确开启


    image.png

    使用elasticsearch提供的API 在elasticsearch上进行查找数据

    http://localhost:9200/_cat/indices?v // 查找当前所有Index

    http://localhost:9200/[Index][Type][ID/_search]
    http://localhost:9200/testlog/doc/_search // testlog下doc类中所有的数据
    http://localhost:9200/testlog/doc/_Ze_f2cBIQjv8oYr3PEN testlog下doc类中ID为_Ze_f2cBIQjv8oYr3PEN的数据
    等等丰富的API供用户调用
    注: 当加入未指定ID的数据时,自动为其生成随机ID

    1. 下载 Kibana

    配置 config/kibana.yml

    运行bin/kibana 默认端口为5601

    此时在页面中选择对应之前创建的Index,即可在discover中或其他页面看到所存在的数据


    至此,已将简单的日志收集转发并在kibana上进行展示的逻辑调通,
    接下来需要做两件事:

    1. 根据elasticsearch提供的API,做一个monitor达到告警的效果
    2. 得到告警后在kibana(多功能)中根据不同的条件,查看具体的日志信息。
    3. 由于本次调试仅在本地调试,所以很多配置直接采用了默认的配置,后续记录其他配置

    相关文章

      网友评论

          本文标题:ELK日志收集处理

          本文链接:https://www.haomeiwen.com/subject/ycqgcqtx.html