Filebeat是轻量级单用途的日志收集工具,用于在没有安装java的服务器上专门收集日志,可以将日志转发到logstash、elasticsearch或redis等场景中进行下一步处理。 
官方文档:https://www.elastic.co/guide/en/beats/filebeat/6.0/index.html

1、Filebeat安装和配置

1.1、filebeat安装

#RPM安装
[root@linux-node2 ~]# curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.0.1-x86_64.rpm
[root@linux-node2 ~]# rpm -vi filebeat-6.0.-x86_64.rpm #docker安装
[root@linux-node2 ~]# docker pull docker.elastic.co/beats/filebeat:6.0.

1.2、filebeat配置输出到文件测试

[root@linux-node2 ~]# grep -v "#" /etc/filebeat/filebeat.yml |grep -v "^$"
filebeat.prospectors:
- type: log
enabled: true
paths:
- /var/log/*.log
- /var/log/messages #配置收集的日志路径
exclude_lines: ['^DBG',"^$"] #排除以DBG开头和空行
document_type: filesystem-log-5612 #设置类型
filebeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false
setup.template.settings:
index.number_of_shards: 3
setup.kibana:
output.file: #输出到文件
path: "/tmp"
filename: "filebeat.txt"
[root@linux-node2 ~]# systemctl restart filebeat
[root@linux-node2 ~]# echo "666666666666666" >> /var/log/messages
[root@linux-node2 conf.d]# tailf /tmp/filebeat.txt
{"@timestamp":"2018-01-02T03:55:54.680Z","@metadata":{"beat":"filebeat","type":"doc","version":"6.0.1"},"message":"666666666666666","source":"/var/log/messages","offset":3164930,"prospector":{"type":"log"},"beat":{"name":"linux-node2","hostname":"linux-node2","version":"6.0.1"}}

2、配置filebeat输出到redis

[root@linux-node2 ~]# vim /etc/filebeat/filebeat.yml
#修改output
output.redis:
hosts: "192.168.56.12"
db: ""
port: ""
password: ""
key: "filesystem-log-5612"
[root@linux-node2 ~]# systemctl restart filebeat
[root@linux-node2 ~]# echo "" >> /var/log/messages #查看redis中是否有数据
[root@linux-node2 ~]# redis-cli -h 192.168.56.12 -a
192.168.56.12:> select
OK
192.168.56.12:[]> KEYS *
) "filesystem-log-5612"
192.168.56.12:[]> llen filesystem-log-
(integer)
192.168.56.12:[]> llen filesystem-log-
(integer)
192.168.56.12:[]> llen filesystem-log-
(integer)
192.168.56.12:[]> llen filesystem-log-
(integer)
192.168.56.12:[]> llen filesystem-log-
(integer)

3、配置linux-node1节点的logstash取redis中的数据

#配置logstash
[root@linux-node1 conf.d]# vim redis-logstash.conf
input {
redis {
data_type => "list"
host => "192.168.56.12"
db => ""
port => ""
password => ""
key => "filesystem-log-5612" }
} output {
elasticsearch {
hosts => ["192.168.56.11:9200"]
index => "filesystem-log-5612-%{+YYYY.MM.dd}"
}
}
#检测语法
[root@linux-node1 conf.d]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/redis-logstash.conf -t
OpenJDK -Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults
Could not find log4j2 configuration at path /usr/share/logstash/config/log4j2.properties. Using default config which logs errors to the console
Configuration OK
#重启logstash
[root@linux-node1 conf.d]# systemctl restart logstash
#写入messages日志
[root@linux-node1 conf.d]# echo "helloworld" >> /var/log/messages
[root@linux-node1 conf.d]# echo "helloworld" >> /var/log/messages
[root@linux-node1 conf.d]# echo "helloworld" >> /var/log/messages
#查看redis数据
[root@linux-node2 ~]# redis-cli -h 192.168.56.12 -a
192.168.56.12:> select
OK
192.168.56.12:[]> KEYS *
) "filesystem-log-5612"
192.168.56.12:[]> llen filesystem-log-
(integer)
192.168.56.12:[]> llen filesystem-log-
(integer)
192.168.56.12:[]> llen filesystem-log-
(integer)
192.168.56.12:[]> llen filesystem-log-
(integer)
192.168.56.12:[]> llen filesystem-log-
(integer)
192.168.56.12:[]> llen filesystem-log-
(integer)
192.168.56.12:[]> llen filesystem-log-
(integer)

4、head插件查看以及kibana添加索引

5、监控redis长度脚本

为了监控Redis的队列长度,可以写一个监控脚本对redis进行监控,并增加zabbix报警

[root@linux-node2 ~]# vim redis-test.py
#!/usr/bin/env python
import redis
def redis_conn():
pool=redis.ConnectionPool(host="192.168.56.12",port=,db=,password=)
conn = redis.Redis(connection_pool=pool)
data = conn.llen('filesystem-log-5612')
print(data)
redis_conn()
[root@linux-node2 ~]# python redis-test.py #当前redis队列长度为0

ELKStack入门篇(四)之Filebeat的更多相关文章

  1. 【SSRS】入门篇(四) -- 向报表添加数据

    原文:[SSRS]入门篇(四) -- 向报表添加数据 定义好数据集后 [SSRS]入门篇(三) -- 为报表定义数据集 ,就可以开始设计报表了,将要显示在报表的字段.文本框.图像和其他项从工具箱拖放到 ...

  2. FPGA基础入门篇(四) 边沿检测电路

    FPGA基础入门篇(四)--边沿检测电路 一.边沿检测 边沿检测,就是检测输入信号,或者FPGA内部逻辑信号的跳变,即上升沿或者下降沿的检测.在检测到所需要的边沿后产生一个高电平的脉冲.这在FPGA电 ...

  3. ELK快速入门(四)filebeat替代logstash收集日志

    ELK快速入门四-filebeat替代logstash收集日志 filebeat简介 Filebeat是轻量级单用途的日志收集工具,用于在没有安装java的服务器上专门收集日志,可以将日志转发到log ...

  4. ELKStack入门篇(一)之ELK部署和使用

    一.ELKStack简介 1.ELK介绍 中文指南:https://www.gitbook.com/book/chenryn/elk-stack-guide-cn/details ELK Stack包 ...

  5. ELKStack入门篇(五)之实用架构解析

    (1)用户通过nginx或haproxy访问ELK日志统计平台,IP地址为keepalived的vip地址. (2)nginx将请求转发到kibana (3)kibana到elasticsearch获 ...

  6. C++入门篇四

    常量引用:形参不能修改,节省开辟内存空间的开销 用一级指针代替二级指针常量引用,使用场景,修饰形参为只读const int a=10会分配内存如果使用引用,在前面加了一个const的话,那么就不可以修 ...

  7. ELKStack入门篇(三)之logstash收集日志写入redis

    1.部署Redis 1.1.下载redis [root@linux-node2 ~]# wget http://download.redis.io/releases/redis-4.0.6.tar.g ...

  8. ELKStack入门篇(二)之Nginx、Tomcat、Java日志收集以及TCP收集日志使用

    1.收集Nginx的json格式日志 1.1.Nginx安装 [root@linux-node1 ~]# yum install nginx -y [root@linux-node1 ~]# vim ...

  9. 【SSRS】入门篇(五) -- 设置报表格式

    原文:[SSRS]入门篇(五) -- 设置报表格式 在上一节 [SSRS]入门篇(四) -- 向报表添加数据 我们设置好了报表,并可以预览到数据,如下图: 当报表完成后,有个重要的工作就是美化报表格式 ...

随机推荐

  1. 在windows下解压缩rar文件

    这是一篇比较无聊的博文.只是给博客除草的. 我从我的移动硬盘里翻出来了一堆电子书,从哪拿到的我忘了,但是都打在rar的压缩包里,这让我查找起来非常不方便.前几天找某本书看,就没有查到,又百度到的下载地 ...

  2. 关于使用Filter降低Lucene tf idf打分计算的调研

    将query改成filter,lucene中有个QueryWrapperFilter性能比较差,所以基本上都须要自己写filter.包含TermFilter,ExactPhraseFilter,Con ...

  3. UVa 11346 - Probability(几何概型)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. 【[JSOI2009]火星藏宝图】

    这里是\(sb\)的\(O(nm)\)做法 上一篇题解里写的\(O(nm)\)做法并没有看懂,我真是好菜啊 这是一个用了斜率优化,但是复杂度仍然是\(O(nm)\)的做法 我们还是先写出简单的\(dp ...

  5. Django中的CBV和FBV

    Django中的CBV和FBV 一.  CBV CBV是采用面向对象的方法写视图文件. CBV的执行流程: 浏览器向服务器端发送请求,服务器端的urls.py根据请求匹配url,找到要执行的视图类,执 ...

  6. ethereumjs/merkle-patricia-tree-1-简介

    https://github.com/ethereumjs/merkle-patricia-tree SYNOPSIS概要 This is an implementation of the modif ...

  7. list详解

    #include <iostream> #include <vector> #include <list> std::list<std::string> ...

  8. AFSoundManager

    iOS audio playing (both local and streaming) and recording made easy through a complete and block-dr ...

  9. UVALive - 6837 Kruskal+一点性质(暴力枚举)

    ICPC (Isles of Coral Park City) consist of several beautiful islands. The citizens requested constru ...

  10. [Linux]使用宝塔面板做负载均衡时遇到的问题和解决办法

    最近公司的小程序因为高峰期访问缓慢的问题,打算用负载均衡试试.本人是个新手,在网上找了几篇负载均衡的文章看了看,最后还是用了宝塔面板的负载均衡插件...这个服务器我也是刚刚接手,很多东西都是以前的同事 ...