elk+filebeat收集springboot项目日志
目录
步骤 1: 安装和配置Elasticsearch
步骤 2: 安装和配置Logstash(可选)
步骤 3: 安装和配置Filebeat
步骤 4: 安装和配置Kibana
要使用ELK(Elasticsearch, Logstash, Kibana)堆栈和Filebeat来收集Spring Boot项目的日志,你可以按照以下步骤进行:
步骤 1: 安装和配置Elasticsearch
-
下载并安装Elasticsearch:
-
访问Elasticsearch官网下载适合你操作系统的版本。
-
解压并运行Elasticsearch。
-
-
启动Elasticsearch:
-
在命令行中运行
./bin/elasticsearch
(Linux或Mac)或bin\elasticsearch.bat
(Windows)。
-
-
验证Elasticsearch是否运行:
-
打开浏览器,访问
http://localhost:9200
,你应该能看到一个JSON响应,表明Elasticsearch正在运行。
-
步骤 2: 安装和配置Logstash(可选)
如果你的日志格式比较复杂或者需要进行预处理,可以使用Logstash。但如果你只是简单地将日志转发到Elasticsearch,这一步可以跳过。
-
下载并安装Logstash:
-
访问Logstash官网下载适合你操作系统的版本。
-
解压并运行Logstash。
-
-
配置Logstash:
-
创建一个Logstash配置文件(例如
springboot-logs.conf
),指定输入(filebeat输出)、过滤和输出(Elasticsearch)。 -
示例配置:
input {beats {port => 5044} } filter {grok {match => { "message" => "%{COMBINEDAPACHELOG}" }}date {match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]} } output {elasticsearch {hosts => ["localhost:9200"]index => "springboot-logs-%{+YYYY.MM.dd}"} }
-
启动Logstash:
./bin/logstash -f springboot-logs.conf
(Linux或Mac)或bin\logstash.bat -f springboot-logs.conf
(Windows)。
-
步骤 3: 安装和配置Filebeat
-
下载并安装Filebeat:
-
访问Filebeat官网下载适合你操作系统的版本。
-
解压并运行Filebeat。
-
-
配置Filebeat:
-
编辑
filebeat.yml
文件,指定日志文件路径和输出到Elasticsearch:filebeat.inputs: - type: log ##新版本为filestream 并为其设置一个idenabled: truepaths:- /path/to/your/springboot/logs/*.log # 修改为你的日志文件路径output.elasticsearch:hosts: ["localhost:9200"]indices:- index: "springboot-logs-%{+yyyy.MM.dd}" # 使用与Logstash相同的索引格式
-
启动Filebeat:
./filebeat -e -c filebeat.yml
(Linux或Mac)或filebeat.exe -e -c filebeat.yml
(Windows)。
-
步骤 4: 安装和配置Kibana
-
下载并安装Kibana:
-
访问Kibana官网下载适合你操作系统的版本。
-
解压并运行Kibana。
-
-
启动Kibana:
-
在命令行中运行
./bin/kibana
(Linux或Mac)或bin\kibana.bat
(Windows)。 -
打开浏览器,访问
http://localhost:5601
,你应该能看到Kibana的界面。
-
-
创建索引模式:
-
在Kibana中,点击“Management” -> “Kibana” -> “Index Patterns”,创建一个新的索引模式,例如
springboot-logs-*
。 -
现在你可以开始查询和可视化你的Spring Boot日志了。
-
通过以上步骤,你可以使用ELK堆栈和Filebeat来收集、存储和分析Spring Boot项目的日志。
以上为简单步骤,具体配置信息参考我的另外一篇文章。或者参考下面的这篇文章:ELK日志监控分析系统的探索与实践(一):利用Filebeat监控Springboot日志-腾讯云开发者社区-腾讯云