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. 运维shell脚本函数语法

    在fun.sh 文件里,使用函数来封装脚本内容 usege() { echo "hello world" echo "脚本怎么使用函数......"}usege ...

  2. neutron基础一(网络基本命令)基本命令,包括veth peer

    ip addr ip link tcpdump -i veth1 -e -v route -n ip route arp ethtool -S veth0 ip link add type veth ...

  3. c++利用类进行单链表的插入,删除,清空操作

    #if 1 #include <iostream> #include <stdlib.h> #include <time.h> #include <fstre ...

  4. Eureka的初识

    在bili看完spring cloud eureka高可用注册中心的视频以后总结: 正常开发中,肯定有一个功能聚集服务中心,将功能方法全部写入其中,也就是一个springboot项目.该服务配置如下: ...

  5. "Loading a plug-in failed The plug-in or one of its prerequisite plug-ins may be missing or damaged and may need to be reinstalled"

    The Unarchiver 虽好,但存在问题比我们在mac上zip打包一个软件xcode, 然后copy to another mac, 这时用The Unarchiver解压缩出来的xcode包不 ...

  6. jQuery-4.动画篇---淡入淡出效果

    jQuery中淡出动画fadeOut 让元素在页面不可见,常用的办法就是通过设置样式的display:none.除此之外还可以一些类似的办法可以达到这个目的.这里要提一个透明度的方法,设置元素透明度为 ...

  7. element 时间选择器——年

    <el-date-picker v-model="fileYear" type="year" placeholder="选择年"> ...

  8. onkeyup+onafterpaste 只能输入数字和小数点

    1.文本框只能输入数字代码(小数点也不能输入)<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafter ...

  9. Linux防火墙开启关闭查询

    1.centos7防火墙 命令含义: –zone #作用域 –add-port=80/tcp #添加端口,格式为:端口/通讯协议 –permanent #永久生效,没有此参数重启后失效 服务与端口的启 ...

  10. io读取遇到的问题

    使用Inputstream输入流读取数据的时候总要使用一个额byte[]数组进行读取 byte[] b= new byte[1024]; while((len = in.read(b)) != -1) ...