linux (centos) 安裝tomcat (用shell指令碼安裝為服務),centostomcat
1、下載tomcat 從http://tomcat.apache.org/download-70.cgi連結下載linux版本(tar.gz)
2、解壓,上傳及賦許可權 解壓,用WinSCP把解壓的安裝檔案上傳到/home/software/tomcat目錄 並用 chmod -R 755 /home/software/tomcat命令賬許可權。
3、編寫安裝為服務的指令碼並運行 shell指令碼如下:
#! /bin/sh#shell script takes care of starting and stopping# the glassfish DAS and glassfish instance.## chkconfig: - 64 36# description: Tomcat auto start# /etc/init.d/tomcatd# Tomcat auto-start# Source function library.#. /etc/init.d/functions# source networking configuration.#. /etc/sysconfig/networkRETVAL=0export JRE_HOME=/usr/local/jdk1.7.0export CATALINA_HOME=/home/jinyuan/tomcat/tomcatjinyuan1export CATALINA_BASE=/home/jinyuan/tomcat/tomcatjinyuan1start(){ if [ -f $CATALINA_HOME/bin/startup.sh ]; then echo $"Starting Tomcat" $CATALINA_HOME/bin/startup.sh RETVAL=$? echo " OK" return $RETVAL fi}stop(){ if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then echo $"Stopping Tomcat" $CATALINA_HOME/bin/shutdown.sh RETVAL=$? sleep 1 ps -fwwu yhjhoo | grep apache-tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9 echo " OK" # [ $RETVAL -eq 0 ] && rm -f /var/lock/... return $RETVAL fi}case "$1" in start) start ;; stop) stop ;; restart) echo $"Restaring Tomcat" $0 stop sleep 1 $0 start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 ;;esacexit $RETVAL
命名為tomcatoa(這個名稱就是服務名,後面用命令方式啟動時可用),用winscp把這個指令檔上傳到/etc/init.d/目錄下 並執行以下指令碼: sudo chmod +x /etc/init.d/tomcatoa
chkconfig --add tomcatoa
chkconfig tomcatoa on
4、用service tomcatoa start命令啟動服務