ELK+Filebeat

Filebeat概述

1.Filebeat简介

Filebeat是一款轻量级的日志收集工具,可以在非JAVA环境下运行。

因此,Filebeat常被用在非JAVAf的服务器上用于替代Logstash,收集日志信息
实际上,Filebeat几乎可以起到与Logstash相同的作用,可以将数据转发到Logstash、Redis或者是Elasticsearch中进行直接处理。

2.使用Filebeat的原因

因为logstash是jvm跑的,资源消耗比较大,启动一个logstash就需要消耗500M左右的内存
(这就是为什么logstash启动特别慢的原因)。

而filebeat只需要10M左右的内存资源。

常用的ELK日志采集方案中,大部分的做法就是将所有节点的日志内容通过filebeat发送到logstash,lostash根据配置文件进行过滤,然后将过滤之后的文件传输到elasticsearch中,最后通过kibana展示

3.Filebeat结合logstash的好处

Filebeat结合logstash中,Filebeat负责收集日志,logstash负责过滤

  • 1、通过logstash,具有基于磁盘的自适应缓冲系统,该系统将吸收传入的吞吐量,从而减轻Elasticsearch持续写入数据的压力。
  • 2、从其它数据源(例如数据库,s3对象存储或消息传递队列)中提取
  • 3、将数据发送到多个目的地,例如S3,HDFS(hadoop分部署文件系统)或写入文件
  • 4、使用数据流逻辑组成更复杂的处理管道。

本机直接收集日志实验

(Nginx日志)

实验组件

复制代码
Node1节点:node1/20.0.0.20			      Elasticsearch
Node2节点:node2/20.0.0.30				  Elasticsearch
Filebeat节点:20.0.0.10				      Logstash  Kibana  Filebeat  Nginx

实验步骤

1.安装Filebeat

复制代码
#10
cd /opt/
--上传filebeat-6.7.2-linux-x86_64.tar.gz--
tar -xf filebeat-6.7.2-linux-x86_64.tar.gz
mv filebeat-6.7.2-linux-x86_64 filebeat
vim /etc/logstash/logstash.yml
--64--
path.config: /opt/log

systemctl restart logstash

2.时间同步

复制代码
#所有节点
yum -y install ntpdate
ntpdate ntp.aliyun.com 
date

3.配置filebeat

复制代码
#修改nginx的端口,防止与apache冲突
vim /etc/nginx/nginx.conf
...
listen       8080;
listen       [::]:8080;
复制代码
#给nginx日志文件赋权
cd /var/log/nginx/
chmod 777 access.log error.log
复制代码
#配置filebeat
cd /opt/filebeat/
vim filebeat.yml
filebeat.inputs:

- type: log
  enabled: true	
  paths:
    - /var/log/nginx/access.log
    - /var/log/nginx/error.log
  tags: ["nginx"]
  fields:
    service_name: 20.0.0.10_nginx
    log_type: nginx
    from: 20.0.0.10

--------------Elasticsearch output-------------------
(全部注释掉)

----------------Logstash output---------------------
output.logstash:
  hosts: ["20.0.0.10:5044"]      #指定logstash的IP和端口

4.配置logstash

复制代码
cd /opt
mkdir log
cd log
vim file_nginx.conf

input {

        beats { port => "5044"}

}

output {

        if "nginx" in [tags] {
           elasticsearch {

                hosts => ["20.0.0.20:9200","20.0.0.30:9200"]
                index => "%{[fields][service_name]}-%{+YYYY.MM.dd}"

           }

        }

stdout {
        codec => rubydebug
       }

}

5.启动filebeat

复制代码
nohup ./filebeat -e -c filebeat.yml > filebeat.out &
-------------------------------------------------------------------------------------------
nohup:表示在后台记录执行命令的过程
./filebeat:运行文件
-e:使用标准输出的同时禁用syslog文件输出
-c:指定配置文件
将执行过程输出到filebeat.out文件当中
&:后台运行
-------------------------------------------------------------------------------------------
logstash -f file_nginx.conf --path.data /opt/test1 &

6.结果

远程收集多个日志实验

(Nginx+Apache+Mysql日志)

实验组件

复制代码
logstash节点:20.0.0.10
Node1节点:node1/20.0.0.20			      Elasticsearch
Node2节点:node2/20.0.0.30				  Elasticsearch
日志来源服务器:20.0.0.81                   MYsql  Nginx  Apache  Filebeat

实验步骤

1.安装Filebeat并配置

复制代码
#81
cd /opt/
--上传filebeat-6.7.2-linux-x86_64.tar.gz--
tar -xf filebeat-6.7.2-linux-x86_64.tar.gz
mv filebeat-6.7.2-linux-x86_64 filebeat
cd filebeat/
vim filebeat.yml

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /var/log/nginx/access.log
    - /var/log/nginx/error.log
  tags: ["nginx_81"]
  fields:
    service_name: 20.0.0.81_nginx
    log_type: nginx
    from: 20.0.0.81

- type: log
  enabled: true
  paths:
    - /etc/httpd/logs/access_log
    - /etc/httpd/logs/error_log
  tags: ["httpd_81"]
  fields:
    service_name: 20.0.0.81_httpd
    log_type: httpd
    from: 20.0.0.81

- type: log
  enabled: true
  paths:
    - /usr/local/mysql/data/mysql_general.log
  tags: ["mysql_81"]
  fields:
    service_name: 20.0.0.81_mysql
    log_type: mysql
    from: 20.0.0.81

--------------Elasticsearch output-------------------
(全部注释掉)

----------------Logstash output---------------------
output.logstash:
  hosts: ["20.0.0.10:5045"]      #指定logstash的IP和端口

2.配置logstash

复制代码
10:
cd /opt/log/
vim nhm_81.conf 

input {
        beats { port => "5045"}
}

output {
        if "nginx_81" in [tags] {
           elasticsearch {
                hosts => ["20.0.0.20:9200","20.0.0.30:9200"]
                index => "%{[fields][service_name]}-%{+YYYY.MM.dd}"
           }
        }

        if "httpd_81" in [tags] {
           elasticsearch {
                hosts => ["20.0.0.20:9200","20.0.0.30:9200"]
                index => "%{[fields][service_name]}-%{+YYYY.MM.dd}"
           }
        }

        if "mysql_81" in [tags] {
           elasticsearch {
                hosts => ["20.0.0.20:9200","20.0.0.30:9200"]
                index => "%{[fields][service_name]}-%{+YYYY.MM.dd}"
           }
        }

stdout {
        codec => rubydebug
       }

}

3.启动filebeat

复制代码
nohup ./filebeat -e -c filebeat.yml > filebeat.out &

logstash -f nhm_81.conf --path.data /opt/test2 &

4.结果

相关推荐
摘星编程2 天前
Linux 日志分析:用 ELK 搭建个人运维监控平台
linux·运维·elk·系统监控·性能优化维监
zzu123zsw5 天前
第一章 ELK Stack基础概念与架构
elk·架构
zzu123zsw5 天前
第二章 ELK安装部署与环境配置
elk
今生相伴9916 天前
ELFK:企业级日志管理的完整解决方案——从入门到精通
运维·elk·elasticsearch
刘一说7 天前
CentOS部署ELK Stack完整指南
linux·elk·centos
路上阡陌7 天前
ELK 部署
运维·elk·jenkins
斯普信专业组14 天前
ELK 统一日志分析系统部署与实践指南(下)
运维·elk
听说唐僧不吃肉14 天前
解析ELK(filebeat+logstash+elasticsearch+kibana)日志系统原理以及k8s集群日志采集过程
elk·elasticsearch·kubernetes
斯普信专业组14 天前
ELK 统一日志分析系统部署与实践指南(上)
elk
kunwen12322 天前
ELKB日志分析平台 部署
elk·es·日志分析·beats