【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

相关推荐
Elasticsearch2 天前
如何使用 Agent Builder 排查 Kubernetes Pod 重启和 OOMKilled 事件
elasticsearch
Elasticsearch3 天前
通用表达式语言 ( CEL ): CEL 输入如何改进 Elastic Agent 集成中的数据收集
elasticsearch
海兰5 天前
离线合同结构化提取与检索:LangExtract + 本地DeepSeek + Elasticsearch 9.x
大数据·elasticsearch·django
yumgpkpm5 天前
AI视频生成:Wan 2.2(阿里通义万相)在华为昇腾下的部署?
人工智能·hadoop·elasticsearch·zookeeper·flink·kafka·cloudera
Sheffield5 天前
如果把ZooKeeper按字面意思比作动物园管理员……
elasticsearch·zookeeper·kafka
嗝屁小孩纸5 天前
ES索引重建(零工具纯脚本执行)
大数据·elasticsearch·搜索引擎
Elastic 中国社区官方博客5 天前
使用 Jina Embeddings v5 和 Elasticsearch 构建“与你的网站数据聊天”的 agent
大数据·人工智能·elasticsearch·搜索引擎·容器·全文检索·jina
Elastic 中国社区官方博客5 天前
Elastic 公共 roadmap 在此
大数据·elasticsearch·ai·云原生·serverless·全文检索·aws
码云数智-大飞5 天前
像写 SQL 一样搜索:dbVisitor 如何用 MyBatis 范式颠覆 ElasticSearch 开发
sql·elasticsearch·mybatis