WebObjects/Web 应用程序/部署/Tomcat 部署详情
用于部署 WebObjects 应用程序到 Tomcat 的详细信息。
- Tomcat 安装位置:/usr/local/tomcat
- Apache 配置位置:/etc/httpd
- 应用程序位置:/usr/local/myapps
- Java 安装位置:/usr/java/jdk1.5.0_06
将所有常用库安装到/usr/local/tomcat/shared/lib,例如:
activation.jar commons-logging-1.1.jar httpunit-1.6.2.jar java-diff-1.0.5.jar mail.jar mysql-connector-java-5.0.6-bin.jar servlet-api.jar wsdl4j.jar
安装
/usr/local/myapps/deploy/myapp.war
对于每组应用程序(以 10 为一组),创建这些文件和目录结构。有关ROOT.xml文件的内容,请参见下一节。
请注意,每个应用程序都有自己的主机目录,例如myapp01.mydomain.com、myapp02.mydomain.com、myapp03.mydomain.com等。
将这些放置在
/usr/local/myapps
Group01
group01/catalina/conf/web.xml group01/catalina/conf/tomcat-users.xml group01/catalina/conf/context.xml group01/catalina/conf/Catalina/myapp01.mydomain.com/ROOT.xml group01/catalina/conf/Catalina/myapp02.mydomain.com/ROOT.xml group01/catalina/conf/Catalina/myapp03.mydomain.com/ROOT.xml group01/catalina/conf/Catalina/myapp04.mydomain.com/ROOT.xml group01/catalina/conf/Catalina/myapp05.mydomain.com/ROOT.xml group01/catalina/conf/Catalina/myapp06.mydomain.com/ROOT.xml group01/catalina/conf/Catalina/myapp07.mydomain.com/ROOT.xml group01/catalina/conf/Catalina/myapp08.mydomain.com/ROOT.xml group01/catalina/conf/Catalina/myapp09.mydomain.com/ROOT.xml group01/catalina/conf/Catalina/myapp10.mydomain.com/ROOT.xml group01/catalina/conf/server.xml group01/catalina/logs/
Group02
group02/catalina/conf/web.xml group02/catalina/conf/tomcat-users.xml group02/catalina/conf/context.xml group02/catalina/conf/Catalina/myapp11.mydomain.com/ROOT.xml group02/catalina/conf/Catalina/myapp12.mydomain.com/ROOT.xml group02/catalina/conf/Catalina/myapp13.mydomain.com/ROOT.xml group02/catalina/conf/Catalina/myapp14.mydomain.com/ROOT.xml group02/catalina/conf/Catalina/myapp15.mydomain.com/ROOT.xml group02/catalina/conf/Catalina/myapp16.mydomain.com/ROOT.xml group02/catalina/conf/Catalina/myapp17.mydomain.com/ROOT.xml group02/catalina/conf/Catalina/myapp18.mydomain.com/ROOT.xml group02/catalina/conf/Catalina/myapp19.mydomain.com/ROOT.xml group02/catalina/conf/Catalina/myapp20.mydomain.com/ROOT.xml group02/catalina/conf/server.xml group02/catalina/logs/
对于每个主机/应用程序,使用此模板,将出现的“myapp01”字符串更改为与主机名称匹配,例如myapp01、myapp02。
<?xml version="1.0" encoding="UTF-8"?> <Context path="/" docBase="/usr/local/myapps/deploy/myapp.war" reloadable="true" antiJARLocking="true"> <Environment name="wo/NSLog4jLoggerName" value="myapp04" type="java.lang.String" override="false"/> <Environment name="wo/myParameter" value="myValue" type="java.lang.String" override="false"/> </Context>
wo/NSLog4jLoggerName参数用于 log4j 日志记录,请参见下文。使其与应用程序名称匹配。
在此处设置您自己的变量以进行特定于应用程序的配置。
对于上面的每个组,安装如下所示的主机定义,使其与前面的命名方案匹配,安装到该组的server.xml中。以下是group02的条目
<Server port="8502" shutdown="SHUTDOWN"> <Service name="group02"> <Connector port="8902" enableLookups="false" debug="0" protocol="AJP/1.3" /> <Engine name="Catalina" defaultHost="myapp11.mydomain.com"> <Host name="myapp11.mydomain.com" debug="0" unpackWARs="false" autoDeploy="true" /> <Host name="myapp12.mydomain.com" debug="0" unpackWARs="false" autoDeploy="true" /> <Host name="myapp13.mydomain.com" debug="0" unpackWARs="false" autoDeploy="true" /> <Host name="myapp14.mydomain.com" debug="0" unpackWARs="false" autoDeploy="true" /> <Host name="myapp15.mydomain.com" debug="0" unpackWARs="false" autoDeploy="true" /> <Host name="myapp16.mydomain.com" debug="0" unpackWARs="false" autoDeploy="true" /> <Host name="myapp17.mydomain.com" debug="0" unpackWARs="false" autoDeploy="true" /> <Host name="myapp18.mydomain.com" debug="0" unpackWARs="false" autoDeploy="true" /> <Host name="myapp19.mydomain.com" debug="0" unpackWARs="false" autoDeploy="true" /> <Host name="myapp20.mydomain.com" debug="0" unpackWARs="false" autoDeploy="true" /> </Engine> </Service> </Server>
- Connector端口对于单个物理机上使用的每个Service必须是唯一的,并且必须与下面介绍的 Apacheworker.properties配置文件中使用的相应modjk工作程序端口匹配。
注意:每个应用程序部署文件和类都可以在应用程序的work目录中找到,但管理员无需在任何时候修改它们。
将此添加到 Tomcat 的开头以获取来自 log4j 的明确调试信息。Log4j 可能非常令人沮丧,因此这对于调试它正在执行的步骤至关重要
log4j.debug=true
有关详细信息,请参见下面的 Tomcat 启动命令。
将log4j属性文件安装到 Tomcat 的 common/clases 目录中
/usr/local/tomcat/common/classes/log4j.properties
如果此位置似乎无效,请尝试
/usr/local/myapps/group01/catalina/common/classes/log4j.properties
将路径更改为应用程序的相应组,例如从 group01 更改为 group02。
可以取消注释注释行,并重新启动应用程序对应的 Tomcat 服务器,以输出特定应用程序的日志记录。此处的示例用于名为“myapp01”的应用程序;此名称在上面的 ROOT.xml 文件中由wo/NSLog4jLoggerName参数定义
#log4j.logger.myapp01=DEBUG, A2 #log4j.appender.A2=org.apache.log4j.RollingFileAppender #log4j.appender.A2.File=${catalina.base}/logs/myapp01.log #log4j.appender.A2.MaxFileSize=100MB #log4j.appender.A2.MaxBackupIndex=2 #log4j.appender.A2.layout=org.apache.log4j.PatternLayout #log4j.appender.A2.layout.ConversionPattern=%-5p %c [%t] %r - %m%n #log4j.appender.A2.Threshold=DEBUG log4j.rootLogger=INFO, Tomcat log4j.appender.Tomcat=org.apache.log4j.FileAppender log4j.appender.Tomcat.File=${catalina.base}/logs/tomcat.log log4j.appender.Tomcat.layout=org.apache.log4j.PatternLayout log4j.appender.Tomcat.layout.ConversionPattern=%p %t %c - %m%n log4j.logger.myapp01=FATAL log4j.logger.myapp02=FATAL log4j.logger.myapp03=FATAL log4j.logger.myapp04=FATAL log4j.logger.myapp05=FATAL log4j.logger.myapp06=FATAL log4j.logger.myapp07=FATAL log4j.logger.myapp08=FATAL log4j.logger.myapp09=FATAL log4j.logger.myapp10=FATAL log4j.logger.myapp11=FATAL log4j.logger.myapp12=FATAL log4j.logger.myapp13=FATAL log4j.logger.myapp14=FATAL log4j.logger.myapp15=FATAL log4j.logger.myapp16=FATAL log4j.logger.myapp17=FATAL log4j.logger.myapp18=FATAL log4j.logger.myapp19=FATAL log4j.logger.myapp20=FATAL
另一种查看应用程序日志记录信息的方法是,例如,注释相应的行并重新启动服务器
# log4j.logger.myapp16=FATAL
这会将myapp16应用程序的日志记录信息输出到/usr/local/tomcat/logs/tomcat.log。
分别启动每个服务器。环境变量可以在之前导出,或者像这样在命令行上传递,然后调用可执行文件
JAVA_OPTS="-Xms256m -Xmx256m" JAVA_HOME=/usr/java/jdk1.5.0_06 CATALINA_BASE=/usr/local/myapps/group01/catalina /usr/local/tomcat/bin/startup.sh JAVA_OPTS="-Xms256m -Xmx256m" JAVA_HOME=/usr/java/jdk1.5.0_06 CATALINA_BASE=/usr/local/myapps/group02/catalina /usr/local/tomcat/bin/startup.sh JAVA_OPTS="-Xms256m -Xmx256m" JAVA_HOME=/usr/java/jdk1.5.0_06 CATALINA_BASE=/usr/local/myapps/group03/catalina /usr/local/tomcat/bin/startup.sh JAVA_OPTS="-Xms256m -Xmx256m" JAVA_HOME=/usr/java/jdk1.5.0_06 CATALINA_BASE=/usr/local/myapps/group04/catalina /usr/local/tomcat/bin/startup.sh JAVA_OPTS="-Xms256m -Xmx256m" JAVA_HOME=/usr/java/jdk1.5.0_06 CATALINA_BASE=/usr/local/myapps/group05/catalina /usr/local/tomcat/bin/startup.sh
或者启动一个带有 log4j 调试的 Tomcat 实例以确定 log4j 在确定日志设置和输出时使用的步骤
JAVA_OPTS="-Dlog4j.debug=true -Xms256m -Xmx256m" JAVA_HOME=/usr/java/jdk1.5.0_06 CATALINA_BASE=/usr/local/myapps/group01/catalina /usr/local/tomcat/bin/startup.sh
在 Linux 上,此命令将关闭服务器上的所有 Java 进程,请小心
pkill java
或者可以指定特定进程,例如 12203
pkill -P 10203
有时 Tomcat 会挂起,请小心,这会杀死系统上的每一个 Java 进程,绝不留情
pkill -9 java
这也有效,在本例中用于group01服务器
CATALINA_BASE=/usr/local/myapps/group01/catalina /usr/local/tomcat/bin/shutdown.sh
添加到 httpd.conf
JkLogFile "/usr/local/tomcat/logs/mod_jk.log" JkLogLevel info JkOptions +ForwardURICompat JkWorkersFile /etc/httpd/workers.properties
并添加/etc/httpd/worker.properties,其中包含
worker.list=worker01,worker02,worker03,worker04,worker05 worker.worker01.type=ajp13 worker.worker01.host=localhost worker.worker01.port=8901 worker.worker02.type=ajp13 worker.worker02.host=localhost worker.worker02.port=8902 worker.worker03.type=ajp13 worker.worker03.host=localhost worker.worker03.port=8903 worker.worker04.type=ajp13 worker.worker04.host=localhost worker.worker04.port=8904 worker.worker05.type=ajp13 worker.worker05.host=localhost worker.worker05.port=8905
每个虚拟主机都包含这样的条目,其中具体内容已适当地修改,例如将myapp02更改为与您的应用程序名称匹配
<VirtualHost *:80> ServerName myapp02.mydomain.com DocumentRoot "/Library/WebServer/WebSites/myapp02" JkMount /WebObjects/* worker01 <Location "/MyApp/WEB-INF/*"> AllowOverride None deny from all </Location> <Location "/MyApp/META-INF/*"> AllowOverride None deny from all </Location> <IfModule mod_rewrite.c> Include "/etc/httpd/mods/mod_rewrite_tomcat.conf" RewriteRule (.*)/cgi-bin/(.*)/___AppNamePlaceHolder___(\.woa(/.*)?)? $1/$2/MyApp$3 [L,PT] </IfModule> </VirtualHost>
确保 apache 已构建和/或安装以使用 mod_rewrite。
然后安装 /etc/httpd/mod_rewrite.conf
RewriteEngine On RewriteRule ^/WebObjects/.*$ - [L,PT]
这只是一个示例,您需要自己详细了解。或者弄清楚并使用通用规则更新此维基。
Tomcat 服务器启动并 Apache 运行后,访问一个网站。
http://myapp04.mydomain.com
修改 WAR 文件将重新部署所有应用程序。用应用程序的更新版本替换 WAR 文件,将系统地自动部署新版本,一次一个 Tomcat 服务器。这可以通过跟踪 /usr/local/tomcat/logs/tomcat.log 来实现。
修改或更新 ROOT.xml 应用程序文件将重新加载/重新部署应用程序,如果进行了任何更改,则新部署将获取这些更改。
要获取重写规则日志,请将以下内容添加到重写文件的顶部
RewriteLog /tmp/mod_rewrite.log RewriteLogLevel 9
重启 Apache 并跟踪 /tmp/mod_rewrite.log,同时访问网站。
等待更多信息。
参见上面的注释。目前,不会阻止应用程序正常运行。看起来像是 web.xml 文件中未使用的条目。
未知,但可能是应用程序先前完全无法启动的结果。
删除类路径中 jar 文件的重复副本,最有可能在 /usr/local/tomcat/common/lib 中。
Caused by: java.lang.ExceptionInInitializerError Caused by: java.lang.IllegalStateException There is already a unique instance for Bundle named 'JavaXML'.
例如
mv /usr/local/tomcat/common/lib/JavaXML.jar /var/tmp
未知,配置错误。
- Servlet threw load() exception javax.servlet.UnavailableException: Can't find application bundle. You can either define WOROOT, LOCALROOT and WOAINSTALLROOT as Java system properties (e.g. in your application server's launch script as command line arguments) or in the application Deployment Descriptor file (web.xml). at com.webobjects.jspservlet.WOServletAdaptor._applicationInit(WOServletAdaptor.java:335)
at com.webobjects.eoaccess.EODatabaseContext._fireArrayFault(EODatabaseContext.java:4399) at com.webobjects.eoaccess.EOAccessArrayFaultHandler.completeInitializationOfObject(EOAccessArrayFaultHandler.java:70) at com.webobjects.eocontrol._EOCheapCopyMutableArray.willRead(_EOCheapCopyMutableArray.java:38) at com.webobjects.eocontrol._EOCheapCopyMutableArray.count(_EOCheapCopyMutableArray.java:92) at com.webobjects.eocontrol.EOSortOrdering._sortUsingKeyOrderArray(EOSortOrdering.java:173) at com.webobjects.eocontrol.EOSortOrdering.sortArrayUsingKeyOrderArray(EOSortOrdering.java:254)