Cento OS7安装tomcat

 下载tomcat

[jerry@172 ~]$wget http://mirrors.noc.im/apache/tomcat/tomcat-6/v6.0.45/bin/apache-tomcat-6.0.45.tar.gz

 下载后会保存到当前用户的home目录下,运行如下命令解压

[jerry@172 ~]$tar -zxvf apache-tomcat-6.0.45.tar.gz

 修改文件夹名称

[jerry@172 ~]$ mv apache-tomcat-6.0.45 apache-tomcat-6.0.45_1

 切换到以下目录

[jerry@172 ~]$ cd /home/jerry/apache-tomcat-6.0.45_1/bin

 启动tomcat

[jerry@172 bin]$ ./startup.sh

 停止tomcat

[jerry@172 bin]$ ./shutdown.sh

 将tomcat变成服务可以开机运行,先编写以下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
export CATALINA_HOME=/home/jerry/apache-tomcat-6.0.45_1
export CATALINA_BASE=/home/jerry/apache-tomcat-6.0.45_1
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

 注意如下需要根据实际情况来写

export JRE_HOME=/usr
export CATALINA_HOME=/home/jerry/apache-tomcat-6.0.45_1
export CATALINA_BASE=/home/jerry/apache-tomcat-6.0.45_1

 将脚本保存为tomcat6_1.sh上传到/etc/init.d/目录再运行如下命令添加服务

[jerry@172 ~]$ sudo chmod +x /etc/init.d/tomcat6_1.sh

 

[jerry@172 ~]$ sudo chkconfig --add tomcat6_1.sh

 

[jerry@172 ~]$ sudo chkconfig  tomcat6_1.sh on

 至此服务已安装完成并可以开机自动启动。我们也可以手动启动服务

[jerry@172 ~]$ service tomcat6_1.sh start

 或停止服务

[jerry@172 ~]$ service tomcat6_1.sh stop

 

你可能感兴趣的:(Cento OS7安装tomcat)