linux安装Tomcat及开启自启动

linux安装Tomcat及开启自启动

去官网http://tomcat.apache.org/download-90.cgi下载安装包在上传到linux上,找到Binary Distributions进行下载

解压

tar -xzvf  apache-tomcat-9.0.0.M9.tar.gz  

配置环境

JAVA_HOME=/usr/java/jdk-10.0.1        配置jdk
CLASSPATH=$JAVA_HOME/lib/       
CATALINA_HOME=/usr/local/tomcat                     tomcat环境变量
PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
export PATH JAVA_HOME CLASSPATH CATALINA_HOME

修改Tomcat端口

进入conf文件夹 vi server.xml 编辑配置文件

 <Connector port="8088" protocol="HTTP/1.1"
        connectionTimeout="20000"

        redirectPort="8443" />

启动服务

./startup.sh

查看状态

ps -ef|grep java

停止服务

错误代码:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of

解决方法:打开tomcat的bin目录下面的setclasspath.sh

vi ./setclasspath.sh在最前面添加

export JAVA_HOME=/opt/zimbra/jdk1.6.0_31
export JRE_HOME=/opt/zimbra/jdk1.6.0_31/jre 

tomcat开启自启动

创建tomcat 文件并给权限chmod 755 tomcat编写以下内容:

#!/bin/bash
#
# kenny kenny.zhou@tom.com
# /etc/rc.d/init.d/tomcat
# init script for tomcat precesses
#
# processname: tomcat
# description: tomcat is a j2se server
# chkconfig: 2345 86 16
# description: Start up the Tomcat servlet engine.

if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
echo -e "/atomcat: unable to locate functions lib. Cannot continue."
exit -1
fi

RETVAL=$?
CATALINA_HOME="/usr/local/tomcat"

case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac

exit $RETVAL

将tomcat文件拷贝到/etc/init.d/下,并运行:

chkconfig --add tomcat

在tomcat/bin/catalina.sh文件中加入以下语句:

export JAVA_HOME=/YOURPATH/tomcat/jdk
export CATALINA_HOME=/YOURPATH/tomcat
export CATALINA_BASE=/YOURPATH/tomcat
export CATALINA_TMPDIR=/YOURPATH/tomcat/temp

启动tomcat:

service tomcat start

停止tomcat:

service tomcat stop 
上一篇:安装配置Tomcat,idea配置Tomcat(纯步骤)


下一篇:上传图片到项目路径下保存