设为首页 收藏本站
查看: 458|回复: 0

[经验分享] 解压版Tomcat创建服务启动

[复制链接]
发表于 2017-1-28 09:43:15 | 显示全部楼层 |阅读模式
  .配置环境变量
  1.JDK安装到C:\Program Files\Java\jdk1.6.0下载免安装版tomcat6.0(TomcatZip)压缩包,Tomcat解压放到C:\Tomcat6.0
  2.添加系统环境变量:
  JAVA_HOME=C:\ProgramFiles\Java\jdk1.6.0
  CLASSPATH=.;%JAVA_HOME%\lib
  TOMCAT_HOME=C:\Tomcat6.0
  修改系统环境变量PATH,在它的最前面加入:
  %JAVA_HOME%\bin;
  注:放在最前面是预防有其它的JDKJRE路径占先,如你装了Oracle就会有一个低版本的JRE
  配置Tomcat启动环境(注意,如果已经象前面那样设置过了,这里就可以跳过了)
  1、修改startup.bat文件:
  在第一行前面加入如下两行--
  SET JAVA_HOME=JDK目录
  SET CATALINA_HOME=前面解压后Tomcat的目录
  片段如下:
  @echo off
  SET JAVA_HOME=C:\Program Files\Java\jdk1.6.0
  SET CATALINA_HOME=C:\Tomcat6.0
  rem Licensed to the ApacheSoftware Foundation (ASF) under one or more
  rem contributor licenseagreements. See the NOTICE filedistributed with
  rem this work for additionalinformation regarding copyright ownership.
  rem The ASF licenses this file toYou under the Apache License, Version 2.0
  rem (the "License");you may not use this file except in compliance with
  2.如果需要使用shutdown.bat关闭服务器的话,也按照上面加入两行。
  片段如下:
  @echo off
  SET JAVA_HOME=C:\Program Files\Java\jdk1.6.0
  SET CATALINA_HOME=C:\Tomcat6.0
  rem Licensed to the Apache Software Foundation (ASF)under one or more
  rem contributor license agreements. See the NOTICE file distributed with
  rem this work for additional information regardingcopyright ownership.
  rem The ASF licenses this file to You under the ApacheLicense, Version 2.0
  rem (the "License"); you may not use thisfile except in compliance with
  rem the License. You may obtain a copy of the License at
  rem
  3、这样,运行startup.bat就可以运行服务器,运行shutdown.bat就可以关闭服务器了。
  但是这样运行startup.bat后不能把startup.bat弹出的窗口关掉,否则就退出了tomcat6.0服务,所以为了使用方便我们可以考虑把tomcat6.0加入系统的服务中去
  Tomcat加入服务
  //说明:如果你已经按照第一步(.配置环境变量),且运行startup.batshutdown.bat能成功那么下面第一就不要做了,否则会出现错误
  1、修改bin目录中的service.bat:
  REM 添加下面的一行
  set CATALINA_HOME=%cd%
  如果从来没有安装过Tomcat,或者保证Services.msc启动服务管理器检查没有Apache Tomcat系统服务,到此你就可以转到第二步了。否则继续往下走--
  //第一步一般不要了,否则可能出错!!
  REM 按照描述修改下面的几行
  set SERVICE_NAME=Tomcat6
  REM 上面一行,Tomcat6修改成你需要的服务名,这个将是一后使用net start/stop来操作的服务名称。
  //注意这一步很重要,如果你的系统现在有安装tomcat6.0,那么你一定要把"tomcat6"改成其它名字,而且不要以"tomcat6"为前缀,否则会由于你系统已经存在服务"tomcat6"而启动失败,可以把名字改为:"你的名字"+Tomcat6形式
  set PR_DISPLAYNAME=Apache Tomcat
  REM 上面一行,Apache Tomcat改为你需要的显示服务名,这个将显示在服务管理器中。
  //注意这一步也是很重要,如果你的系统现在有安装tomcat6.0,那么你一定要不"Apachetomcat"改成其它名字,而且不要以"Apachetomcat"为前缀,否则会由于你系统已经存在服务"Apachetomcat"而启动失败,可以把名字改为:"你的名字"+apache形式
  set PR_DESCRIPTION=Apache TomcatServer - http://jakarta.apache.org/tomcat
  REM 这一行改不改无所谓,是服务的描述,根据自己的喜好决定吧。
  我的tomcat6.0bin下的service.bat(下载后没有经过其它的配置修改,保持下载时的状态)修改后如下:贴出来如下
  @echo off
  rem Licensed to the Apache Software Foundation (ASF)under one or more
  rem contributor license agreements. See the NOTICE file distributed with
  rem this work for additional information regardingcopyright ownership.
  rem The ASF licenses this file to You under the ApacheLicense, Version 2.0
  rem (the "License"); you may not use thisfile except in compliance with
  rem the License.You may obtain a copy of the License at
  rem
  remhttp://www.apache.org/licenses/LICENSE-2.0
  rem
  rem Unless required by applicable law or agreed to inwriting, software
  rem distributed under the License is distributed on an"AS IS" BASIS,
  rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.
  rem See the License for the specific languagegoverning permissions and
  rem limitations under the License.
  if "%OS%" == "Windows_NT" setlocal
  rem---------------------------------------------------------------------------
  rem NT Service Install/Uninstall script
  rem
  rem Options
  rem install Install the service usingTomcat6 as service name.
  rem Service is installedusing default settings.
  rem remove Remove the service from theSystem.
  rem
  rem name(optional) If the second argument is present it is considered
  rem to be new servicename
  rem
  rem $Id: service.bat 600659 2007-12-03 20:15:09Z jim $
  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\tomcat6.exe"goto okHome
  rem CD to the upper dir
  cd ..
  set CATALINA_HOME=%cd%
  :gotHome
  if exist "%CATALINA_HOME%\bin\tomcat6.exe"goto okHome
  echo The tomcat.exe was not found...
  echo The CATALINA_HOME environment variable is notdefined correctly.
  echo This environment variable is needed to run thisprogram
  goto end
  rem Make sure prerequisite environment variables are set
  if not "%JAVA_HOME%" == "" gotookHome
  echo The JAVA_HOME environment variable is not defined
  echo This environment variable is needed to run thisprogram
  goto end
  :okHome
  if not "%CATALINA_BASE%" == ""goto gotBase
  set CATALINA_BASE=%CATALINA_HOME%
  :gotBase
  
  set EXECUTABLE=%CATALINA_HOME%\bin\tomcat6.exe
  rem Set default Service name
  set SERVICE_NAME=haotomcat6//原来为 setSERVICE_NAME=Tomcat6,这里hao是我的名字
  set PR_DISPLAYNAME=hao apache//原来为 setPR_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
  if %1 == uninstall 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 CATALINA_BASE: %CATALINA_BASE%
  echo Using JAVA_HOME: %JAVA_HOME%
  rem Use the environment variables as an example
  rem Each command line option is prefixed with PR_
  set PR_DESCRIPTION=Apache Tomcat Server -http://tomcat.apache.org/
  set PR_INSTALL=%EXECUTABLE%
  set PR_LOGPATH=%CATALINA_BASE%\logs
  set PR_CLASSPATH=%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 --StopClassorg.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 notneeded 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%\endorsed"--StartMode jvm --StopMode jvm
  rem More extra parameters
  set PR_LOGPATH=%CATALINA_BASE%\logs
  set PR_STDOUTPUT=auto
  set PR_STDERROR=auto
  "%EXECUTABLE%" //US//%SERVICE_NAME%++JvmOptions"-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties"--JvmMs128 --JvmMx 256
  echo The service '%SERVICE_NAME%' has been installed.
  :end
  cd %CURRENT_DIR%
  //service.bat中要修改的两处地方已经在上面要红色标出来了
  2、运行cmd打开控制台,进入Tomat目录/bin文件夹,输入如下命令运行。
  service.bat install
  程序提示:The service 'Tomcat5(或者你修改一后的SERVICE_NAME' has beeninstalled
  说明服务Tomcat已经被安装成功。
  顺便说一下,运行service.bat remove可以移除服务。
  3、到这里,服务添加成功,控制台下运行services.msc,可以看到添加的服务(在右边可以找到PR_DISPLAYNAME指定的服务名"haoapache"),默认状态下该服务是手动运行的,在他的属性中,可以将启动类型更改为自动,以后机器启动以后Tomcat就在后台启动了。
  
  控制台控制服务的命令
  启动服务
  net Start 服务名(此服务名为set SERVICE_NAME后面指定的服务名,或者为setPR_DISPLAYNAME指定的,下面一样)
  关闭服务
  net stop 服务名
  注:
  1 此服务名可以是SERVICE_NAME,也可以是PR_DISPLAYNAME;
  2 如果服务名中包含空格或者中文,请将服务名用半角双引号包含起来。
  
  最后,预祝第一次配置顺利。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-334371-1-1.html 上篇帖子: Tomcat访问日志详细配(转) 下篇帖子: Tomcat配置技巧Top 10 [ZT]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表