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

x33g5p2x  于2022-06-27 转载在 其他  
字(2.6k)|赞(0)|评价(0)|浏览(346)

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

CSDN 社区图书馆,开张营业!

深读计划,写书评领图书福利~

相关文章