您好,登錄后才能下訂單哦!
在容器啟動時,tomcat的輸出日志信息如下;
docker logs 5ddb9eeb4815
Using CATALINA_BASE:?? /opt/tomcat-8.5.11
Using CATALINA_HOME:?? /opt/tomcat-8.5.11
Using CATALINA_TMPDIR: /opt/tomcat-8.5.11/temp
Using JRE_HOME:??????? /opt/jdk1.8.0_73
Using CLASSPATH:?????? /opt/tomcat-8.5.11/bin/bootstrap.jar:/opt/tomcat-8.5.11/bin/tomcat-juli.jar
Tomcat started.
22-Jul-2019 06:12:52.297 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:??????? Apache Tomcat/8.5.11
22-Jul-2019 06:12:52.299 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:????????? Jan 10 2017 21:02:52 UTC
22-Jul-2019 06:12:52.299 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:???????? 8.5.11.0
22-Jul-2019 06:12:52.299 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:?????????????? Linux
22-Jul-2019 06:12:52.299 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:??????????? 3.10.0-514.el7.x86_64
22-Jul-2019 06:12:52.299 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:????????? amd64
22-Jul-2019 06:12:52.299 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:???????????? /opt/jdk1.8.0_73/jre
22-Jul-2019 06:12:52.299 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:?????????? 1.8.0_73-b02
22-Jul-2019 06:12:52.299 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:??????????? Oracle Corporation
22-Jul-2019 06:12:52.299 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:???????? /opt/tomcat-8.5.11
22-Jul-2019 06:12:52.299 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:???????? /opt/tomcat-8.5.11
22-Jul-2019 06:12:52.299 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/opt/tomcat-8.5.11/conf/logging.properties
22-Jul-2019 06:12:52.299 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
22-Jul-2019 06:12:52.300 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
22-Jul-2019 06:12:52.300 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
22-Jul-2019 06:12:52.300 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/opt/tomcat-8.5.11
22-Jul-2019 06:12:52.300 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/opt/tomcat-8.5.11
22-Jul-2019 06:12:52.300 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/opt/tomcat-8.5.11/temp
22-Jul-2019 06:12:52.300 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
22-Jul-2019 06:12:52.566 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
22-Jul-2019 06:12:52.593 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
22-Jul-2019 06:12:52.606 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
22-Jul-2019 06:12:52.607 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
22-Jul-2019 06:12:52.611 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1015 ms
22-Jul-2019 06:12:52.663 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
22-Jul-2019 06:12:52.664 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.11
22-Jul-2019 06:12:52.682 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /opt/tomcat-8.5.11/webapps/ROOT
22-Jul-2019 06:13:09.698 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [16,530] milliseconds.
22-Jul-2019 06:13:09.795 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /opt/tomcat-8.5.11/webapps/ROOT has finished in 17,113 ms
22-Jul-2019 06:13:09.795 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /opt/tomcat-8.5.11/webapps/docs
22-Jul-2019 06:13:09.891 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /opt/tomcat-8.5.11/webapps/docs has finished in 96 ms
22-Jul-2019 06:13:09.891 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /opt/tomcat-8.5.11/webapps/examples
22-Jul-2019 06:13:10.384 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /opt/tomcat-8.5.11/webapps/examples has finished in 493 ms
22-Jul-2019 06:13:10.385 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /opt/tomcat-8.5.11/webapps/host-manager
22-Jul-2019 06:13:10.429 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /opt/tomcat-8.5.11/webapps/host-manager has finished in 43 ms
22-Jul-2019 06:13:10.429 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /opt/tomcat-8.5.11/webapps/manager
22-Jul-2019 06:13:10.470 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /opt/tomcat-8.5.11/webapps/manager has finished in 41 ms
22-Jul-2019 06:13:10.487 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [http-nio-8080]
22-Jul-2019 06:13:10.494 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [ajp-nio-8009]
22-Jul-2019 06:13:10.495 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 17883 ms
22-Jul-2019 06:15:15.904 INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance.
22-Jul-2019 06:15:15.905 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8080"]
22-Jul-2019 06:15:15.957 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8009"]
22-Jul-2019 06:15:16.008 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service Catalina
22-Jul-2019 06:15:16.055 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
22-Jul-2019 06:15:16.056 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]
22-Jul-2019 06:15:16.056 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
22-Jul-2019 06:15:16.060 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]
進入容器內(nèi)部查看其時間
本地的CST時區(qū),說明Docker與操作系統(tǒng)使用的是同一個時區(qū)
?說明: ?????
????? (1) UTC
整個地球分為二十四時區(qū),每個時區(qū)都有自己的本地時間。在國際無線電通信場合,為了統(tǒng)一起見,使用一個統(tǒng)一的時間,稱為通用協(xié)調(diào)時(UTC, Universal Time Coordinated)。
(2) GMT
格林威治標準時間 (Greenwich Mean Time)指位于英國倫敦郊區(qū)的×××格林尼治天文臺的標準時間,因為本初子午線被定義在通過那里的經(jīng)線。(UTC與GMT時間基本相同,本文中不做區(qū)分)
(3) CST
中國標準時間 (China Standard Time)
代碼如下:
GMT + 8 = UTC + 8 = CST
(4) DST
夏令時(Daylight Saving Time) 指在夏天太陽升起的比較早時,將時鐘撥快一小時,以提早日光的使用。(中國不使用)
是因為Tomcat啟動時,使用了JVM啟動時的默認時區(qū)所致,難道JVM啟動不是使用系統(tǒng)提供的默認時區(qū)嗎?答案:不是的,默認是UTC時區(qū)
基于這種現(xiàn)象,本人在容器中寫了測試的代碼:
public?class?Test{ ???public?static?void?main(String[]?args){ ??????System.out.println(new?java.util.Date()); ??????System.out.println(System.getProperty("user.timezone")); ???} }
進行編譯,然后運行
javac?-g?Test.java #?java?Test
看如下截圖:
正好相差8個小時
找到原因其實就好解決了
一是修改JVM啟動提供的默認時區(qū),二是修改Tomcat啟動腳本
我這里選擇修改Tomcat啟動腳本的參數(shù)
在$Tomcat_HOME/bin/catalina.sh 中添加如下:
export?JAVA_OPTS="$JAVA_OPTS?-server?-Dfile.encoding=UTF-8?-Duser.timezone=GMT+08"
最后啟動Tomcat,正常,見如下:
方法二:
使用tzselect進行進行修改
# tzselect
?1) Africa
?2) Americas
?3) Antarctica
?4) Arctic Ocean
?5) Asia
?6) Atlantic Ocean
?7) Australia
?8) Europe
?9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
選擇5
Please select a country.
?1) Afghanistan?????????? 18) Israel??????????????? 35) Palestine
?2) Armenia?????????????? 19) Japan???????????????? 36) Philippines
?3) Azerbaijan??????????? 20) Jordan??????????????? 37) Qatar
?4) Bahrain?????????????? 21) Kazakhstan??????????? 38) Russia
?5) Bangladesh??????????? 22) Korea (North)???????? 39) Saudi Arabia
?6) Bhutan??????????????? 23) Korea (South)???????? 40) Singapore
?7) Brunei??????????????? 24) Kuwait??????????????? 41) Sri Lanka
?8) Cambodia????????????? 25) Kyrgyzstan??????????? 42) Syria
?9) China???????????????? 26) Laos????????????????? 43) Taiwan
10) Cyprus??????????????? 27) Lebanon?????????????? 44) Tajikistan
11) East Timor??????????? 28) Macau???????????????? 45) Thailand
12) Georgia?????????????? 29) Malaysia????????????? 46) Turkmenistan
13) Hong Kong???????????? 30) Mongolia????????????? 47) United Arab Emirates
14) India???????????????? 31) Myanmar (Burma)?????? 48) Uzbekistan
15) Indonesia???????????? 32) Nepal???????????????? 49) Vietnam
16) Iran????????????????? 33) Oman????????????????? 50) Yemen
17) Iraq????????????????? 34) Pakistan
選擇9
Please select one of the following time zone regions.
1) Beijing Time
2) Xinjiang Time
選擇1
The following information has been given:
??????? China
??????? Beijing Time
Therefore TZ='Asia/Shanghai' will be used.
Local time is now:????? Mon Jul 22 15:55:01 CST 2019.
Universal Time is now:? Mon Jul 22 07:55:01 UTC 2019.
Is the above information OK?
1) Yes
2) No
選擇1
# cp /etc/timezone /etc/timezone.bak
cat > /etc/timezone << EOF
Asia/Shanghai
EOF
將之前的catalina.sh腳本注釋掉,最后啟動Tomcat,時區(qū)也是正常的
見下圖:
最后,可以將這些配置好的信息,重新打包成新鏡像,然后發(fā)布到repos中
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。