【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

相关推荐
春日见18 小时前
Autoware使用教程
大数据·人工智能·深度学习·elasticsearch·搜索引擎·docker·容器
会员源码网18 小时前
Elasticsearch从零启动指南:安装、配置、启停与排坑全解析
大数据·elasticsearch·搜索引擎
lcx_defender19 小时前
【Docker】Docker部署运行Elasticsearch
elasticsearch·docker·jenkins
洛阳纸贵2 天前
JAVA高级工程师--Elasticsearch安装以及内置分词器、IK分词器
大数据·elasticsearch·搜索引擎
Howie Zphile2 天前
Git 拉 NocoBase 2.0 beta(next 分支),并“每天自动更新 + 自动编译 + 自动重启”
大数据·git·elasticsearch
历程里程碑2 天前
子串----和为K的子数组
大数据·python·算法·leetcode·elasticsearch·搜索引擎·哈希算法
2401_859049082 天前
lvgl移植到Linux踩坑
linux·运维·arm开发·elasticsearch·嵌入式·ubantu
峥嵘life2 天前
Android EDLA CTS、GTS等各项测试命令汇总
android·学习·elasticsearch
invicinble2 天前
一文了解git
大数据·git·elasticsearch
Elastic 中国社区官方博客2 天前
使用 LangGraph 和 Elasticsearch 构建 人机协同( HITL )AI agent
大数据·人工智能·elasticsearch·搜索引擎·ai·机器人·全文检索