网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
{
"name" : "4895e681875f",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "C8NC8FWcSkqUv9x5M5pGVQ",
"version" : {
"number" : "7.8.0",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65",
"build_date" : "2020-06-14T19:35:50.234439Z",
"build_snapshot" : false,
"lucene_version" : "8.5.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
好家伙这么多密码
查看网络 sudo docker network inspect elastic
2. 安装 kibana
宿主机创建配置文件映射到容器内
/data/kibana/kibana.yml
#
# ** THIS IS AN AUTO-GENERATED FILE **
#
# Default Kibana configuration for docker target
server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://172.18.0.2:9200" ]
monitoring.ui.container.elasticsearch.enabled: true
i18n.locale: "zh-CN"
elasticsearch.username: "elastic"
elasticsearch.password: "123456"
xpack.reporting.encryptionKey: "sdfbwe83q12gsdfgsdvfshjfvashfn34y372rh32gru32yre32erh2u3hrlibsdfjefe"
xpack.security.encryptionKey: "hsaufhsabfasbhdsbfjbsjhfbshjbfsbfcshjdbf623423gjh234v32hv4h32h3vrhj"
- 修改elasticsearch.hosts 根据你的实际情况
- 使用更长的字符 > 32 『你自己随意设置哈』
- 修改 elasticsearch.password为刚才你设置的密码
启动容器
docker run -d --name kibana --net elastic -p 5601:5601 -v /data/kibana/kibana.yml:/usr/share/kibana/config/kibana.yml kibana:7.8.0
如果遇到:
FATAL Error: [config validation of [xpack.reporting].encryptionKey]: value has length [11] but it must have a minimum length of [32].
xpack.reporting.encryptionKey: 设置更长的长度, 修改完成后,重启容器
- 安装logstash
创建logstash 的配置文件
/data/logstash/conf.d
/data/logstash/config
logstash.yml配置如下:
http.host: "0.0.0.0"
xpack.monitoring.elasticsearch.hosts: [ "http://172.19.0.2:9200" ]
xpack.monitoring.enabled: true
path.config: /usr/share/logstash/conf.d/*.conf
path.logs: /var/log/logstash
其中xpack.monitoring.elasticsearch.hosts配置项改为获取到的elasticsearch容器地址, sudo docker network inspect elastic
logstash.conf的配置如下:
input {
tcp {
mode => "server"
host => "0.0.0.0"
port => 5047
codec => json_lines
}
}
output {
elasticsearch {
hosts => "172.19.0.2:9200"
index => "springboot-logstash-%{+YYYY.MM.dd}"
user => "elastic"
password => "123456"
}
}
下面host填写elastsearch容器地址,index为日志索引的名称,user和password填写xpack设置的密码,port为对外开放收集日志的端口
运行logstash
docker run -it -d -p 5047:5047 -p 9600:9600 \
--name logstash --privileged=true --net elastic -v \
/data/logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml -v \
/data/logstash/conf.d/:/usr/share/logstash/conf.d/ logstash:7.8.0
5047端口是刚才port设置的端口
- 创建springboot 工程
加入依赖
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>6.6</version>
</dependency>
logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<!-- 获取spring配置 -->
<springProperty scope="context" name="logPath" source="log.path" defaultValue="/app/log/elk-biz"/>
<springProperty scope="context" name="appName" source="spring.application.name"/>
<!-- 定义变量值的标签 -->
<property name="LOG_HOME" value="${logPath}"/>
<property name="SPRING_NAME" value="${appName}"/>
<!-- 彩色日志依赖的渲染类 -->
<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"/>
<!-- 链路追踪sleuth 格式化输出 以及 控制台颜色设置变量 -->
<property name="CONSOLE_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) [${appName},%yellow(%X{X-B3-TraceId}),%green(%X{X-B3-SpanId}),%blue(%X{X-B3-ParentSpanId})] [%yellow(%thread)] %green(%logger:%L) :%msg%n"/>
<!-- #############################################定义日志输出格式以及输出位置########################################## -->
<!--控制台输出设置-->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<!-- <charset>GBK</charset> -->
</encoder>
</appender>
<!--普通文件输出设置-->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_HOME}/log_${SPRING_NAME}_%d{yyyy-MM-dd}_%i.log</FileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>200MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!--aop接口日志拦截文件输出-->
<appender name="bizAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_HOME}/log_%d{yyyy-MM-dd}_%i.log</FileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>200MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<!--开启tcp格式的logstash传输,通过TCP协议连接Logstash-->
<!-- <appender name="STASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">-->
<!-- <destination>10.11.74.123:9600</destination>-->
<!-- <encoder class="net.logstash.logback.encoder.LogstashEncoder" />-->
<!-- </appender>-->
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<!--可以访问的logstash日志收集端口-->
<destination>localhost:5047</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder"/>
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp>
<timeZone>Asia/Shanghai</timeZone>
</timestamp>
<pattern>
<pattern>
{
"app_name":"${SPRING_NAME}",
"traceid":"%X{traceid}",
"ip": "%X{ip}",
"server_name": "%X{server_name}",
"level": "%level",
"trace": "%X{X-B3-TraceId:-}",
"span": "%X{X-B3-SpanId:-}",
"parent": "%X{X-B3-ParentSpanId:-}",
"thread": "%thread",
"class": "%logger{40} - %M:%L",
"message": "%message",
"stack_trace": "%exception{10}"
}
</pattern>
</pattern>
</providers>
</encoder>
</appender>
<!-- #############################################设置输出日志输出等级########################################## -->
<!-- mybatis log configure-->
<!-- logger设置某一个包或者具体的某一个类的日志打印级别 -->
<logger name="com.apache.ibatis" level="TRACE"/>
<logger name="java.sql.Connection" level="DEBUG"/>
<logger name="java.sql.Statement" level="DEBUG"/>
<logger name="java.sql.PreparedStatement" level="DEBUG"/>
<logger name="org.apache.ibatis.logging.stdout.StdOutImpl" level="DEBUG"/>
<!-- SaveLogAspect log configure外部接口调用-->
<!-- logger设置某一个包或者具体的某一个类的日志打印级别 -->
<logger name="com.springweb.baseweb.log.aop.SaveLogAspect" additivity="false" level="INFO">
<!-- 同时输出到两个文件 -->
<appender-ref ref="bizAppender"/>
### 最后的话
最近很多小伙伴找我要Linux学习资料,于是我翻箱倒柜,整理了一些优质资源,涵盖视频、电子书、PPT等共享给大家!
### 资料预览
给大家整理的视频资料:
![](https://img-blog.csdnimg.cn/img_convert/f7a995bf1f4c6d0435c3503b777e8c19.png)
给大家整理的电子书资料:
![](https://img-blog.csdnimg.cn/img_convert/df46f2292c75597dd82218fd7e1cb9e8.png)
**如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!**
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/topics/618542503)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
# 资料预览
给大家整理的视频资料:
[外链图片转存中...(img-9dTwJXIo-1714751324454)]
给大家整理的电子书资料:
[外链图片转存中...(img-cZPORxtC-1714751324454)]
**如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!**
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/topics/618542503)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**