Install the ELK
I chose to install the docker image. Refer to the elk – docker. Readthedocs. IO /
Pull the ELK mirror image
Docker pull sebp/elk: 7.10.0Copy the code
Run the mirror
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256" -p 5601:5601 -p 5044:5044 -p 9200:9200 -p 9300:9300 -it --name elk 649ed8dfdcc1
Copy the code
If the following error occurs during startup
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
The solution
CD vim/etc/security/limits. Conf behind the additional content below es hard nofiles 65536 es soft nofiles 65536Copy the code
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
The solution
Conf add vm.max_map_count=655360 Run the sysctl -p commandCopy the code
Restart the elk
docker restart elk
Copy the code
Integrate into the SpringBoot project
Add logstach dependencies
<dependency> <groupId>net.logstash.logback</groupId> <artifactId>logstash-logback-encoder</artifactId> The < version > 6.6 < / version > < / dependency >Copy the code
Configuration logback
Place logback-spring. XML in the rescource directory of the Springboot project
<? The XML version = "1.0" encoding = "utf-8"? > <configuration> <! -- Color log --> <! <conversionRule conversionWord=" CLR" converterClass="org.springframework.boot.logging.logback.ColorConverter" /> <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" /> <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" / > <! <property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-% CLR (%d{YYYY-MM-DD HH: mm: ss.) SSS} {abbreviation} % CLR (${LOG_LEVEL_PATTERN: - % 5 p}) % CLR (${PID: -} {magenta} % CLR (-) {abbreviation} % CLR ([% 15.15 t]) {abbreviation} X {traceLogId}] [% % the CLR (% 40.40 logger {39}) CLR (:) {abbreviation} {cyan} % % m % n ${wEx LOG_EXCEPTION_CONVERSION_WORD: - %}} "/ > <! - development environment - > < springProfile name = "dev" > < appender name = "STDOUT" class = "ch. Qos. Logback. Core. ConsoleAppender" > < encoder charset="UTF-8"> <! Encoder can specify character set, ${CONSOLE_LOG_PATTERN}</pattern> </encoder> </appender> <root level="INFO"> <appender-ref ref="STDOUT"/> </root> </springProfile> <! <springProfile name="test"> <appender name="LOGSTASH" Class = "net. Logstash, logback appender. LogstashTcpSocketAppender" > < destination > 192.168.56.101:5044 < / destination > < encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder"/> </appender> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder charset="UTF-8"> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceLogId}] %-5level %logger{50} - %msg%n</pattern> </encoder> </appender> <appender name="ROLLING_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>./logs/${project.artifactId}/info.log</File> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <! /logs/${project.artifactid}/info.%d{YYYY-MM-dd}. Log </FileNamePattern> <! -- Log file retention days --> <maxHistory>7</maxHistory> <totalSizeCap>1GB</totalSizeCap> </rollingPolicy> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceLogId}] %-5level %logger{50} - %msg%n</pattern> </encoder> </appender> <root level="INFO"> <appender-ref ref="LOGSTASH"/> <appender-ref ref="STDOUT"/> <appender-ref ref="ROLLING_FILE"/> </root> </springProfile> <! <springProfile name="prod"> <appender name="LOGSTASH" Class = "net. Logstash, logback appender. LogstashTcpSocketAppender" > < destination > 192.168.56.101:5044 < / destination > < encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder"/> </appender> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder charset="UTF-8"> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceLogId}] %-5level %logger{50} - %msg%n</pattern> </encoder> </appender> <appender name="ROLLING_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>./logs/${project.artifactId}/info.log</File> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <! /logs/${project.artifactid}/info.%d{YYYY-MM-dd}. Log </FileNamePattern> <! -- Log file retention days --> <maxHistory>7</maxHistory> <totalSizeCap>1GB</totalSizeCap> </rollingPolicy> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{traceLogId}] %-5level %logger{50} - %msg%n</pattern> </encoder> </appender> <root level="INFO"> <appender-ref ref="LOGSTASH"/> <appender-ref ref="STDOUT"/> <appender-ref ref="ROLLING_FILE"/> </root> </springProfile> </configuration>Copy the code
Start springboot project browser enter http://192.168.56.101:5601/ observation log output