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:</