ELK解决方案

概述

背景

logs 分布在 logger数据库,应用程序自己的log,系统log。没有统一的界面,查询比较麻烦,格式不统一,难以重复定制方案。

解决思路

利用logstash将各个地方,各种格式的log集中起来,规范化,保存到elasticsearch 中,使用kibana提供的界面来管理和查看。

步骤

  1. logstash 收集log,并统一输出到 elasticseach中。
  • 1.1 logstash需要安装到所有产生log文件的机器上和最后统一处理redis队列的机器上。

  • 1.2 节点 logstash从所有log文件的机器上收集log ,输出到redis。统一由index logstash 存储到elasticsearch中。

  • 1.3 配置文件 输入,处理,输出

    input {
    }
    filter {
    }
    output {
    }
    

    input 中配置收集log,比如 节点logstash从文件变化中收集。

    input{
        file {
        path => ["/config/nginx.log"]
        type => "nginx"
        start_position => "end"
        codec => "json"
        }
    }
    

    节点logstash 输出到redis,output配置

    output{
        redis{
          db => '0'
          host => '127.0.0.1'
          password => '1231'
          port => '6379'  
          key => 'redis_key_nginx'
      }
    }
    

    index logstash从redis中收集。

    input{
       redis {
        host => "172.17.0.36"
        port => "6379"
        data_type => "list"
        key => "redis_key_nginx"
        type => "nginx"
        }
    }
    

    filter 处理

    filter{
        json {
       source => "log_response_body"
       target => "log_response_body_json"
     }
     json {
     source => "log_request_headers"
     target => "log_request_headers_json"
     }
    }
    

    output 到elastics

     output{
          elasticsearch {
            host => "127.0.0.1"
          port => "9300"
        }
    }
    
  1. 需要安装启动elasticsearch。
  2. 安装kibana,并连接到elasticsearch 的 9300端口。

你可能感兴趣的:(ELK解决方案)