ELK + Filebeat 日志分析系统

架构图

环境

OS:CentOS 7.4
Filebeat: 6.3.2
Logstash: 6.3.2
Elasticsearch 6.3.2
Kibana: 6.3.2

FileBeat安装配置

安装

wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.3.2-x86_64.rpm
yum localinstall filebeat-6.3.2-x86_64.rpm

配置

这里以nginx日志为例作为演示

配置文件:/etc/filebeat/filebeat.yml

filebeat.prospectors:
- input_type: log #输入类型为log
paths: #日志路径
- /usr/local/nginx/logs/*.access.log
document_type: ngx-access-log #日志类型
- input_type: log
paths:
- /usr/local/nginx/logs/*.error.log
document_type: ngx-error-log
output.logstash: #输出到Logstash(也可以输出到其他,如elasticsearch)
hosts: ["10.1.4.171:1007"]

启动

systemctl enable filebeat
systemctl start filebeat

Logstash安装配置

安装

wget https://artifacts.elastic.co/downloads/logstash/logstash-6.3.2.rpm
yum localinstall logstash-6.3.2.rpm

配置

Logstash需要自定义,自定义配置文件目录是/etc/logstash/conf.d

这里新建一个filebeat.conf配置文件

/etc/logstash/conf.d/filebeat.conf

input {
#输入方式是beats
beats {
port => "1007" #监听1007端口(自定义端口)
}
} filter {
if [type] == "ngx-access-log" { #对日志类型为ngx-access-log进行处理。日志类型为filebeat配置定义
grok {
patterns_dir => "/usr/local/logstash/patterns"
match => { #对传过来的message字段做拆分,分割成多个易读字段
message => "%{IPV4:remote_addr}\|%{IPV4:FormaxRealIP}\|%{POSINT:server_port}\|%{GREEDYDATA:scheme}\|%{IPORHOST:http_host}\|%{HTTPDATE:time_local}\|%{HTTPMETHOD:request_method}\|%{URIPATHPARAM:request_uri}\|%{GREEDYDATA:server_protocol}\|%{NUMBER:status}\|%{NUMBER:body_bytes_sent}\|%{GREEDYDATA:http_referer}\|%{GREEDYDATA:user_agent}\|%{GREEDYDATA:http_x_forwarded_for}\|%{HOSTPORT:upstream_addr}\|%{BASE16FLOAT:upstream_response_time}\|%{BASE16FLOAT:request_time}\|%{GREEDYDATA:cookie_formax_preview}"
}
remove_field => ["message"] #已经将message字段拆分,可以将message字段删除
} date {
match => [ "time_local", "dd/MMM/yyyy:HH:mm:ss Z"] #nginx日志中的时间替换@timestamp
remove_field => ["time_local"] #删除nginx日志时间字段
} mutate {
rename => ["http_host", "host"] #nginx日志中http_host字段,替换host字段
}
}
} output {
elasticsearch { # 输出到elasticsearch
hosts => ["127.0.0.1:9200"]
index => "logstash-%{type}-%{+YYYY.MM.dd}" #输出索引格式
}
}

启动

systemctl enable logstash
systemctl start logstash

Elasticsearch安装配置

安装

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.rpm
yum localinstall elasticsearch-6.3.2.rpm

配置

/etc/elasticsearch/elasticsearch.yml

path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 0.0.0.0
http.port: 9200
#elasticsearch-head需要下列配置
http.cors.enabled: true
http.cors.allow-origin: "*"

启动

systemctl enable elasticsearch
systemctl start elasticsearch

elasticsearch-head安装

elasticsearch-head用于连接elasticsearch,并提供一个前端管理页面

git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start
open http://localhost:9100/

Kibana安装配置

安装

wget https://artifacts.elastic.co/downloads/kibana/kibana-6.3.2-x86_64.rpm
yum localinstall kibana-6.3.2-x86_64.rpm

配置

默认配置就好

启动

nohup /usr/share/kibana/bin/kibana &> /usr/share/kibana/logs/kibana.stdout &

nginx代理到kibana

安装nginx

yum install nginx

配置

/etc/nginx/conf.d/kibana.conf

server {
listen 80;
server_name test.kibana.com; root html;
access_log /var/log/nginx/test.kibana.com.access.log main;
error_log /var/log/nginx/test.kibana.com.error.log; proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_connect_timeout 10;
proxy_read_timeout 30;
proxy_send_timeout 180;
proxy_ignore_client_abort on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_set_header Host $host; location /monitor {
default_type text/plain;
return 200 "OK";
} location /echoip {
default_type text/plain;
return 200 $http_x_forwarded_for,$remote_addr;
} location / {
expires off;
if ($server_port = "80") {
proxy_pass http://127.0.0.1:5601;
}
proxy_pass https://127.0.0.1:5601; }
}

启动

systemctl enable nginx
systemctl start nginx

后记

本文只是简单介绍了一下ELK+Filebeat日志分析系统的安装配置,以及一个简单的nginx日志处理过程。要想更细致的学习ELK体系,可以看ELKstack 中文指南。虽然该书以ELK5版本进行讲解,ELK6也可以看。

ELK + Filebeat 日志分析系统的更多相关文章

  1. [原创]ubuntu14.04部署ELK+redis日志分析系统

    ubuntu14.04部署ELK+redis日志分析系统 [环境] host1:172.17.0.4 搭建ELK+redis服务 host2:172.17.0.3 搭建logstash+nginx服务 ...

  2. Docker搭建ElasticSearch+Redis+Logstash+Filebeat日志分析系统

    一.系统的基本架构 在以前的博客中有介绍过在物理机上搭建ELK日志分析系统,有兴趣的朋友可以看一看-------------->>链接戳我<<.这篇博客将介绍如何使用Docke ...

  3. docker:搭建ELK 开源日志分析系统

    ELK 是由三部分组成的一套日志分析系统, Elasticsearch: 基于json分析搜索引擎,Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片 ...

  4. ELK + Filebeat日志分析系统安装

    之前搭建过elk,用于分析日志,无奈服务器资源不足,开了多个Logstash之后发现占用内存过高,于是现在改为Filebeat做日志收集,记录一下搭建过程和遇到问题的解决方案. 第一步 , 安装jdk ...

  5. springboot+ELK+logback日志分析系统demo

    之前写的有点乱,这篇整理了一下搭建了一个简单的ELK日志系统 借鉴此博客完成:https://blog.csdn.net/qq_22211217/article/details/80764568 设置 ...

  6. ELK+Beats日志分析系统部署

    一.            名词介绍: E:ElasticSearch 搜索,简称es L:Logstash 管理日志和事件的工具 K:Kibana 功能强大的数据显示客户端 Beats 轻量级数据传 ...

  7. filebeat+redis+logstash+elasticsearch+kibana搭建日志分析系统

    filebeat+redis+elk搭建日志分析系统 官网下载地址:https://www.elastic.co/downloads 1.下载安装filebeat wget https://artif ...

  8. 十分钟搭建和使用ELK日志分析系统

    前言 为满足研发可视化查看测试环境日志的目的,准备采用EK+filebeat实现日志可视化(ElasticSearch+Kibana+Filebeat).题目为“十分钟搭建和使用ELK日志分析系统”听 ...

  9. Docker笔记(十):使用Docker来搭建一套ELK日志分析系统

    一段时间没关注ELK(elasticsearch —— 搜索引擎,可用于存储.索引日志, logstash —— 可用于日志传输.转换,kibana —— WebUI,将日志可视化),发现最新版已到7 ...

随机推荐

  1. Java学习NO.4

    学习内容如下: 数组的概述与特征 概述: 它是具有相同数据类型的一组数据的集合 存储在数组中的数据我们称之为数组元素,可通过“数组名[下标]”的方式进行访问,下标也就是索引,从0开始,且负数索引是无效 ...

  2. MySQL中查询、删除重复记录的方法大全

    查找所有重复标题的记录: select title,count(*) as count from user_table group by title having count>1; SELECT ...

  3. php中生成透明背景png缩略图程序

    /** *$sourePic:原图路径 * $smallFileName:小图名称 * $width:小图宽 * $heigh:小图高 */function pngthumb($sourePic,$s ...

  4. Filter 中空指针错误

    Filter 是过滤器,凡是通过servlet  JSP 的请求需要filter 进行过滤或者拦截操作,保证数据的合法或者逻辑正确性 但是写第一个filter 配置完成后,发现jsp 文件进不去了,直 ...

  5. bootstrap框架下 单选按钮组的选中以及取值问题

    1.业务功能:四个按钮只能选中一个,且默认选择水准4 先看代码. <div class="btn-group" data-toggle="buttons" ...

  6. 安装activeMQ(window,linux系统)

    今天学习了activeMQ服务器,把它说成成服务器是我的理解,,呵呵,首先,说一下它的安装, 官网:http://activemq.apache.org/overview.html window下的安 ...

  7. jQuery-3.事件篇---事件对象的使用

    jQuery事件对象的作用 事件中的Event对象容易被初学者忽略掉,可能大多时候初学者不知道怎么去用它,但有些时候它还是非常有用的 一个标准的"click"点击事件 $(elem ...

  8. vue 安装

    安装cnpm npm install -g cnpm --registry=https://registry.npm.taobao.org 安装 vue.js cnpm install -g vue- ...

  9. 解决eclipse使用tomcat启动项目后访问项目404的问题

    今天启动项目的时候发现项目启动没有问题,但是一直访问不到页面,F12发现根本没有交互,百度后解决了,故记下来为以后提供方法,若有不同的解决方法,欢迎指教 1.首先要确保你的tomcat下没有项目,怎么 ...

  10. 【步步为营 Entity Framework+Reporting service开发】-(2) Code Fir

    也许有人问,为什么要用EF创建爱你数据表,code first好处是什么? 使用EF创建数据库/表,只需要设计简单的C#类,再表内容变化的时候他会自动更新数据库结构,并且保留原有数据. EF很强大,支 ...