1、安装elasticserch
2、安装kibana
1、下载kibana(以kibana-6.5.4-linux-x86_64为例)
https://www.elastic.co/downloads
2、解压
tar -zxvf kibana-6.5.4-linux-x86_64.tar.gz
3、配置elasticsearc位置
修改 config/kibana.yml
elasticsearch.url: "http://192.168.1.20:9200"
注意:
如果你想kibana可以被哪个ip地址访问就修改server.host,我这里允许被任何用户访问
server.host: "0.0.0.0"
4、启动
bin/kibana
5、访问
安装logstash
Spring Boot2.x与Logstash 6.5.4整合
pom.xml 中需要引入jar包:
<!--集成logstash-->
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>4.9</version>
</dependency>
logback-spring.xml 日志配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<!--应用名称-->
<property name="APP_NAME" value="websocket"/>
<!--日志文件保存路径-->
<property name="LOG_FILE_PATH" value="D:/websocket/logs}"/>
<contextName>${APP_NAME}</contextName>
<!--每天记录日志到文件appender-->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE_PATH}/${APP_NAME}-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<!--输出到logstash的appender-->
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>192.168.1.20:4560</destination>
<!-- <destination>192.168.1.21:4560</destination>
<destination>192.168.1.22:4560</destination>
<destination>192.168.1.23:4560</destination>-->
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">
<!-- 自定义变量,在logstash配置中用-->
<customFields>{"appname":"${APP_NAME}"}</customFields>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
<appender-ref ref="LOGSTASH"/>
</root>
</configuration>
logstash 配置文件logstash-springboot.conf:
input {
tcp {
port => 4560
codec => json_lines
}
}
output{
elasticsearch {
hosts => ["localhost:9200"]
index => "%{[appname]}"
}
stdout { codec => rubydebug }
}
启动logstash
logstash -f logstash.conf