linux中通過jsvc自動啟動tomcat並且加載到服務中

來源:互聯網
上載者:User

關鍵字: linux jsvc tomcat 服務

一直在找讓tomcat並且加載到 linux服務中的方法,有的使用wrapper,我暫時還沒找到這種安裝的方法。看tomcat DOC文檔發現JSVC可以做到,即刻實踐,下面給自己做一下總結——

 

1、JDK和Tomcat的安裝這裡就略過了

 

 

 

2、建立使用者:

 

#groupadd tomcat

#useradd -s /sbin/nologin -g tomcat tomcat

 

 

 

3.修改目錄所有者:

#chown -R tomcat:tomcat /usr/local/tomcat5.5

 

 

 

4、安裝jsvc

#cd /usr/local/tomcat/bin

#tar xvfz jsvc.tar.gz

#cd jsvc-src

#sh support/buildconf.sh

#chmod 755 configure

#./configure --with-java=/usr/local/java      (改成你的JDK的位置)

#make

 

註:我在執行./configure --with-java=/usr/local/java 的過程中,產生"configure: error:no acceptable C compiler found in $PATH "這樣的錯誤提示,發現是沒有安裝C編譯器,於是執行“yum install gcc”安裝了gcc,之後重新執行./configure --with-java=/usr/local/java 就Ok了

 

 

 

5、修改開機檔案

#vi ./native/Tomcat5.sh

改成如下內容:

 

#

# chkconfig: 345 87 13

# description: Tomcat Daemon

# processname: jsvc

# pidfile: /var/run/jsvc.pid

# config:

#

# Source function library.

# . /etc/rc.d/init.d/functions

#

# prog=tomcat

#

# Small shell script to show how to start/stop Tomcat using jsvc

# If you want to have Tomcat running on port 80 please modify the server.xml

# file:

#

#

#

# port="80" minProcessors="5" maxProcessors="75"

# enableLookups="true" redirectPort="8443"

# acceptCount="10" debug="0" connectionTimeout="60000"/>

#

# You need a developement version of Tomcat (Apache Tomcat/4.1-dev)

#

# Adapt the following lines to your configuration

 

#!/bin/sh

##############################################################################

#

# Copyright 2004 The Apache Software Foundation.

#

# Licensed under the Apache License, Version 2.0 (the "License");

# you may not use this file except in compliance with the License.

# You may obtain a copy of the License at

#

# http://www.apache.org/licenses/LICENSE-2.0

#

# Unless required by applicable law or agreed to in writing, software

# distributed under the License is distributed on an "AS IS" BASIS,

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

# See the License for the specific language governing permissions and

# limitations under the License.

##############################################################################

#

# Small shell script to show how to start/stop Tomcat using jsvc

# If you want to have Tomcat running on port 80 please modify the server.xml

# file:

#

#

#

# port="80" minProcessors="5" maxProcessors="75"

# enableLookups="true" redirectPort="8443"

# acceptCount="10" debug="0" connectionTimeout="60000"/>

#

# That is for Tomcat-5.0.x (Apache Tomcat/5.0)

#

# Adapt the following lines to your configuration

JAVA_HOME=/usr/java/jdk1.5.0.12

CATALINA_HOME=/usr/local/tomcat5.5

DAEMON_HOME=/usr/local/tomcat5.5/bin

TOMCAT_USER=tomcat

 

# for multi instances adapt those lines.

TMP_DIR=/var/tmp

PID_FILE=/var/run/jsvc.pid

CATALINA_BASE=/usr/local/tomcat5.5

 

CATALINA_OPTS=

CLASSPATH=/

$JAVA_HOME/lib/tools.jar:/

$CATALINA_HOME/bin/commons-daemon.jar:/

$CATALINA_HOME/bin/bootstrap.jar

 

case "$1" in

start)

#

# Start Tomcat

#

$DAEMON_HOME/src/jsvc /

-user $TOMCAT_USER /

-home $JAVA_HOME /

-Dcatalina.home=$CATALINA_HOME /

-Dcatalina.base=$CATALINA_BASE /

-Djava.io.tmpdir=$TMP_DIR /

-wait 10 /

-pidfile $PID_FILE /

-outfile $CATALINA_HOME/logs/catalina.out /

-errfile '&1' /

$CATALINA_OPTS /

-cp $CLASSPATH /

org.apache.catalina.startup.Bootstrap

#

# To get a verbose JVM

#-verbose /

# To get a debug of jsvc.

#-debug /

exit $?

;;

 

stop)

#

# Stop Tomcat

#

$DAEMON_HOME/src/jsvc /

-stop /

-pidfile $PID_FILE /

org.apache.catalina.startup.Bootstrap

exit $?

;;

 

*)

echo "Usage: $0 start/stop"

exit 1;;

esac

 

 

 

 

 

6、拷貝開機檔案

#cp ./native/Tomcat5.sh /etc/init.d/tomcat5

#chmod -c 777 /etc/init.d/tomcat5

 

7.添加服務

#chkconfig --add tomcat5

#chkconfig --level 345 tomcat5 on

 

8.完成,啟動服務

#service tomcat5 start

這時重啟系統,tomcat也就會自動啟動了.

 

 

 

 

 

注意事項——

1.開機檔案Tomcat5.sh檔案中的路徑一定要正確,且檔案前的注釋不能刪除,否則不能添加服務.

2.tomcat的安裝目錄的所有者一定要修改(#chown -R tomcat:tomcat /usr/java/tomcat5.5)

否則會出( Java HotSpot(TM) Client VM warning: Can't detect initial thread stack location - find_vma failed)錯誤資訊.

 zz:http://wenson.javaeye.com/blog/153771

 

在按照例文進行實裝時,修改後相應的檔案路徑,在執行#chkconfig --add tomcat5命令時,卻顯示tomcat不支援chkconfig,不知道原因是什麼,我用的tomcat和jdk分別是6.0和1.6的!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.