欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

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

发布时间:2025/5/22 39 豆豆
生活随笔 收集整理的这篇文章主要介绍了 轻量型日志采集器 Filebeat基本使用 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

文章目录

    • 1 介绍
    • 2 安装
      • 2.1 下载安装
    • 3 收集日志配置
    • 4 启动
      • 5 举例
      • 5.1 Filebeat收集日志并输出到控制台
      • 5.2 Filebeat收集Nginx运行日志并输出到es
      • 5.3 基于Nginx module使用Filebeat收集Nginx运行日志并输出到es

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: logenabled: truepaths:- /usr/local/nginx/logs/access.logfields:name: cccccccccfields_under_root: true output.console:pretty: true ./filebeat -e -c filebeat_log.yml

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

filebeat_nginx.yml

filebeat.inputs: - type: logenabled: truepaths:- /usr/local/nginx/logs/access.logtags: ["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: logenabled: truepaths:- /usr/local/nginx/logs/access.logtags: ["nginx"]#keys_under_root可以让字段位于根节点,默认为falsejson.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: nginxaccess:enabled: truevar.paths: ["/usr/local/nginx/logs/access.log"]error:enabled: truevar.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/*.ymlreload.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

总结

以上是生活随笔为你收集整理的轻量型日志采集器 Filebeat基本使用的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。