注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Computer Science

I Pressed My Words Here. Will You Read ?

 
 
 

日志

 
 

tomcat 中启动/停止 指定项目配置  

2012-11-28 09:47:36|  分类: Tips |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
引用:
给 Tomcat 指定运行的不同配置文件 http://www.oschina.net/question/12_330

在tomcat中可能配置有多个项目,当同时启动他们时可能会出现冲突,这时,即不想反复更改配置,又不愿意为每个项目单独做个tomcat(浪费空间)。那么以下命令能帮你解决这个问题:
cd 到tomcat文件夹下
启动:bin/startup.sh -config conf/server_1.xml
停止:bin/shutdown.sh -config conf/server_1.xml

server.xml中有两行配置默认是:
    <Engine name="Catalina" defaultHost="localhost">

     <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
对应的是 conf/Catalina/localhost/ 目录,意思是启动时,要按照此目录下的XXXX.xml中的配置路径来找要包含的项目/工程所在的目录。
xxxx.xml内容如下:
<Context path="/myProjectA" docBase="/opt/Workspace/myProjectA/trunk/src/main/webapp" debug="0" reloadable="true" crossContext="true">
    <!--Logger className="org.apache.catalina.logger.FileLogger" prefix="kfit." suffix=".txt" timestamp="true"/-->
</Context>

现在要参照server另配置一个server_1.xml 。将其中那两行配置中的localhost改为localhostProjectB。
于是 tomcat 在命令start.sh -config conf/server_1.xml 下 便会取conf/Catalina/localhostProjectB/目录下取找相应的xxxx.xml配置,而不会理会conf/Catalina/localhost/目录下的xml。

这样定向启动的目的便达到了。

启动后浏览器访问地址依旧时localhost:开头。如:lhttp://ocalhost:8080/myProjectB


参考:Tomcat Configuration - A Step By Step Guide http://www.mulesoft.com/tomcat-configuration

Engine

This element is used in conjunction with one or more Connectors, nested within a Service element, and is responsible for processing all requests associated with its parent service. The Engine element can only be used if it is nested within a Service element, and only one Engine element is allowed within a given Service element.Pay close attention to the "defaultHost" attribute, which defines the Host element responsible for serving requests for host names on the server that are not configured in server.xml. This attribute must match the name of one of the Host elements nested inside the Engine element in question. Also, it's important to assign a unique, logical name to each of your Engine elements, using the "name" attribute. If a single Server element in your server.xml file includes multiple Service elements, you are required to assign a unique name to every Engine element.

_____________________________________
后记
—————————————————————
后来,觉得这样在命令后面加参数的方式可能会在使用时,遭到一些挑剔的用户视为诟病,而否定以上配置方案。故,研究觉得模仿start.sh写一个startMyProjectA.sh的脚本,将参数一并分装。
#!/bin/sh
PRG="$0"
PRGDIR=`dirname "$PRG"`
exec "$PRGDIR"/"startup.sh" start "-config" "$PRGDIR"/".."/"conf/server-MyProjectA.xml"
保存在tomcat的bin目录下。
记得chmod +x bin/startMyProjectA.sh 给文件加执行权限。然后就可以直接通过bin/startMyProjectA.sh 启动MyProjectA了。至于shutdown的脚本,大家根据上文,应该不难修改出来。这里就不写了。
后来,有想了想。或许改成 bin/startmy.sh MyProjectB 这样的命令会更好。读者可以试着改改。
————————————————————————————————————————————
2013年1月7日
-------------------
新年好,为庆祝大家顺利度过世界末日来到天堂,在此和大家分享交互更加人性化的 startupmy.sh 和 startupmy.bat:
startupmy.sh
#!/bin/sh

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# -----------------------------------------------------------------------------
# Start script for the startup script of CATALINA Server
#
# $Id: startupmy.sh 000000 2013-1-7 11:30:17 $
# -----------------------------------------------------------------------------
PRG="$0"
PRGDIR=`dirname "$PRG"`
SERVERNAME="$1"
exec "$PRGDIR"/"startup.sh" start "-config" "$PRGDIR"/".."/"conf"/"server-$SERVERNAME.xml"

startupmy.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 regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the "License"); you may not use this file except in compliance with
rem the License.  You may obtain a copy of the License at
rem
rem     http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, 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 language governing permissions and
rem limitations under the License.

%OS%" == "Windows_NT" setlocal
rem ---------------------------------------------------------------------------
rem Start script for the startup script of CATALINA Server
rem
rem $Id: startupmy.bat 000001 2013-01-06 17:40:34 $
rem ---------------------------------------------------------------------------

set PRGDIR=%cd%
set /p SERVERNAME=Please input the SERVERNAME:
call "%PRGDIR%\startup.bat" start "-config" "%PRGDIR%\..\conf\server-%SERVERNAME%.xml"

就我的使用经验而言,startupmy.sh和 startupmy.bat在使用时操作步骤有些不同,效果也不同。startupmy.sh 带参数执行后终端不会有tomcat的log信息,而且关闭好像也需要使用shutdownmy.sh这样的脚本来指定停止相应名称的服务。而startupmy.bat执行后才要求输入SERVER的名称。并且会有tomcat的log在终端输出。关闭时,只需要Ctrl + C就停止了。

_________________________
注意:在localhost文件夹中 的xml配置名称应该是小写英文字母,我尝试用大写,然后页面得到400错误。

_________________________

tomcat 动态指定启动端口 http://computerscience.blog.163.com/blog/static/17496234320138511155588/

  评论这张
 
阅读(1580)| 评论(13)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017