ELKStack入门篇(四)之Filebeat
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的更多相关文章
- 【SSRS】入门篇(四) -- 向报表添加数据
原文:[SSRS]入门篇(四) -- 向报表添加数据 定义好数据集后 [SSRS]入门篇(三) -- 为报表定义数据集 ,就可以开始设计报表了,将要显示在报表的字段.文本框.图像和其他项从工具箱拖放到 ...
- FPGA基础入门篇(四) 边沿检测电路
FPGA基础入门篇(四)--边沿检测电路 一.边沿检测 边沿检测,就是检测输入信号,或者FPGA内部逻辑信号的跳变,即上升沿或者下降沿的检测.在检测到所需要的边沿后产生一个高电平的脉冲.这在FPGA电 ...
- ELK快速入门(四)filebeat替代logstash收集日志
ELK快速入门四-filebeat替代logstash收集日志 filebeat简介 Filebeat是轻量级单用途的日志收集工具,用于在没有安装java的服务器上专门收集日志,可以将日志转发到log ...
- ELKStack入门篇(一)之ELK部署和使用
一.ELKStack简介 1.ELK介绍 中文指南:https://www.gitbook.com/book/chenryn/elk-stack-guide-cn/details ELK Stack包 ...
- ELKStack入门篇(五)之实用架构解析
(1)用户通过nginx或haproxy访问ELK日志统计平台,IP地址为keepalived的vip地址. (2)nginx将请求转发到kibana (3)kibana到elasticsearch获 ...
- C++入门篇四
常量引用:形参不能修改,节省开辟内存空间的开销 用一级指针代替二级指针常量引用,使用场景,修饰形参为只读const int a=10会分配内存如果使用引用,在前面加了一个const的话,那么就不可以修 ...
- ELKStack入门篇(三)之logstash收集日志写入redis
1.部署Redis 1.1.下载redis [root@linux-node2 ~]# wget http://download.redis.io/releases/redis-4.0.6.tar.g ...
- ELKStack入门篇(二)之Nginx、Tomcat、Java日志收集以及TCP收集日志使用
1.收集Nginx的json格式日志 1.1.Nginx安装 [root@linux-node1 ~]# yum install nginx -y [root@linux-node1 ~]# vim ...
- 【SSRS】入门篇(五) -- 设置报表格式
原文:[SSRS]入门篇(五) -- 设置报表格式 在上一节 [SSRS]入门篇(四) -- 向报表添加数据 我们设置好了报表,并可以预览到数据,如下图: 当报表完成后,有个重要的工作就是美化报表格式 ...
随机推荐
- CATransaction:原子化操作、批量操作、整体设置、自动添加
Transactions are CoreAnimation's mechanism for batching multiple layer- tree operations into atomic ...
- js事件的机制
1.html事件处理程序 <button id="btn1" onclick="alert(1);">按钮1</button> 2.do ...
- bbs论坛浏览器兼容性问题
一直都是在chrome上进行调试,今天终于把bbs论坛这个项目搭建完了,进入IE.Firefox看了看 吓哭了!!! 火狐 Edge chrome 特别是加了<!DOCTYPE html> ...
- 安装Windows7步骤
我初次装Linux系统的时候,查过一些资料,然后也有网友教过我,这里做一个总结,和大家分享一下(U盘安装). 事实上我们平时电脑开机的时候,是有个启动顺序的,他并非直接进入我们的操作系统, ...
- Strategy(策略)模式
1.概述 在软件开发中也常常遇到类似的情况,实现某一个功能有多种算法或者策略,我们可以根据环境或者条件的不同选择不同的算法或者策略来完成该功能.如查找.排序等,一种常用的方法是硬编码(Hard Cod ...
- iOS:UITableView相关(18-10-20更)
UITableView用得较多,遇到的情况也较多,单独记录一篇. 一.零散的技巧 二.取cell 三.cell高度 四.导航栏.TableView常见问题相关 五.自定义左滑删除按钮图片 六.仅做了解 ...
- java spring-WebSocket json参数传递与接收
Websocket原理(摘抄) 一.websocket与http WebSocket是HTML5出的东西(协议),也就是说HTTP协议没有变化,或者说没关系,但HTTP是不支持持久连接的(长连接,循环 ...
- BZOJ 3489: A simple rmq problem(K-D Tree)
Time Limit: 40 Sec Memory Limit: 512 MBSubmit: 2579 Solved: 888[Submit][Status][Discuss] Descripti ...
- linux学习笔记一:远程连接linux服务器
环境介绍:win7电脑,通过VM虚拟出linux系统,安装centOS7 通过Xshell连接linux,ftp访问服务器资源. 遇到的问题,ftp连不上linux 解决:linux上安装ftp服务 ...
- promise 格式
promise执行过程(test) var arr =new Array() var obj =new Object() let p =new Promise(function(resolve,rej ...