Docker镜像体积变大问题

Blade 未结 1 676
ccc
ccc 剑圣 2021-11-23 17:18

https://sns.bladex.cn/q-6815.html

还是这个修改日志输出的问题。


回复是这样的

docker本身的日志过大,应该和logback关系不大,具体看下上面的帖子试试

这个答案可能并不是我们服务的实际情况。


现在系统中每分钟都调用一次,deploy.sh里面的rmLogs的方法,这个方法可以清理Docker的日志。

使用docker system df -v命令可以看到容器的体积很大。截图中的500m的体积,是清理半小时后的大小。

图片.png

使用docker exec -it /bin/shi查看文件,可以看到镜像内的info*.log文件非常大。这个路径和logback里面配置的日志输出路径是一样的。这个日志文件应该怎么清理或者不输出呢?

图片.png


1条回答
  • 2021-11-24 20:34

    这回描述相对清晰,的确是log本身的问题,应该是你们打的log较多,访问量大,所以日志堆积的就多了。你可以参考dev的log配置方式,这种情况只会在控制台打印,并不会生成实际的log文件,具体看下面的配置。

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration scan="true" scanPeriod="60 seconds">
        <!-- 自定义参数监听 -->
        <contextListener class="org.springblade.core.log.listener.LoggerStartupListener"/>
        <springProperty scope="context" name="springAppName" source="spring.application.name"/>
    
        <!-- 彩色日志依赖的渲染类 -->
        <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}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
        <!-- 控制台输出 -->
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
                <pattern>${CONSOLE_LOG_PATTERN}</pattern>
                <charset>utf8</charset>
            </encoder>
        </appender>
    
        <if condition='property("ELK_MODE").toUpperCase().contains("TRUE")'>
            <then>
                <!-- 推送日志至elk -->
                <appender name="STDOUT_LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
                    <destination>${DESTINATION}</destination>
                    <!-- 日志输出编码 -->
                    <encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
                        <providers>
                            <timestamp>
                                <timeZone>UTC</timeZone>
                            </timestamp>
                            <pattern>
                                <pattern>
                                    {
                                    "traceId": "%X{traceId}",
                                    "requestId": "%X{requestId}",
                                    "accountId": "%X{accountId}",
                                    "tenantId": "%X{tenantId}",
                                    "logLevel": "%level",
                                    "serviceName": "${springAppName:-SpringApp}",
                                    "pid": "${PID:-}",
                                    "thread": "%thread",
                                    "class": "%logger{40}",
                                    "line":"%L",
                                    "message": "%message"
                                    }
                                </pattern>
                            </pattern>
                            <mdc/>
                            <stackTrace/>
                        </providers>
                    </encoder>
                </appender>
            </then>
        </if>
    
        <!-- 日志输出级别 -->
        <root level="INFO">
            <appender-ref ref="STDOUT"/>
            <appender-ref ref="${STDOUT_APPENDER}"/>
        </root>
    
        <logger name="net.sf.ehcache" level="INFO"/>
        <logger name="druid.sql" level="INFO"/>
    
    
        <!-- MyBatis log configure -->
        <logger name="com.apache.ibatis" level="INFO"/>
        <logger name="org.mybatis.spring" level="INFO"/>
        <logger name="java.sql.Connection" level="INFO"/>
        <logger name="java.sql.Statement" level="INFO"/>
        <logger name="java.sql.PreparedStatement" level="INFO"/>
    
        <!-- 减少部分debug日志 -->
        <logger name="druid.sql" level="INFO"/>
        <logger name="org.apache.shiro" level="INFO"/>
        <logger name="org.mybatis.spring" level="INFO"/>
        <logger name="org.springframework" level="INFO"/>
        <logger name="org.springframework.context" level="WARN"/>
        <logger name="org.springframework.beans" level="WARN"/>
        <logger name="com.baomidou.mybatisplus" level="INFO"/>
        <logger name="org.apache.ibatis.io" level="INFO"/>
        <logger name="org.apache.velocity" level="INFO"/>
        <logger name="org.eclipse.jetty" level="INFO"/>
        <logger name="io.undertow" level="INFO"/>
        <logger name="org.xnio.nio" level="INFO"/>
        <logger name="org.thymeleaf" level="INFO"/>
        <logger name="springfox.documentation" level="INFO"/>
        <logger name="org.hibernate.validator" level="INFO"/>
        <logger name="com.netflix.loadbalancer" level="INFO"/>
        <logger name="com.netflix.hystrix" level="INFO"/>
        <logger name="com.netflix.zuul" level="INFO"/>
        <logger name="de.codecentric" level="INFO"/>
        <!-- cache INFO -->
        <logger name="net.sf.ehcache" level="INFO"/>
        <logger name="org.springframework.cache" level="INFO"/>
        <!-- cloud -->
        <logger name="org.apache.http" level="INFO"/>
        <logger name="com.netflix.discovery" level="INFO"/>
        <logger name="com.netflix.eureka" level="INFO"/>
        <!-- 业务日志 -->
        <Logger name="org.springblade" level="INFO"/>
        <Logger name="org.springblade.core.tenant" level="INFO"/>
        <Logger name="org.springblade.core.version" level="INFO"/>
    
        <!-- 减少nacos日志 -->
        <logger name="com.alibaba.nacos" level="ERROR"/>
    
    
    </configuration>


    如果不需要elk日志推送,可以使用如下配置

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration scan="true" scanPeriod="60 seconds">
        <!-- 自定义参数监听 -->
        <contextListener class="org.springblade.core.log.listener.LoggerStartupListener"/>
        <springProperty scope="context" name="springAppName" source="spring.application.name"/>
    
        <!-- 彩色日志依赖的渲染类 -->
        <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}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
        <!-- 控制台输出 -->
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
                <pattern>${CONSOLE_LOG_PATTERN}</pattern>
                <charset>utf8</charset>
            </encoder>
        </appender>
    
    
        <!-- 日志输出级别 -->
        <root level="INFO">
            <appender-ref ref="STDOUT"/>
            <appender-ref ref="${STDOUT_APPENDER}"/>
        </root>
    
        <logger name="net.sf.ehcache" level="INFO"/>
        <logger name="druid.sql" level="INFO"/>
    
    
        <!-- MyBatis log configure -->
        <logger name="com.apache.ibatis" level="INFO"/>
        <logger name="org.mybatis.spring" level="INFO"/>
        <logger name="java.sql.Connection" level="INFO"/>
        <logger name="java.sql.Statement" level="INFO"/>
        <logger name="java.sql.PreparedStatement" level="INFO"/>
    
        <!-- 减少部分debug日志 -->
        <logger name="druid.sql" level="INFO"/>
        <logger name="org.apache.shiro" level="INFO"/>
        <logger name="org.mybatis.spring" level="INFO"/>
        <logger name="org.springframework" level="INFO"/>
        <logger name="org.springframework.context" level="WARN"/>
        <logger name="org.springframework.beans" level="WARN"/>
        <logger name="com.baomidou.mybatisplus" level="INFO"/>
        <logger name="org.apache.ibatis.io" level="INFO"/>
        <logger name="org.apache.velocity" level="INFO"/>
        <logger name="org.eclipse.jetty" level="INFO"/>
        <logger name="io.undertow" level="INFO"/>
        <logger name="org.xnio.nio" level="INFO"/>
        <logger name="org.thymeleaf" level="INFO"/>
        <logger name="springfox.documentation" level="INFO"/>
        <logger name="org.hibernate.validator" level="INFO"/>
        <logger name="com.netflix.loadbalancer" level="INFO"/>
        <logger name="com.netflix.hystrix" level="INFO"/>
        <logger name="com.netflix.zuul" level="INFO"/>
        <logger name="de.codecentric" level="INFO"/>
        <!-- cache INFO -->
        <logger name="net.sf.ehcache" level="INFO"/>
        <logger name="org.springframework.cache" level="INFO"/>
        <!-- cloud -->
        <logger name="org.apache.http" level="INFO"/>
        <logger name="com.netflix.discovery" level="INFO"/>
        <logger name="com.netflix.eureka" level="INFO"/>
        <!-- 业务日志 -->
        <Logger name="org.springblade" level="INFO"/>
        <Logger name="org.springblade.core.tenant" level="INFO"/>
        <Logger name="org.springblade.core.version" level="INFO"/>
    
        <!-- 减少nacos日志 -->
        <logger name="com.alibaba.nacos" level="ERROR"/>
    
    
    </configuration>


    0 讨论(0)
提交回复