【Elasticsearch】file-beat 将文件数据导入es

1、备份 filebeat.yml 文件:

2、新 filebeat.yml 文件配置示例:

复制代码
###################### Filebeat Configuration Example #########################

# ============================== Filebeat inputs ===============================

filebeat.inputs:
- type: log
  enabled: true  
  # 注意:
    # 文件最后必须回车换行,否则最后一行将不会被导入es。
    # 为避免数据重复写入,被指定路径的文件不会被二次执行,即使更新索引也不行。
  paths:
    - /home/lvlh/soft/filebeat-8.4.1-linux-x86_64/logtest/cdrlog02/cdr_*.log
  encoding: utf-8


# ================================== Outputs ===================================
# Configure what output to use when sending the data collected by the beat.

#控制台输出
#output.console:
  #pretty: true

# ---------------------------- Elasticsearch Output ----------------------------
output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["localhost:9200"]
  # 索引名称一般为'服务名称+ip+ --%{+yyyy.MM.dd}'
  index: "cdr-log-%{+yyyy.MM.dd}"
  username: "elastic"
  password: "CV-j4TSSiIhRgG0mCt-k"
  
# 配置文件的部分指定 用于设置的索引模板 Elasticsearch 中的映射。
# 如果启用了模板加载(默认值), 文件节拍成功后自动加载索引模板 连接到 Elasticsearch。
setup.template.name: "test-index-template-01"
setup.template.pattern: "test-index-template-*"  

#============================== Kibana =====================================

setup.kibana:              
  #kibanaIP地址
  host: "localhost:5601"
  username: "elastic"
  password: "CV-j4TSSiIhRgG0mCt-k"
  
###################### Filebeat Configuration Example #########################

# ============================== Filebeat inputs ===============================

filebeat.inputs:
- type: log
  enabled: true  
  # 注意:
    # 文件最后必须回车换行,否则最后一行将不会被导入es。
    # 为避免数据重复写入,被指定路径的文件不会被二次执行,即使更新索引也不行。
  paths:
    - /home/lvlh/soft/filebeat-8.4.1-linux-x86_64/logtest/test01/test_logfile_*.log
  # 日志标签,区别不同日志,下面建立索引会用到
  fields:
    index: "test-filebeat-01"
  # 指定被监控的文件的编码类型,使用plain和utf-8都是可以处理中文日志的
  encoding: utf-8
  # 多行日志开始的那一行匹配的pattern
  #multiline.pattern: ^{
  # 是否需要对pattern条件转置使用,不翻转设为true,反转设置为false。  【建议设置为true】
  #multiline.negate: true
  # 匹配pattern后,与前面(before)还是后面(after)的内容合并为一条日志
  #multiline.match: after
  
- type: log
  enabled: true  
  paths:
    - /home/lvlh/soft/filebeat-8.4.1-linux-x86_64/logtest/test02/apache-daily-access_*.log
  fields:
    index: "test-filebeat-02"
  encoding: utf-8

    
# ================================== Outputs ===================================
# Configure what output to use when sending the data collected by the beat.

#控制台输出
#output.console:
  #pretty: true

# ---------------------------- Elasticsearch Output ----------------------------
output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["localhost:9200"]
  # 索引名称一般为'服务名称+ip+ --%{+yyyy.MM.dd}'
  #index: "test-filebeat-01"
  # 
  indices:
    - index: "test-filebeat-01-%{+yyyy.MM.dd}"
      when.contains:
        fields:
          index: "test-filebeat-01"
    - index: "test-filebeat-02-%{+yyyy.MM.dd}"
      when.contains:
        fields:
          index: "test-filebeat-02"
  username: ""
  password: ""
  # ES重试次数,默认3次,超过3次后,当前事件将被丢弃
  max_retries: 3 
  
# 配置文件的部分指定 用于设置的索引模板 Elasticsearch 中的映射。
# 如果启用了模板加载(默认值), 文件节拍成功后自动加载索引模板 连接到 Elasticsearch。
setup.template.name: "test-index-template-01"
setup.template.pattern: "test-index-template-*"  

#============================== Kibana =====================================

setup.kibana:              
  #kibanaIP地址
  host: "localhost:5601"
  username: ""
  password: ""

3、启动:

在根路径下:./filebeat -e -c filebeat.yml

相关推荐
liushangzaibeijing11 小时前
Superpower 使用大纲
大数据·elasticsearch·搜索引擎
Elastic 中国社区官方博客12 小时前
每次操作一个 API 调用:Elastic Cloud Hosted 如何让大规模部署管理变得可行
大数据·运维·数据库·elasticsearch·搜索引擎·serverless
逸Y 仙X20 小时前
文章六:ElasticSearch 集群通信安全权限
java·大数据·服务器·elasticsearch·搜索引擎·全文检索
繁星星繁20 小时前
Git 入门之道:从版本流转到基础操作
大数据·git·elasticsearch
Elastic 中国社区官方博客1 天前
我们如何在 Elasticsearch Serverless 上将向量搜索吞吐量提升一倍
大数据·数据库·人工智能·elasticsearch·搜索引擎·云原生·serverless
愤怒的苹果ext2 天前
Flink同步到ES时间遇到的问题
elasticsearch·flink·时间
共享家95272 天前
OpenClaw核心功能
大数据·elasticsearch·搜索引擎
醉颜凉2 天前
实战教程:如何使用 Kibana 对 Elasticsearch 数据进行可视化和操作(从入门到精通)
大数据·elasticsearch·jenkins
oioihoii2 天前
CentOS 7单机部署Elasticsearch:这些坑和关键配置,生产环境踩过才知道
linux·elasticsearch·centos
Elastic 中国社区官方博客2 天前
Kibana 仪表板即代码:在 Elastic 9.4 中用于 Kibana 仪表板的 GitOps、漂移检测与 Terraform
大数据·人工智能·elasticsearch·搜索引擎·云原生·kibana·terraform