linux上安装logstash

01 上传或是wget logstash包 wget https://artifacts.elastic.co/downloads/logstash/logstash-6.6.1.tar.gz

02 解压tar包 tar -zxvf logstash-6.6.1.tar.gz

03 配置logstash-6.6.1/config下的配置文件如logstash-sample.conf中指定es的地址

 

04 后台启动logstash

nohup ./bin/logstash -f config/logstash-sample.conf >>logstash_start.out 2>&1 &

05. 配置springboot项目中logback-spring.xml文件进行日志收集

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<consolePlugin/>
<!-- 动态读物yml文件里面配置的logstash地址-->
<springProperty scope="context" name="logstashAddress" source="logstash" defaultValue="default"/>
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_DIR}_%d{yyyy-MM-dd}.log
</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{100}
- %msg%n
</pattern>
<charset class="java.nio.charset.Charset">UTF-8</charset>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level
%logger{36}-%msg%n
</pattern>
<charset class="java.nio.charset.Charset">UTF-8</charset>
</encoder>
</appender>
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>${logstashAddress}</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>

<include resource="org/springframework/boot/logging/logback/base.xml"/>
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
<appender-ref ref="LOGSTASH"/>
</root>

</configuration>
————————————————
版权声明:本文为CSDN博主「weixin_38239459」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_38239459/article/details/117369798

posted on 2022-04-27 17:33  南山以南丶  阅读(776)  评论(0编辑  收藏  举报

导航