RedHat 5.2 安装jdk 6和tomcat 7(3)

自动启动tomcat
第一种方法
添加/usr/local/tomcat/bin/startup.sh到/etc/rc.d/rc.local
[root@javasrv ~]# echo "/usr/local/tomcat/bin/startup.sh" >>/etc/rc.d/rc.local

第二种方法
使用Tomcat5.sh
生成jsvc
[root@javasrv tomcat]# cd /usr/local/tomcat/output/build/bin
[root@javasrv bin]# tar zxvf commons-daemon-native.tar.gz
[root@javasrv bin]# cd commons-daemon-1.0.3-native-src/
[root@javasrv commons-daemon-1.0.3-native-src]# cd unix/
[root@javasrv unix]# ./configure && make
[root@javasrv unix]# cp jsvc ../..
[root@javasrv unix]# cd ../..
[root@javasrv bin]# pwd
/usr/local/tomcat/output/build/bin
[root@javasrv bin]# cp ./commons-daemon-1.0.3-native-src/unix/native/Tomcat5.sh /etc/init.d/tomcat
[root@javasrv bin]# cd /etc/init.d
[root@javasrv init.d]# vi tomcat

image

如需使用debug、verbose,这两个开关放在紧随jsvc命令之后
增加如下两行
# chkconfig: 345 88 14 
# description: Tomcat Daemon
修改第35行
JAVA_HOME=/usr/java/default
CATALINA_HOME=/usr/local/tomcat
DAEMON_HOME=/usr/local/tomcat/bin
TOMCAT_USER=root
修改第43行
CATALINA_BASE=/usr/local/tomcat
第46-50行
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar:\
$CATALINA_HOME/bin/tomcat-juli.jar
$CATALINA_HOME/bin/tomcat-juli.jar //此处是重要之处,故障查找比较隐蔽,原文件少这一句,导致服务启动失败。
第57行修改
$DAEMON_HOME/jsvc \
第82行修改
$DAEMON_HOME/jsvc \
如果为了排错,可打开debug开关

tomcat文件修改完成之后,调整tomcat目录的符号链接
[root@javasrv local]# rm -rf tomcat
[root@javasrv local]# ln -s /usr/local/apache-tomcat-7.0.4-src/output/build/ tomcat
将tomcat加入到服务
[root@javasrv local]# chkconfig --add tomcat
[root@javasrv local]# chkconfig --list|grep tomcat
tomcat          0:off   1:off   2:off   3:on    4:on    5:on    6:off
tomcat的启动和关闭
[root@javasrv bin]# ./startup.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/default
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@javasrv bin]# tail ../logs/catalina.out
Jul 4, 2011 1:41:41 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
Jul 4, 2011 1:41:41 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
Jul 4, 2011 1:41:41 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jul 4, 2011 1:41:41 AM org.apache.coyote.ajp.AjpProtocol start
INFO: Starting Coyote AJP/1.3 on ajp-8009
Jul 4, 2011 1:41:41 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 467 ms
[root@javasrv bin]# ./shutdown.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/default
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@javasrv bin]# tail ../logs/catalina.out
Jul 4, 2011 1:42:38 AM org.apache.coyote.http11.AbstractHttp11Protocol pause
INFO: Pausing Coyote HTTP/1.1 on http-8080
Jul 4, 2011 1:42:39 AM org.apache.coyote.ajp.AbstractAjpProtocol pause
INFO: Pausing Coyote AJP/1.3 on ajp-8009
Jul 4, 2011 1:42:39 AM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Jul 4, 2011 1:42:39 AM org.apache.coyote.http11.AbstractHttp11Protocol stop
INFO: Stopping Coyote HTTP/1.1 on http-8080
Jul 4, 2011 1:42:39 AM org.apache.coyote.ajp.AbstractAjpProtocol stop
INFO: Stopping Coyote AJP/1.3 on ajp-8009

[root@javasrv logs]# service tomcat start
[root@javasrv bin]# tail ../logs/catalina.out

附:无tomcat-juli.jar启动时的出错信息
07/11/2010 13:03:29 5711 jsvc.exec debug: redirecting stdout to /usr/local/tomcat/logs/catalina.out and stderr to &1
07/11/2010 13:03:29 5708 jsvc.exec debug: wait_child 5711
more /usr/local/tomcat/logs/catalina.out
07/11/2010 13:03:30 5712 jsvc.exec debug: Daemon loading...
java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
        at org.apache.catalina.startup.Bootstrap.<clinit>(Bootstrap.java:56)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at java.lang.Class.newInstance0(Class.java:355)
        at java.lang.Class.newInstance(Class.java:308)
        at org.apache.commons.daemon.support.DaemonLoader.load(DaemonLoader.java:147)
Caused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        ... 8 more
07/11/2010 13:03:30 5712 jsvc.exec error: Cannot load daemon
07/11/2010 13:03:30 5712 jsvc.exec debug: java_load failed
07/11/2010 13:03:30 5711 jsvc.exec error: Service exit with a return value of 3

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wywyfw.html