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]入门篇(四) -- 向报表添加数据 我们设置好了报表,并可以预览到数据,如下图: 当报表完成后,有个重要的工作就是美化报表格式 ...
随机推荐
- Guava包学习-Cache
这段时间用到了ehcache和memcache,memcache只用来配置在tomcat中做负载均衡过程中的session共享,然后ehcache用来存放需要的程序中缓存. Guava中的Cache和 ...
- thinkphp3.2.3代码审计
<?php namespace Home\Controller; use Think\Controller; class UserController extends Controller { ...
- [运维笔记] Nginx编译安装
yum -y install pcre-devel.x86_64 yum -y install openssl openssl-devel.x86_64 useradd www -s /sbin/no ...
- springmvc与Structs2本质区别
1.前端控制器不同:structs2入口是一个filter过滤器,springmvc入口是一个servlet. 2.设计思想不同: struts2通过在action类中定义成员变量接收请求参数,str ...
- Linux环境安装Nexus
Linux环境安装Nexus Nexus可以做Maven私服,私服不是Maven的核心概念,它仅仅是一种衍生出来的特殊的Maven仓库.有三种专门的Maven仓库管理软件可以用来帮助大家建立私服: N ...
- Dubbo实践(二)架构
架构 节点角色说明 节点 角色说明 Provider 暴露服务的服务提供方 Consumer 调用远程服务的服务消费方 Registry 服务注册与发现的注册中心 Monitor 统计服务的调用次数和 ...
- Shell笔记-04
如果表达式中包含特殊字符,Shell 将会进行替换.例如,在双引号中使用变量就是一种替换,转义字符也是一种替换. 举个例子: #!/bin/bash a=10 echo -e "Value ...
- Xcode 5.1安装插件:规范凝视生成器VVDocumenter
类似java的多行凝视! 安装过程: 1.前往GitHub下载project文件:VVDocumenter-Xcode 2.用Xcode打开project,Command + B Build成功后,能 ...
- Mysql实现主从同步
根据网上众多参考案例,继续在VM虚拟机里实现MySQL主从同步功能.步骤如下: * 首先明确下环境 主库本地windows ip192.168.0.103 从库虚拟机mysql5.6 ip192.16 ...
- 使用XWAF框架(3)——下载文件
XWAF提供了HttpFileDownloader类用于简化用户下载文件的编码.该类提供了重载方法“downloadFile(String filePath, String fName)”实现下载.程 ...