1. 构建环境
Elasticsearch环境构建,参照:Elasticsearch入门
1.1 Logstash环境构建
下载tar.gz包到Linux中并解压:logstash下载
编辑config/logstash.conf文件如下:
input {
tcp {
mode => "server"
host => "0.0.0.0"
port => 5044
codec => json_lines
}
}
output {
elasticsearch {
hosts => ["http://192.168.3.12:9200"]
index => "logstash-%{+YYYY.MM.dd}"
document_type => "_doc"
#flush_size => 200
user => "用户名"
password => "密码"
}
stdout {
codec => rubydebug
}
}
启动:[logstash解压文件所在]/bin/logstash -f ../config/logstash.conf
1.2 Kibana环境构建
下载tar.gz包到Linux中并解压:kibana下载
编辑config/kibana.yml文件如下:
server.host: "0.0.0.0"
elasticsearch.url: "http://192.168.3.12:9200"
启动:[kibana解压文件所在]/bin/kibana
1.3 SpringBoot配置
在pom.xml中添加依赖:
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>5.2</version>
</dependency>
在resources文件夹下添加logback-spring.xml文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>192.168.3.12:5044</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder" />
</appender>
<root level="INFO">
<appender-ref ref="LOGSTASH" />
<appender-ref ref="CONSOLE" />
</root>
</configuration>
2. 图形化界面
依次开启,Elasticsearch、Logstash、Kibana、SpringBoot
就可以通过Kibana提供的图形化界面看到SpringBoot输出的日志了:
Kibana的使用方法,参照一下博客:
kibana5.3的基础使用Discover , visualize , Dashboard
(责任编辑:IT) |