如何在tomcat下应用部署日志_Docker容器、Tomcat应用日志时间不一致如何解决

一、问题情况如下:容器日志显示时间,差了8个小时

  • 错误时间
c4acdebba22a4b07c5f9789c4c78f80d.png
  • 正确时间
e394e531dff6d827107445d7159f4577.png

二、解决方法:

  • 1.解决docker容器与宿主机时间不一致问题:在启动容器时,把系统时间挂载到容器内,添加如下参数 -v /etc/localtime:/etc/localtime:ro //ro表示只读
  • 2.解决docker 容器与tomcat 应用打印日志时间不一致问题:在tomcat/bin/catalina.sh文件中修改tomcat JAVA_OPTS,添加如下内容
JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF8 -Duser.timezone=GMT+08

将配置文件,加载至容器

 - './config/catalina.sh:/usr/local/tomcat/bin/catalina.sh'
7ed17484436417cbb0d6efa295f5da09.png

执行命令:重新加载卷

60e12061a78aa827db018e454a1c79da.png

登录容器查看日志信息:

docker exec -it 2cbce5974658 /bin/bash # 登录容器root@2cbce5974658:/usr/local/tomcat# dateWed Aug 21 15:35:38 CST 2019root@2cbce5974658:/usr/local/tomcat# tail -f logs/catalina.2019-08-21.log Aug 21, 2019 3:35:19 PM org.apache.catalina.startup.TldConfig executeINFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.Aug 21, 2019 3:35:32 PM org.artofsolving.jodconverter.office.ProcessPoolOfficeManager INFO: ProcessManager implementation is LinuxProcessManagerAug 21, 2019 3:35:32 PM org.artofsolving.jodconverter.office.OfficeProcess prepareInstanceProfileDirWARNING: profile dir '/usr/local/tomcat/temp/.jodconverter_socket_host-127.0.0.1_port-8100' already exists; deletingAug 21, 2019 3:35:32 PM org.artofsolving.jodconverter.office.OfficeProcess startINFO: starting process with acceptString 'socket,host=127.0.0.1,port=8100,tcpNoDelay=1' and profileDir '/usr/local/tomcat/temp/.jodconverter_socket_host-127.0.0.1_port-8100'Aug 21, 2019 3:35:32 PM org.artofsolving.jodconverter.office.OfficeProcess startINFO: started process; pid = 81tail: unrecognized file system type 0x794c7630 for ‘logs/catalina.2019-08-21.log’. please report this to bug-coreutils@gnu.org. reverting to polling​
a1e053e483f69ff011d4b83ec2fb34cd.png

总结:

  • 1.docker容器和系统时间不一致是因为docker容器的原生时区为0时区,而国内系统为东八区
  • 2.容器中运行的tomcat应用打出的日志时间和通过date -R方式获取的容器标准时间有八个小时时间差。也就是容器时间和系统时间一致,但是部署的应用和容器时间不一致。
7c8f24a897d9356a8fc8660deb775923.png

如果要想要私下交流,可以添加私人QQ:2365823908 ~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值