如何配置 tomcat.conf 文件

如何配置 tomcat.conf 文件

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.输出:

/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

服务器.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]

答案1

作为解决方法,您可以尝试在 /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/共享/java/tomcatCATALINA_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

相关内容