码迷,mamicode.com
首页 > 系统相关 > 详细

linux (centos) 安装tomcat (用shell脚本安装为服务)

时间:2014-11-26 20:58:02      阅读:352      评论:0      收藏:0      [点我收藏+]

标签:linux   tomcat   shell   服务   

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/network
RETVAL=0
export JRE_HOME=/usr/local/jdk1.7.0
export CATALINA_HOME=/home/jinyuan/tomcat/tomcatjinyuan1
export CATALINA_BASE=/home/jinyuan/tomcat/tomcatjinyuan1
start()
{
        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
        ;;
esac
exit $RETVAL
  命名为tomcatoa(这个名称就是服务名,后面用命令方式启动时可用),用winscp把这个脚本文件上传到/etc/init.d/目录下
  并执行以下脚本:
  sudo chmod +x /etc/init.d/tomcatoa

  chkconfig --add tomcatoa

  chkconfig  tomcatoa  on

4、用service tomcatoa start命令启动服务







 
     

linux (centos) 安装tomcat (用shell脚本安装为服务)

标签:linux   tomcat   shell   服务   

原文地址:http://blog.csdn.net/shandian534/article/details/41520595

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!