Spring Boot + ELK搭建日志监控框架
准备ELK三件套
Elasticsearch+Logstash+Kibana
下载地址:https://www.elastic.co/cn/downloads/
下载时注意Elasticsearch和Kibana版本一致,否则启动kibana时会出现版本不一致,无法支持的错误
[ERROR][elasticsearch-service] This version of Kibana (v x.x.x) is incompatible with the following Elasticsearch nodes in your cluster: v7.16.2 @ 127.0.0.1:9200 (127.0.0.1)
不喜欢用Kibana的朋友,也可以直接通过chrome插件(elasticsearch-head)插件查看数据
下载后分别解压,存放于自己的资源目录
Elasticsearch启动
进入到bin目录下,执行启动脚本elasticsearch
Logstash启动
创建配置文件log4j_to_es.conf
input {
tcp {
#监控端口自己定义,与后面Spring Boot项目中的日志配置文件配置的端口一致
#只要与自己本机要启动的服务端口不冲突即可
port => 8888
codec => json_lines
}
}
output {
elasticsearch {
hosts => ["127.0.0.1:9200"]
action=>"index"
#ES索引名称(自己定义的)
#index => "%{[appname]}-%{+YYYY.MM.dd}"
index => "boot"
}
stdout{
codec => json_lines
}
}
执行logstansh -f log4j_to_es.conf启动
Kibana启动
进入bin目录执行kibana启动
构建Spring Boot项目
添加maven依赖
<dependency>
<groupId>net.logstash.logback</groupId>
<