【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

相关推荐
南客先生2 小时前
海量聊天消息处理:ShardingJDBC分库分表、ClickHouse冷热数据分离、ES复合查询方案、Flink实时计算与SpringCloud集成
java·clickhouse·elasticsearch·flink·springcloud·shardingjdbc
MaYuKang4 小时前
「ES数据迁移可视化工具(Python实现)」支持7.x索引数据互传
大数据·数据库·python·mysql·elasticsearch
Elasticsearch7 小时前
使用 AutoGen 与 Elasticsearch
elasticsearch
xmyLydia9 小时前
Kafka + Elasticsearch 构建搜索型审计日志系统实战(含 Kibana 可视化)
elasticsearch·kafka
怒放吧德德19 小时前
MySQL篇:MySQL如何实时同步到ES
mysql·elasticsearch·面试
细心的莽夫20 小时前
Elasticsearch复习笔记
java·大数据·spring boot·笔记·后端·elasticsearch·docker
码农周21 小时前
Elasticsearch 报错 Limit of total fields [1000] has been exceeded
大数据·elasticsearch
Elastic 中国社区官方博客1 天前
Elasticsearch 堆内存使用情况和 JVM 垃圾回收
大数据·jvm·数据库·elasticsearch·搜索引擎·全文检索
道长没有道观1 天前
ubuntu系统下部署使用git教程
git·ubuntu·elasticsearch
菜鸟、上路1 天前
Elasticsearch 集群节点下线方案
大数据·elasticsearch