【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

相关推荐
Elasticsearch9 小时前
ES8 向量功能窥探系列(二):向量数据的存储与优化
elasticsearch
安审若无10 小时前
Elasticsearch中的监控(Monitoring)功能介绍
elasticsearch·搜索引擎·全文检索
leo_hush10 小时前
elasticsearch基本操作笔记
elasticsearch
咸鱼求放生20 小时前
es在Linux安装
大数据·elasticsearch·搜索引擎
xyhshen21 小时前
k8s下离线搭建elasticsearch
elasticsearch·容器·kubernetes
@泽栖1 天前
ES数据聚合
elasticsearch·搜索引擎
張萠飛1 天前
Linux下如何使用shell脚本导出elasticsearch中某一个index的数据为本地csv文件
linux·运维·elasticsearch
LanLance1 天前
ES101系列09 | 运维、监控与性能优化
java·运维·后端·elasticsearch·云原生·性能优化·golang
疯狂的沙粒1 天前
如何通过git命令查看项目连接的仓库地址?
大数据·git·elasticsearch
IT成长日记2 天前
Elasticsearch集群手动分片分配指南:原理与实践
大数据·elasticsearch·手动分片分配