轻量型日志采集器 Filebeat基本使用

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: 轻量型日志采集器 Filebeat基本使用作者主页:https://www.couragesteak.com/

1 介绍

Filebeat是一个日志文件托运工具,安装客户端后,filebeat会监控指令日志,
下载地址:
https://www.elastic.co/cn/beats/filebeat

https://www.elastic.co/cn/downloads/past-releases/filebeat-7-17-0

注意:版本需要和 Elasticearch 版本相同

2 安装

2.1 下载安装

tar -zxvf filebeat-7.17.0-linux-x86_64.tar.gz

3 收集日志配置

安装目录下新建conf/star_module_log.yml

在这里插入代码片

4 启动

chown root filebeat.yml
chown root modules.d/nginx.yml 
./filebeat -e

./filebeat -e -c filebeat_log.yml

./filebeat -e -c filebeat.yml -d "publish"

5 举例

5.1 Filebeat收集日志并输出到控制台

"name": "ccccccccc":自定义name字段
"message": "你好" :日志中输出:你好
fields_under_root: true:将name定义为顶级字段

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /usr/local/nginx/logs/access.log
  fields:
    name: ccccccccc
  fields_under_root: true
output.console:
  pretty: true
./filebeat -e -c filebeat_log.yml

5.2 Filebeat收集Nginx运行日志并输出到es

filebeat_nginx.yml

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /usr/local/nginx/logs/access.log
  tags: ["nginx"]
setup.template.settings:
  index.number_of_shards: 1
output.elasticsearch:
  hosts: ["118.195.175.213:9200"]
  username: "elastic"
  password: "EtWvHc8lGh05YS7vS1mq"
./filebeat -e -c filebeat_nginx.yml

查看es,默认会按照filebeat-版本号-日期格式生成一个索引:

  • nginx日志数据在字段==message==中

在这里插入图片描述
到这里,仍然属于原始数据

filebeat_nginx.yml

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /usr/local/nginx/logs/access.log
  tags: ["nginx"]
    #keys_under_root可以让字段位于根节点,默认为false
  json.keys_under_root: true
  #对于同名的key,覆盖原有key值
  json.overwrite_keys: true
  #将解析错误的消息记录储存在error.message字段中
  json.add_error_key: true
setup.template.settings:
  index.number_of_shards: 1
output.elasticsearch:
  hosts: ["118.19*.17*.213:9200"]
  username: "elastic"
  password: "EtWvHc8lGh05YS7vS1mq"

5.3 基于Nginx module使用Filebeat收集Nginx运行日志并输出到es

## 查看module集合
./filebeat modules list
## 启用module
./filebeat modules enable module名称
## 禁用module
./filebeat modules disable module名称

启动nginx module

./filebeat modules enable nginx

查看module列表

./filebeat modules list

配置Nginx Module

${FILEBEAT_HOME}/modules.d/ nginx.yml

- module: nginx
  access:
    enabled: true
    var.paths: ["/usr/local/nginx/logs/access.log"]

  error:
    enabled: true
    var.paths: ["/usr/local/nginx/logs/error.log"]

配置filebeat:filebeat_nginx_module.yml

filebeat.inputs:
setup.template.settings:
  index.number_of_shards: 3
output.elasticsearch:
  hosts: ["http://118.195.175.213:9200"]
  username: "elastic"
  password: "EtWvHc8lGh05YS7vS1mq"
filebeat.config.modules:
  path: ${path.config}/modules.d/*.yml
  reload.enabled: false

启动filebeat

./filebeat -e -c filebeat_nginx_module.yml
./filebeat -e -c filebeat_nginx_module.yml -d 'publish'

到此,可以查看数据索引

参考地址:
https://blog.csdn.net/zyxwvuuvwxyz/article/details/108831962

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
3月前
|
存储 数据采集 JavaScript
深入理解数仓开发(一)数据技术篇之日志采集
深入理解数仓开发(一)数据技术篇之日志采集
|
29天前
|
消息中间件 监控 Kafka
Filebeat+Kafka+Logstash+Elasticsearch+Kibana 构建日志分析系统
【8月更文挑战第13天】Filebeat+Kafka+Logstash+Elasticsearch+Kibana 构建日志分析系统
72 3
|
4月前
|
存储 数据采集 Kubernetes
一文详解K8s环境下Job类日志采集方案
本文介绍了K8s中Job和Cronjob控制器用于非常驻容器编排的场景,以及Job容器的特点:增删频率高、生命周期短和突发并发大。文章重点讨论了Job日志采集的关键考虑点,包括容器发现速度、开始采集延时和弹性支持,并对比了5种采集方案:DaemonSet采集、Sidecar采集、ECI采集、同容器采集和独立存储采集。对于短生命周期Job,建议使用Sidecar或ECI采集,通过调整参数确保数据完整性。对于突发大量Job,需要关注服务端资源限制和采集容器的资源调整。文章总结了不同场景下的推荐采集方案,并指出iLogtail和SLS未来可能的优化方向。
148 1
|
1月前
|
存储 应用服务中间件 nginx
部署ELK+filebeat收集nginx日志
部署ELK+filebeat收集nginx日志
部署ELK+filebeat收集nginx日志
|
2月前
|
消息中间件 Kubernetes Kafka
日志采集/分析
日志采集/分析
44 7
|
24天前
|
存储 Kubernetes Java
在k8S中,容器内日志是怎么采集的?
在k8S中,容器内日志是怎么采集的?
|
27天前
|
数据采集 监控 Kubernetes
Job类日志采集问题之iLogtail以减小容器发现和开始采集的延时如何优化
Job类日志采集问题之iLogtail以减小容器发现和开始采集的延时如何优化
|
27天前
|
数据采集 Kubernetes Java
Job类日志采集问题之在日志中添加容器的元信息标签,如何操作
Job类日志采集问题之在日志中添加容器的元信息标签,如何操作
|
27天前
|
存储 容器
Job类日志采集问题之DaemonSet采集方式的参数以减小采集延时如何调整
Job类日志采集问题之DaemonSet采集方式的参数以减小采集延时如何调整
|
27天前
|
容器
Job类日志采集问题之ECI产品采集方式对于弹性扩缩容是如何支持的
Job类日志采集问题之ECI产品采集方式对于弹性扩缩容是如何支持的