ubuntu怎么安装tomcat

ubuntu怎么安装tomcat,第1张

1、环境:ubuntu9.0、jre1.6、tomcat6.0(apache-tomcat-6.0.8.tar.gz)

2、jre安装与配置见

3、tomcat6解压并安装

$sudo tar -zxvf apache-tomcat-6.0.8.tar.gz

$sudo mv apache-tomcat-6.0.8 /opt/tomcat

4、启动tomcat,测试如果找不到JAVA_HOME,则打开catalina.sh

$sudo vim apache-tomcat-6.0.8/bin/catalina.sh

//在最顶上添加一行

JAVA_HOME=/usr/lib/java/jre1.6.0_21

5、测试正确结果输出如下:

Using CATALINA_BASE: /opt/tomcat/apache-tomcat-6.0.8

Using CATALINA_HOME: /opt/tomcat/apache-tomcat-6.0.8

Using CATALINA_TMPDIR: /opt/tomcat/apache-tomcat-6.0.8/temp

Using JRE_HOME: /usr/lib/java/jre1.6.0_21

6、修改默认端口,打开conf/server.xml

$sudo vim conf/server.xml

//修改

<Connector port="8080" ...

7、添加管理用户,打开conf/tomcat-users.xml,在tomcat-user中间添加

<role rolename="manager" />

<user username="admin" password="tomcat" roles="manager"/>

8、打开浏览器,输入地址打开正常,安装完成。

在ubuntu下面,我们安装tomcat可以有两种方式

[1]用aptitude安装

aptitude install tomcat6

[2]免安装版

从apache tomcat 网站下载apache-tomcat-6.0.20 然后直接解压

第一种方式,可以用/etc/init.d/tomcat6实现对tomcat的启动和关闭

那么第二种方式呢,就只能 cd /opt/apache-tomcat-6.0.20,然后

bin/startup.sh来启动,用bin/shutdown.sh来关闭。麻烦在于你每次都需要先进入目录,才

能启动和关闭。

一个简便的方式,可以如下实现和第一种方式一样的结果。

其实很简单。

cd /zy/green/apache-tomcat-6.0.20/

#./bin/startup.sh

case "$1" in

start)

./bin/startup.sh

exit 1

stop)

./bin/shutdown.sh

exit 1

esac

保存成文件/etc/init.d/tomcat

然后,你就可以用/etc/init.d/start来启动你的tomcat了,也可以用/etc/init.d/tomcat来关

闭你的tomcat了。

1.我这个是zip版本的,所以里面有一个service.bat的文件,所以很简单

运行:cmd=>再到Tomcat 5.0/bin目录下运行: service install 即可.

2.如果没有service.bat文件,可以把以下内容保存为service.bat.

service.bat全文件内容:

@echo off

if "%OS%" == "Windows_NT" setlocal

rem ---------------------------------------------------------------------------

rem NT Service Install/Uninstall script

rem

rem Options

rem install Install the service using Tomcat5 as service name.

rem Service is installed using default settings.

rem remove Remove the service from the System.

rem

rem name (optional) If the second argument is present it is considered

rem to be new service name

rem

rem $Id: service.bat,v 1.5.2.2 2004/09/05 07:57:57 mturk Exp $

rem ---------------------------------------------------------------------------

rem Guess CATALINA_HOME if not defined

set CURRENT_DIR=%cd%

if not "%CATALINA_HOME%" == "" goto gotHome

set CATALINA_HOME=%cd%

if exist "%CATALINA_HOME%/bin/tomcat5.exe" goto okHome

rem CD to the upper dir

cd ..

set CATALINA_HOME=%cd%

:gotHome

if exist "%CATALINA_HOME%/bin/tomcat5.exe" goto okHome

echo The tomcat.exe was not found...

echo The CATALINA_HOME environment variable is not defined correctly.

echo This environment variable is needed to run this program

goto end

rem Make sure prerequisite environment variables are set

if not "%JAVA_HOME%" == "" goto okHome

echo The JAVA_HOME environment variable is not defined

echo This environment variable is needed to run this program

goto end

:okHome

if not "%CATALINA_BASE%" == "" goto gotBase

set CATALINA_BASE=%CATALINA_HOME%

:gotBase

set EXECUTABLE=%CATALINA_HOME%/bin/tomcat5.exe

rem Set default Service name

set SERVICE_NAME=Tomcat5

set PR_DISPLAYNAME=Apache Tomcat

if "%1" == "" goto displayUsage

if "%2" == "" goto setServiceName

set SERVICE_NAME=%2

set PR_DISPLAYNAME=Apache Tomcat %2

:setServiceName

if %1 == install goto doInstall

if %1 == remove goto doRemove

echo Unknown parameter "%1"

:displayUsage

echo

echo Usage: service.bat install/remove [service_name]

goto end

:doRemove

rem Remove the service

"%EXECUTABLE%" //DS//%SERVICE_NAME%

echo The service '%SERVICE_NAME%' has been removed

goto end

:doInstall

rem Install the service

echo Installing the service '%SERVICE_NAME%' ...

echo Using CATALINA_HOME: %CATALINA_HOME%

echo Using JAVA_HOME: %JAVA_HOME%

rem Use the environment variables as an exaple

rem Each command line option is prefixed with PR_

set PR_DESCRIPTION=Apache Tomcat Server - http://jakarta.apache.org/tomcat

set PR_INSTALL=%EXECUTABLE%

set PR_LOGPATH=%CATALINA_HOME%/logs

set PR_CLASSPATH=%JAVA_HOME%/lib/tools.jar%CATALINA_HOME%/bin/bootstrap.jar

rem Set the server jvm from JAVA_HOME

set PR_JVM=%JAVA_HOME%/jre/bin/server/jvm.dll

if exist "%PR_JVM%" goto foundJvm

rem Set the client jvm from JAVA_HOME

set PR_JVM=%JAVA_HOME%/jre/bin/client/jvm.dll

if exist "%PR_JVM%" goto foundJvm

set PR_JVM=auto

:foundJvm

echo Using JVM: %PR_JVM%

"%EXECUTABLE%"

//IS//%SERVICE_NAME% --StartClass org.apache.catalina.startup.Bootstrap

--StopClass org.apache.catalina.startup.Bootstrap --StartParams start

--StopParams stop

if not errorlevel 1 goto installed

echo Failed installing '%SERVICE_NAME%' service

goto end

:installed

rem Clear the environment variables. They are not needed any more.

set PR_DISPLAYNAME=

set PR_DESCRIPTION=

set PR_INSTALL=

set PR_LOGPATH=

set PR_CLASSPATH=

set PR_JVM=

rem Set extra parameters

"%EXECUTABLE%"

//US//%SERVICE_NAME% --JvmOptions

"-Dcatalina.base=%CATALINA_BASE%-Dcatalina.home=%CATALINA_HOME%-Djava.endorsed.dirs=%CATALINA_HOME%/common/endorsed"

--StartMode jvm --StopMode jvm

rem More extra parameters

set PR_STDOUTPUT=%CATALINA_HOME%/logs/stdout.log

set PR_STDERROR=%CATALINA_HOME%/logs/stderr.log

"%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%/temp" --JvmMs 128 --JvmMx 256

Echo "%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%/temp" --JvmMs 128 --JvmMx 256

echo The service '%SERVICE_NAME%' has been installed.

:end

cd %CURRENT_DIR%

然后再执行1.的命令.

3.然后用: net start Tomcat 命令将服务启起来.

一般来说,很多服务都可以用以下命令来添加服务和运行服务.

添加服务:service install "服务名字"

启动服务:net start 服务名

停止服务:net stop 服务名

如: net start mysql5 即启动MySQL服务.


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11427314.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存