FileBeat笔记(一)——安装和采集Springboot日志

本文详细介绍了如何在Windows环境下安装和配置FileBeat进行Springboot日志采集,包括FileBeat的下载安装、配置文件filebeat.yml的设置、Logstash输出配置、Kibana仪表盘的创建以及多行日志采集的实现。此外,还讨论了如何根据日志时间字段替换和标识不同系统模块的字段来创建ES索引。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 下载和安装

# windows 下载,本文以windows命令演示
https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.6.2-windows-x86_64.zip

# linux 下载
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.6.2-darwin-x86_64.tar.gz

1.1. 配置filebeat.yml

完整的配置放在文章末尾

1.2. ES模板fields.yml

直连ES时可以自动导模板,否则需要手动导入

# 手动导入
.\filebeat.exe setup --template -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'
# 删除旧的模板文档
curl -XDELETE 'http://localhost:9200/filebeat-*'

1.3. 设置kibana仪表盘

# 初次使用可以跳过此步,可以熟悉了之后再配置Kibana
.\filebeat.exe setup --dashboards

1.4. 为Logstash输出设置仪表板

# 初次使用可以跳过此步,可以熟悉了之后再配置Kibana
.\filebeat.exe setup -e `
  -E output.logstash.enabled=false `
  -E output.elasticsearch.hosts=['140.143.206.106:9200'] `
  -E output.elasticsearch.username=filebeat_internal `
  -E output.elasticsearch.password=YOUR_PASSWORD `
  -E setup.kibana.host=localhost:5601

2. 启动

2.1. 安装

如果是windows上, 可以修改一下install-service-filebeat.ps1里的安装路径(E:\filebeat-6.6.2-windows-x86_64)

# Delete and stop the service if it already exists.
if (Get-Service filebeat -ErrorAction SilentlyContinue) {
   
   
  $service = Get-WmiObject -Class Win32_Service -Filter "name='filebeat'"
  $service.StopService()
  Start-Sleep -s 1
  $service.delete()
}

$workdir = Split-Path $MyInvocation.MyCommand.Path

# Create the new service.
New-Service -name filebeat `
  -displayName Filebeat `
  -binaryPathName "`"$workdir\filebeat.exe`" -c `"$workdir\filebeat.yml`" -path.home `"$workdir`" -path.data `"E:\filebeat-6.6.2-windows-x86_64\datas`" -path.logs `"E:\filebeat-6.6.2-windows-x86_64\logs`""

2.2. 启动
# mac and linux 执行:
sudo chown root filebeat.yml 
sudo ./filebeat -e
sudo ./filebeat -e -c filebeat.yml -d "publish"

# windows 以管理员身份执行,记得修改ps1里的路径
# 安装,没有报错则成功
PS E:\filebeat-6.6.2-windows-x86_64> .\install-service-filebeat.ps1

# 卸载
PS E:\filebeat-6.6.2-windows-x86_64> .\uninstall-service-filebeat.ps1

# 启动
PS E:\filebeat-6.6.2-windows-x86_64> Start-Service filebeat

启动成功后可以查看日志,看是否正常采集
测试阶段,采集的日志偏移量存在filebeat注册表中,删除datas目录下的registry相关文件后,可以从头再次采集

3. 配置多行采集

3.1. multiline在Filebeat中的配置实现(第一种方式,推荐):
filebeat.prospectors:
    -
       paths:
          - /home/project/elk/logs/test.log
       input_type: log 
       multiline:
            pattern:</
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值