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.结果

  • 21
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值