時(shí)間:2015/6/28來(lái)源:IT貓撲網(wǎng)作者:網(wǎng)管聯(lián)盟我要評(píng)論(0)
1.安裝jdk,在/etc/profile中配置java環(huán)境變量。
export JAVA_HOME=/usr/local/jdk1.5.0_09
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
2.安裝tomcat。將三行環(huán)境變量腳本從profile文件移到/etc/rc.d/rc.local文件末尾。因?yàn)閜rofile文件只有在用戶登錄進(jìn)來(lái)時(shí)才會(huì)執(zhí)行。而rc.local是系統(tǒng)啟動(dòng)后自動(dòng)執(zhí)行的。
在rc.local文件末尾的Java環(huán)境變量設(shè)置腳本后加入啟動(dòng)tomcat命令:
/usr/local/tomcat5.5/bin/startup.sh
linux下tomcat隨系統(tǒng)自動(dòng)啟動(dòng)腳本
# !/ bin / sh
#
# chkconfig: 345 86 14
# description: manager tomcat
#
# filename: / etc / rc.d / init.d / tomcat5
#
javaDir = `ls / usr / java`
for java in $javaDir
do
export JAVA_HOME = " /usr/java/${java} "
done
export TOMCAT_HOME = " /usr/tomcat5 "
case $ 1 in
start) $TOMCAT_HOME / bin / startup.sh
;;
stop) $TOMCAT_HOME / bin / shutdown.sh
;;
restart) $TOMCAT_HOME / bin / shutdown.sh
$TOMCAT_HOME / bin / startup.sh
;;
* ) echo " Usage: $0 {start|stop|restart} "
;;
esac
exit 0
Tomcat作為linux系統(tǒng)服務(wù)自啟動(dòng)設(shè)置
一. 簡(jiǎn)單的方法
最簡(jiǎn)單的方法就是通過(guò)Tomcat自帶的startup.sh來(lái)自動(dòng)啟動(dòng),編輯/etc/rc.d/rc.local,增加:
export JDK_HOME=/usr/local/jdk
export JAVA_HOME=/usr/local/jdk
/usr/local/tomcat/bin/startup.sh
二. 復(fù)雜而專(zhuān)業(yè)的方法
第一個(gè)方法無(wú)法指定啟動(dòng)Tomcat服務(wù)的用戶,存在安全隱患,另外在系統(tǒng)關(guān)閉時(shí)無(wú)法自動(dòng)停止服務(wù)。在Linux下,Tomcat可以作為一個(gè)守護(hù)進(jìn)程來(lái)啟動(dòng)以及停止,這個(gè)必須借助于項(xiàng)目commons-daemon中的jsvc工具。Tomcat安裝完后就帶有這個(gè)工具的源碼$CATALINA_HOME/bin/jsvc.tar.gz。首先安裝這個(gè)工具:
# tar zxvf jsvc.tar.gz
# cd jsvc-src
# chmod +x configure
# ./configure --with-java=/usr/jdk
# make
# ./jsvc -help //檢驗(yàn)
完成后是無(wú)法用chkconfig --add tomcat設(shè)置為自動(dòng)啟動(dòng),會(huì)顯示錯(cuò)誤信息:service tomcat does not support chkconfig ,需要修改腳本$CATALINA_HOME/bin/jsvc-src/native/Tomcat.sh,并cp到/etc/rc.d/init.d。我的啟動(dòng)腳本如下(中間出現(xiàn)了幾次問(wèn)題,結(jié)果發(fā)現(xiàn)都是腳本的問(wèn)題,所以一定要謹(jǐn)慎):
#!/bin/sh
#
# Startup Script for Tomcat5
#
# 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:
#
# <!-- 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"/>
#
# You need a developement version of Tomcat (Apache Tomcat/4.1-dev)
#
# Adapt the following lines to your configuration
JAVA_HOME=/usr/local/jdk
CATALINA_HOME=/usr/local/tomcat
DAEMON_HOME=$CATALINA_HOME/bin/jsvc-src
TOMCAT_USER=tomcat
TMP_DIR=/var/tmp
CATALINA_OPTS=
CLASSPATH=$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/bin/commons-daemon.jar:$CATALINA_HOME/bin/bootstrap.jar
start(){
echo -n $"Starting $prog: "
#
# Start Tomcat
#
$DAEMON_HOME/jsvc \
-user $TOMCAT_USER \
-home $JAVA_HOME \
-Dcatalina.home=$CATALINA_HOME \
-Djava.io.tmpdir=$TMP_DIR \
-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 \
RETVAL=$?
[ $RETVAL = 0 ] && touch /var/lock/subsys/jsvc
[ $RETVAL = 0 ] && echo_success || echo_failure
echo
return $RETVAL
}
stop(){
echo -n $"Stopping $prog: "
#
# Stop Tomcat
#
PID=`cat /var/run/jsvc.pid`
kill $PID
RETVAL=$?
[ $RETVAL = 0 ] && rm /var/lock/subsys/jsvc
[ $RETVAL = 0 ] && echo_success || echo_failure
echo
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
*)
echo "Usage $0 start/stop"
exit 1;;
esac
這樣便大功告成了(某些路徑、用戶設(shè)置需要根據(jù)自己的具體環(huán)境修改)?赡苓需要用chown tomcat tomcat及chmod +x tomcat修改屬主及可執(zhí)行權(quán)限
關(guān)鍵詞標(biāo)簽:Linux,Tomcat
相關(guān)閱讀
熱門(mén)文章 安裝紅帽子RedHat Linux9.0操作系統(tǒng)教程使用screen管理你的遠(yuǎn)程會(huì)話GNU/Linux安裝vmware如何登錄linux vps圖形界面 Linux遠(yuǎn)程桌面連
人氣排行 Linux下獲取CPUID、硬盤(pán)序列號(hào)與MAC地址linux tc實(shí)現(xiàn)ip流量限制dmidecode命令查看內(nèi)存型號(hào)linux下解壓rar文件安裝紅帽子RedHat Linux9.0操作系統(tǒng)教程Ubuntu linux 關(guān)機(jī)、重啟、注銷(xiāo) 命令lcx.exe、nc.exe、sc.exe入侵中的使用方法查看linux服務(wù)器硬盤(pán)IO讀寫(xiě)負(fù)載