Configuration

如何配置tomcat.conf文件

  • February 19, 2016

yum在我的CentOS 6.7伺服器上執行更新後,我的Tomcat7實例已停止正常執行。

更新期間的消息:

warning: /etc/tomcat/server.xml created as /etc/tomcat/server.xml.rpmnew

有兩條日誌執行後出現異常:

/etc/rc.d/init.d/tomcat restart
Stopping tomcat:                                           [FAILED]
Starting tomcat:                                           [FAILED]

catalina.out:

/usr/sbin/tomcat: line 59: -classpath: command not found

tomcat-initd.log:

/usr/sbin/tomcat: error: Failed to set JAVACMD

但是,如果我將 tomcat.conf 更新為以下內容:

# Where your tomcat installation lives
CATALINA_BASE="/usr/share/java/tomcat"
CATALINA_HOME="/usr/share/java/tomcat"
JASPER_HOME="/usr/share/java/tomcat"
CATALINA_TMPDIR="/var/cache/tomcat/temp"

其中有:

ls -all /usr/share/java/tomcat
total 19180
drwxrwxrwx.  2 tomcat root    4096 Feb 18 21:50 .
drwxr-xr-x. 10 root   root   12288 Feb 18 21:50 ..
-rw-r--r--.  1 root   root   16910 Jan  6 13:50 annotations-api.jar
-rwxr-xr-x.  1 root   root 1997327 Jul 23  2014 bcprov-jdk15on-147.jar
-rw-r--r--.  1 root   root   55617 Jan  6 13:50 catalina-ant.jar
-rw-r--r--.  1 root   root  132331 Jan  6 13:50 catalina-ha.jar
-rw-r--r--.  1 root   root 1638948 Jan  6 13:50 catalina.jar
-rw-r--r--.  1 root   root  261524 Jan  6 13:50 catalina-tribes.jar
lrwxrwxrwx.  1 root   root      47 Feb 18 21:50 commons-collections.jar -> /usr/share/java/jakarta-commons-collections.jar
-rwxr-xr-x.  1 root   root  354491 Jul 23  2014 commons-configuration-1.8.jar
-rwxr-xr-x.  1 root   root 2309495 Jul 23  2014 commons-configuration-1.8-javadoc.jar
lrwxrwxrwx.  1 root   root      40 Feb 18 21:50 commons-dbcp.jar -> /usr/share/java/jakarta-commons-dbcp.jar
-rwxr-xr-x.  1 root   root  241614 Jul 23  2014 commons-digester3-3.2.jar
-rwxr-xr-x.  1 root   root  852037 Jul 23  2014 commons-digester3-3.2-javadoc.jar
-rwxr-xr-x.  1 root   root  282032 Jul 23  2014 commons-digester3-3.2-sources.jar
-rwxr-xr-x.  1 root   root  734212 Jul 23  2014 commons-digester3-3.2-with-deps.jar
-rwxr-xr-x.  1 root   root  284220 Jul 23  2014 commons-lang-2.6.jar
-rwxr-xr-x.  1 root   root 1624033 Jul 23  2014 commons-lang-2.6-javadoc.jar
-rwxr-xr-x.  1 root   root  372982 Jul 23  2014 commons-lang-2.6-sources.jar
-rwxr-xr-x.  1 root   root   60841 Jul 23  2014 commons-logging-1.1.1.jar
-rwxr-xr-x.  1 root   root  141401 Jul 23  2014 commons-logging-1.1.1-javadoc.jar
-rwxr-xr-x.  1 root   root   74976 Jul 23  2014 commons-logging-1.1.1-sources.jar
-rwxr-xr-x.  1 root   root   26520 Jul 23  2014 commons-logging-adapters-1.1.1.jar
-rwxr-xr-x.  1 root   root   52313 Jul 23  2014 commons-logging-api-1.1.1.jar
-rwxr-xr-x.  1 root   root 1749257 Jul 23  2014 ecj-3.7.2.jar
-rw-r--r--.  1 root   root 1796326 Jul 23  2014 ecj-4.2.1.jar
-rw-r--r--.  1 root   root   46085 Jul 23  2014 el-api.jar
-rwxr-xr-x.  1 root   root   21892 Jul 23  2014 fluent-hc-4.2.2.jar
-rwxr-xr-x.  1 root   root  428353 Jul 23  2014 httpclient-4.2.2.jar
-rwxr-xr-x.  1 root   root  115269 Jul 23  2014 httpclient-cache-4.2.2.jar
-rwxr-xr-x.  1 root   root  223571 Jul 23  2014 httpcore-4.2.2.jar
-rwxr-xr-x.  1 root   root   26594 Jul 23  2014 httpmime-4.2.2.jar
-rw-r--r--.  1 root   root  125279 Jan  6 13:50 jasper-el.jar
-rw-r--r--.  1 root   root  600391 Jan  6 13:50 jasper.jar
lrwxrwxrwx.  1 root   root      23 Feb 18 21:50 jasper-jdt.jar -> /usr/share/java/ecj.jar
-rw-r-----.  1 root   root  578790 Jun 18  2015 javax.mail.jar
-rw-r-----.  1 root   root   23737 Jun  9  2015 json-simple-1.1.1.jar
-rw-r--r--.  1 root   root   88691 Jul 23  2014 jsp-api.jar
-rwxr-xr-x.  1 root   root   43858 Jul 23  2014 kxml2-2.3.0.jar
lrwxrwxrwx.  1 root   root      25 Feb 18 21:50 log4j.jar -> /usr/share/java/log4j.jar
-rw-r--r--.  1 root   root  177568 Jul 23  2014 servlet-api.jar
-rw-r--r--.  1 root   root  586192 Jul 21  2015 sqljdbc41.jar
-rw-r--r--.  1 root   root  212895 Jan  6 13:50 tomcat7-websocket.jar
-rw-r--r--.  1 root   root    6918 Jan  6 13:50 tomcat-api.jar
-rw-r--r--.  1 root   root  793503 Jan  6 13:50 tomcat-coyote.jar
lrwxrwxrwx.  1 root   root      24 Feb 18 21:50 tomcat-el-2.2-api.jar -> ../tomcat-el-2.2-api.jar
-rw-r--r--.  1 root   root   77568 Jan  6 13:50 tomcat-i18n-es.jar
-rw-r--r--.  1 root   root   48323 Jan  6 13:50 tomcat-i18n-fr.jar
-rw-r--r--.  1 root   root   50982 Jan  6 13:50 tomcat-i18n-ja.jar
-rw-r--r--.  1 root   root  126977 Jan  6 13:50 tomcat-jdbc.jar
lrwxrwxrwx.  1 root   root      25 Feb 18 21:50 tomcat-jsp-2.2-api.jar -> ../tomcat-jsp-2.2-api.jar
lrwxrwxrwx.  1 root   root      37 Feb 18 21:50 tomcat-juli.jar -> /usr/share/tomcat/bin/tomcat-juli.jar
lrwxrwxrwx.  1 root   root      29 Feb 18 21:50 tomcat-servlet-3.0-api.jar -> ../tomcat-servlet-3.0-api.jar
-rw-r--r--.  1 root   root   33065 Jan  6 13:50 tomcat-util.jar
-rw-r--r--.  1 root   root   36558 Jan  6 13:50 websocket-api.jar

但隨後執行:

/etc/rc.d/init.d/tomcat restart

拋出以下異常:

Stopping tomcat: /etc/rc.d/init.d/tomcat: line 209: /usr/share/java/tomcat/logs/tomcat-initd.log: No such file or directory
                                                          [FAILED]
Starting tomcat:                                           [FAILED]

第 209 行/etc/init.d/tomcat

[ "$RETVAL" -eq "0" ] && $SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} stop" >> ${TOMCAT_LOG} 2>&1 || RETVAL="4"

這些設置應該在 tomcat.conf 中是什麼? 我無法弄清楚這一點。

編輯

根據 ALex_hha 的建議,遇到以下情況:

/etc/rc.d/init.d/tomcat restart
Stopping tomcat:                                           [  OK  ]
Starting tomcat: sed: can't read /usr/share/java/tomcat/conf/server.xml: No such file or directory
                                                          [  OK  ]

此外:

ls -all /usr/share/tomcat
total 36
drwxrwxr-x.   3 root   tomcat 4096 Feb 19 16:23 .
drwxr-xr-x. 194 root   root   4096 Feb 19 09:30 ..
-rw-------.   1 tomcat tomcat 1503 Jul 18  2014 .bash_history
drwxr-xr-x.   2 tomcat tomcat 4096 Feb 19 16:23 bin
lrwxrwxrwx.   1 root   tomcat   11 Feb 19 16:23 conf -> /etc/tomcat
-rw-r--r--.   1 tomcat tomcat 7192 Sep  2  2014 .keystore
-rw-r--r--.   1 root   root   3967 Sep  2  2014 .keystore-20140902
-rw-r--r--.   1 tomcat tomcat 5862 Aug 20  2014 .keystore-org
lrwxrwxrwx.   1 root   tomcat   22 Feb 19 16:23 lib -> /usr/share/java/tomcat
lrwxrwxrwx.   1 root   tomcat   15 Feb 19 16:23 logs -> /var/log/tomcat
lrwxrwxrwx.   1 root   tomcat   22 Feb 19 16:23 temp -> /var/cache/tomcat/temp
lrwxrwxrwx.   1 root   tomcat   23 Feb 19 16:23 webapps -> /var/lib/tomcat/webapps
lrwxrwxrwx.   1 root   tomcat   22 Feb 19 16:23 work -> /var/cache/tomcat/work

server.xml(部分)

<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
          maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
          clientAuth="false" sslProtocol="TLS" />


<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

tomcat 執行了嗎?

sudo service tomcat status
PID file exists, but process is not running                [WARNING]
tomcat lockfile exists but process is not running          [FAILED]

作為解決方法,您可以嘗試在 /etc/rc.d/init.d/tomcat 中顯式設置日誌文件的路徑

代替

TOMCAT_LOG="${TOMCAT_LOG:-${CATALINA_HOME}/logs/${NAME}-initd.log}"

TOMCAT_LOG="/var/log/tomcat/tomcat-initd.log"

但是,如果我將 tomcat.conf 更新為以下內容:

應該

CATALINA_BASE="/usr/share/tomcat"
CATALINA_HOME="/usr/share/tomcat"
JASPER_HOME="/usr/share/tomcat"

/usr/share/java/tomcat的 CATALINA_BASE/CATALINA_HOME 路徑不正確

# ls -la /usr/share/tomcat/
total 12
drwxrwxr-x    3 root tomcat 4096 Feb 19 08:51 .
drwxr-xr-x. 115 root root   4096 Feb 19 09:00 ..
drwxr-xr-x    2 root root   4096 Feb 19 08:51 bin
lrwxrwxrwx    1 root tomcat   11 Feb 19 08:51 conf -> /etc/tomcat
lrwxrwxrwx    1 root tomcat   22 Feb 19 08:51 lib -> /usr/share/java/tomcat
lrwxrwxrwx    1 root tomcat   15 Feb 19 08:51 logs -> /var/log/tomcat
lrwxrwxrwx    1 root tomcat   22 Feb 19 08:51 temp -> /var/cache/tomcat/temp
lrwxrwxrwx    1 root tomcat   23 Feb 19 08:51 webapps -> /var/lib/tomcat/webapps
lrwxrwxrwx    1 root tomcat   22 Feb 19 08:51 work -> /var/cache/tomcat/work

引用自:https://serverfault.com/questions/758515