2018-05-25需要在Linux环境下配置免安装版本的Tomcat

实习过程中,需要在Linux环境下配置免安装版本的Tomcat,下面列出详细步骤,希望对大家有帮助。

一、下载免安装版Tomcat

打开Tomcat主页http://tomcat.apache.org/,下载Tomcat免安装版,我这里下载的是apache-tomcat-7.0.2.tar.gz。

二、配置Java环境变量

Java的环境变量已经在前几篇文章里有了概述,详细见:http://www.fengwenxuan.com/index.php/red-hat-enterprise-linux/238.html

三、解压Tomcat

      将Tomcat解压缩到/usr/local目录下

      # tar zxvf apache-tomcat-7.0.2.tar.gz 

四、启动Tomcat

      # cd /usr/local/apache-tomcat-7.0.2/bin

      # ./startup.sh

      如果启动成功,shell终端会出现如下提示:


      Using CATALINA_BASE:   /usr/local/apache-tomcat-7.0.2

      Using CATALINA_HOME:   /usr/local/apache-tomcat-7.0.2

      Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.2/temp

      Using JRE_HOME:       /usr/local/jdk1.6.0_21

      如果终端报错,基本上可以肯定是Jdk环境变量没有配置好,仔细在检查一下Jdk环境变量的配置

五、测试Tomcat

      打开火狐浏览器,地址栏输入http://localhost:8080,回车后看到Tomcat的LOGO,表示一切正常。也可以更改Tomcat目录下的conf文件夹,里面有一个server.xml文件,修改成使用80端口,这样浏览器只要输入http://localhost/就可以直接进入你的主页了。

六、停止Tomcat

      # cd /usr/local/apache-tomcat-7.0.2/bin

      # ./shutdown.sh

七、设置开机自动启动Tomcat


方法一:

在/usr/local/apache-tomcat-7.0.2/bin/startup.sh 为:

JAVA_HOME=/home/fwx/jdk1.6.0_14

CLASSPATH=.:$JAVA_HOME/lib/tools.jar

PATH=$JAVA_HOME/bin:$PATH

export JAVA_HOME CLASSPATH PATH

export CATALINA_HOME=/usr/local/apache-tomcat-7.0.2

/usr/local/tomcat/bin/catalina.sh start


在/etc/rc.d/rc.local中加入:

/usr/local/apache-tomcat-7.0.2/bin/startup.sh

方法二:

1、把下面的代码保存为tomcat文件,并让它成为可执行文件 chmod 755 tomcat.

#!/bin/bash

#

# [email protected]

# /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/apache-tomcat-7.0.2"

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

2、将tomcat文件拷贝到/etc/init.d/下,并运行:chkconfig --add tomcat

3、在apache-tomcat-7.0.2/bin/catalina.sh文件中加入以下语句:

export JAVA_HOME=/home/fwx/jdk1.6.0_14

export CATALINA_HOME=/usr/local/apache-tomcat-7.0.2

export CATALINA_BASE=/usr/local/apache-tomcat-7.0.2

export CATALINA_TMPDIR=/usr/local/apache-tomcat-7.0.2/temp

启动tomcat: service tomcat start

停止tomcat: service tomcat stop

本文来自:http://www.blogjava.net/peiliangye/articles/357768.html


异常处理

linux下启动tomcat----Cannot find ./catalina.sh

参考:http://dearseven.blog.163.com/blog/static/1005379222013764440253/

linux 下启动tomcat

[root@test233 bin]# sh startup.sh 

Cannot find ./catalina.sh

The file is absent or does not have execute permission

This file is needed to run this program


解决办法:

给.sh文件授权

[root@test233 bin]#  chmod +x *.sh  

再启动,成功

[root@test233 bin]# sh startup.sh 

Using CATALINA_BASE: /home/tomcat2

Using CATALINA_HOME: /home/tomcat2

Using CATALINA_TMPDIR: /home/tomcat2/temp

Using JRE_HOME: /home/jdk

Using CLASSPATH: /home/tomcat2/bin/bootstrap.jar:/home/tomcat2/bin/tomcat-juli.jar

Tomcat started.

你可能感兴趣的:(2018-05-25需要在Linux环境下配置免安装版本的Tomcat)