【Python】windows10搭建ELK5日志收集系统

本文介绍如何使用ELK Stack(Elasticsearch、Logstash、Kibana)进行日志数据收集、处理与可视化分析的过程。包括配置Logstash读取Nginx日志文件、解析并导入到Elasticsearch中,最后通过Kibana展示分析结果。
摘要由CSDN通过智能技术生成

需要准备的软件


安装elasticsearch-5.5.1

  • 首先要配好JDK的环境变量,保存CMD可以运行Java和javac
  • 安装好后访问:localhost:9200

  • 打开谷歌浏览器,安装扩展程序:elasticsearch-head


安装logstash-5.5.1

  • 解压文件,进入bin目录
  • 创建一个配置文件,这里叫nginx_data.config
input {
    file {
        path => "C:\Users\DELL\Desktop\ELK\nginx.log"
        start_position => "beginning"
    }
}
filter {
    grok {
      match => { "message" => "%{IP:client} - - \[%{HTTPDATE:logdate}\] \"%{WORD:verb} %{URIPATHPARAM:request} HTTP/%{NUMBER:httpversion}\" %{NUMBER:http_status_code} %{NUMBER:bytes} \"%{NOTSPACE:ref}\" \"%{DATA:user_agent}\"" }
    }
    date {
        match => ["logdate", "dd/MMM/yyyy:HH:mm:ss Z"]
        target => "@timestamp"
    }
    kv {
                source => "request"
                field_split => "&?"
                value_split => "="
        }
    urldecode {
        all_fields => true
    }
}
output {
    elasticsearch {
        hosts => "localhost:9200"
    }
    stdout {
        codec => json_lines
    }
}
  • nginx.log为:
127.0.0.1 - - [18/Aug/2017:01:00:07 +0800] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36" "-"
127.0.0.1 - - [18/Aug/2017:01:00:07 +0800] "GET /favicon.ico HTTP/1.1" 404 571 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36" "-"
127.0.0.1 - - [18/Aug/2017:01:00:10 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36" "-"
127.0.0.1 - - [18/Aug/2017:01:00:14 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36" "-"
127.0.0.1 - - [18/Aug/2017:01:00:59 +0800] "GET /favicon.ico HTTP/1.1" 404 571 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36" "-"
127.0.0.1 - - [18/Aug/2017:01:01:00 +0800] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36" "-"
127.0.0.1 - - [18/Aug/2017:01:01:00 +0800] "GET /favicon.ico HTTP/1.1" 404 571 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36" "-"
127.0.0.1 - - [18/Aug/2017:01:01:00 +0800] "GET /favicon.ico HTTP/1.1" 404 571 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36" "-"
  • 运行:logstash.bat -f nginx_data.config 往ES中导入数据

安装kibana-5.5.1-windows-x86

  • 解压文件,修改conf/kibana.yml文件,解开连接ES的注释
  • 进入bin目录,执行kibana.bat 即可启动
  • 访问http://localhost:5601 进行配置

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值