環境:
centos 6.4
tomcat 6 :我的安裝目錄在:/home/tomcat/apache-tomcat-6.0.41
開始:(注:也可以單獨下載jsvc.tar.gz)
1、在/home/tomcat/apache-tomcat-6.0.41/bin中有commons-daemon-native.tar.gz 壓縮包
2、解壓commons-daemon-native.tar.gz
# tar -zxvf commons-daemon-native.tar.gz
3、解壓完成,出現commons-daemon-1.0.2-native-src文件夾(目錄)
1、 進入commons-daemon-1.0.2-native-src 下的unix目錄
2、 執行configure 文件(如果沒有執行權限則加之:chmod +x ./configure)
# ./configure
5、 編譯
# make
6、 編譯完成後出現jsvc文件夾,復制jsvc到/usr/share/tomcat6/bin目錄下面
# cp jsvc /home/tomcat/apache-tomcat-6.0.41/bin
------------------------------------------------------------------------------------
7、在/etc/init.d/目錄下編寫tomcat啟動服務配置文件,配置文件的名稱即為服務名,這裡是tomcat。
#cd /etc/init.d/
# vi tomcat
錄入以下內容,並修改兩個地方,下面已經注明了
#!/bin/sh # tomcat: Start/Stop/Restart tomcat # # chkconfig: 2345 85 15 # description: Apache tomcat6 # 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: # # <!-- Define a non-SSL HTTP/1.1 Connector on port 80 --> # <Connector className="org.apache.catalina.connector.http.HttpConnector" # port="80" minProcessors="5" maxProcessors="75" # enableLookups="true" redirectPort="8443" # acceptCount="10" debug="0" connectionTimeout="60000"/> ## 根據自己情況 修改下面的JDK path和tomcat安裝的path JAVA_HOME=/usr/java/jdk1.7.0_67CATALINA_HOME=/home/tomcat/apache-tomcat-6.0.41 DAEMON_HOME=$CATALINA_HOME/bin # I did not use the user. #TOMCAT_USER=tomcat # for multi instances adapt those lines. TMP_DIR=$CATALINA_HOME/tmp PID_FILE=/var/run/jsvc.pid CATALINA_BASE=$CATALINA_HOME . /etc/rc.d/init.d/functions CATALINA_OPTS= CLASSPATH=\ $JAVA_HOME/lib/tools.jar:\ $CATALINA_HOME/bin/commons-daemon.jar:\ $CATALINA_HOME/bin/bootstrap.jar start() { echo -n $"Starting Tomcat6: " # If you want to specify a user to run Tomcat. #increase the 'user $ TOMCAT_USER \' to the parameter list. $DAEMON_HOME/jsvc \ -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 echo"*****************************[ok]" } stop() { echo -n $"Stopping Tomcat6: " # $DAEMON_HOME/jsvc \ -stop \ -pidfile $PID_FILE \ org.apache.catalina.startup.Bootstrap echo "*****************************[ok]" } status() { ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap" | awk '{printf $1 " "}' | wc | awk '{print $2}' >/tmp/tomcat_process_count.txt read line < /tmp/tomcat_process_count.txt if [ $line -gt 0 ]; then echo -n "tomcat6 ( pid " ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap" | awk '{printf $1 " "}' echo ") is running " else echo "Tomcat6 is stopped" fi } case "$1" in start) # Start Tomcat start exit $? ;; stop) # Stop Tomcat stop exit $? ;; restart) # Restart Tomcat stop sleep 3 start exit $? ;; status) status exit $? ;; *) echo "Usage: tomcat6 {start|stop|restart|status}" exit 1;; esac#########8、錄入完成,保存退出,並賦予執行權限。
9、#chkconfig --add tomcat ##添加tomcat服務
10、#chkconfig –list |grep tomcat ##查看tomcat服務是否被添加
11、# service tomcat start ##啟動tomcat服務
12、# service tomcat stop ##停止tomcat服務
13、# service tomcat restart ##重啟tomcat
14、# service tomcat status ##查看tomcat服務啟動狀態