Difference between revisions of "Tomcat 5"

From Briki
Jump to: navigation, search
(Logging)
 
Line 72: Line 72:
 
* Comment out '''Logger''' section in '''/usr/share/tomcat5/conf/server.xml'''
 
* Comment out '''Logger''' section in '''/usr/share/tomcat5/conf/server.xml'''
 
* Create empty file '''/var/log/tomcat5/tomcat.log''' (tomcat complains without this, for some reason)
 
* Create empty file '''/var/log/tomcat5/tomcat.log''' (tomcat complains without this, for some reason)
 
  
 
=== Changing a webapp to use log4j logging (eg. axis) ===
 
=== Changing a webapp to use log4j logging (eg. axis) ===
Line 94: Line 93:
 
log4j.logger.org.bretts=DEBUG
 
log4j.logger.org.bretts=DEBUG
 
</pre>
 
</pre>
 +
 
== org.apache.jasper.JasperException: Unable to compile class for JSP ==
 
== org.apache.jasper.JasperException: Unable to compile class for JSP ==
  

Latest revision as of 20:48, 8 June 2010

Setup apache2 to connect to Tomcat 5/6

  • Uncomment the AJP connector on port 8009 in /etc/tomcat?/server.xml:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
  • Enable the necessary apache2 modules:
sudo a2enmod proxy_ajp
sudo a2enmod rewrite
  • Allow access to the proxy for all hosts by changing Deny from all to Allow from all in /etc/apache2/mods-enabled/proxy.conf. Ensure that ProxyRequests if off, unless you want to become an open proxy for anyone.
  • Create /etc/apache2/conf.default/tomcat (or add to /etc/apache2/sites-enabled/000-default) with the contents:
# Tomcat Root
RedirectMatch permanent         ^/tomcat$               /tomcat/
<Location /tomcat/>
    ProxyPass                   ajp://localhost:8009/
    ProxyPassReverse            ajp://localhost:8009/
    ProxyPassReverseCookiePath  /tomcat/                ajp://localhost:8009/
</Location>
  • Ensure, if other redirects are added in future, that they appear above the tomcat redirect to avoid path overrides

Webapp locations

  • /var/lib/tomcat5/webapps/ - user webapps, plus ROOT, examples, docs etc.
  • /var/lib/tomcat5/server/webapps/ - builtin admin and manager webapps

Other locations

  • /var/lib/tomcat5/common/lib/ - external libraries used by both tomcat itself and webapps
  • /var/lib/tomcat5/shared/lib/ - external libraries used by webapps, but not tomcat

Changing tomcat user

  • Set TOMCAT_USER in /etc/tomcat5/tomcat5.conf
  • See Fixing tomcat-users.xml.new error below
  • chown tomcat:tomcat /usr/share/tomcat5/conf/jk2.properties
  • chown tomcat:tomcat /usr/share/tomcat5/work/

Tidying up /etc/init.d/tomcat5 output

  1. In /etc/init.d/tomcat5
    1. Remove if statement around . /etc/init.d/rc.d/functions
    2. Change echo "waiting for processes to exit" to echo -n "."
    3. Add success after start and stop commands
  2. In /usr/bin/dtomcat5
    1. Comment out Using... lines
  3. In /usr/share/tomcat5/bin/relink
    1. Reorder find arguments to put -type d after mindepth and maxdepth arguments

Fixing tomcat-users.xml.new error

Error is javax.naming.NamingException: /usr/share/tomcat5/conf/tomcat-users.xml.new (Permission denied)

  1. chown tomcat:tomcat /etc/tomcat5 (NB. /usr/share/tomcat5/conf is a symlink to /etc/tomcat5)

Logging

Changing to tomcat to use log4j logging

  • Ensure log4j.jar and commons-logging.jar (or symlinks to them) are present in /usr/share/tomcat5/common/lib
  • Create file /usr/share/tomcat5/common/classes/log4j.properties with contents:
log4j.rootLogger=INFO, FileAppender

log4j.appender.FileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.FileAppender.File=/var/log/tomcat5/tomcat.log
log4j.appender.FileAppender.layout=org.apache.log4j.PatternLayout
# Print the date in ISO 8601 format
log4j.appender.FileAppender.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.FileAppender.MaxFileSize=1MB
log4j.appender.FileAppender.MaxBackupIndex=4

#log4j.logger.org.apache=DEBUG
  • Comment out Logger section in /usr/share/tomcat5/conf/server.xml
  • Create empty file /var/log/tomcat5/tomcat.log (tomcat complains without this, for some reason)

Changing a webapp to use log4j logging (eg. axis)

  • Ensure that log4j.jar is present in /var/lib/tomcat6/webapps/axis/WEB-INF/lib
  • Add a log4j.properties to /var/lib/tomcat6/webapps/axis/WEB-INF/classes
  • Reload the webapp

Example log4j.properties:

log4j.rootLogger=INFO, axisfile

log4j.appender.axisfile=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.axisfile=org.apache.log4j.RollingFileAppender
#log4j.appender.axisfile.MaxFileSize=10MB
#log4j.appender.axisfile.MaxBackupIndex=10
log4j.appender.axisfile.File=${catalina.base}/logs/axis/axis.log
# suffix for old daily logs
log4j.appender.axisfile.DatePattern='.'yyyy-MM-dd
log4j.appender.axisfile.layout=org.apache.log4j.PatternLayout
log4j.appender.axisfile.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss.SSS} %-5p [%t] %m <%c{1}>%n

log4j.logger.org.bretts=DEBUG

org.apache.jasper.JasperException: Unable to compile class for JSP

  1. chown tomcat:tomcat /usr/share/tomcat5/work/ (trailing slash is important)
  2. Restart tomcat


No Host matches server name error

  • Ensure /var/lib/tomcat5/webapps/ROOT is present - if not (and you're on Mandriva), you probably forgot to install the tomcat5-webapps and tomcat5-admin-webapps packages.


org.w3c.dom.DOMException: NOT_SUPPORTED_ERR error

  • For some reason, this occurred the first time cruisecontrol was run - restarting tomcat fixed it.

java.security.AccessControlException errors

  • Ensure CATALINA_OPTS contains -Djava.security.debug=access,failure in /etc/init.d/tomcat5
  • Restart tomcat and recreate the error
  • Run /usr/local/bin/catscan < /var/log/tomcat5/catalina_date.log to generate the required additions to /etc/tomcat5/policy.d/
  • Add the relevant permissions to a new, appropriately named file in /etc/tomcat5/policy.d/
  • Restart tomcat and retest
  • Rinse and repeat, until all errors gone

Azureus and Cocoon 2.1.9 via Tomcat 5.5

Setting up cocoon

  • Download the cocoon tar and untar.
  • Run ./build.sh webapp
  • cp -a build/webapp /usr/share/tomcat5/webapps/cocoon
  • Ensure the contents of /usr/share/tomcat5/webapps/cocoon are owned by root:root, except for the following, which should be owned by tomcat:root:
    • WEB-INF/db
    • WEB-INF/logs
  • Create the directory /usr/share/tomcat5/webapps/cocoon/slide, owned by tomcat5:root
  • Create /etc/tomcat5/policy.d/30cocoon.policy, with contents:
grant codeBase "file:${catalina.home}/webapps/cocoon/-" {
   permission java.io.FilePermission "/usr/lib/j2sdk1.5-sun/jre/lib/slide.properties", "read";
   permission java.io.FilePermission "/etc/tomcat5/policy.d", "read";
   permission java.io.FilePermission "/etc/tomcat5/policy.d/slide", "read,write";
   permission java.io.FilePermission "/etc/tomcat5/policy.d/slide/-", "read,write";
   permission java.io.FilePermission "${catalina.home}/temp/-", "read,write,delete";
   permission java.io.FilePermission "${catalina.home}/.cocoon/*", "read";
   permission java.io.FilePermission "${catalina.home}/webapps/cocoon/slide", "read,write";
   permission java.io.FilePermission "${catalina.home}/webapps/cocoon/slide/-", "read,write,delete";
   permission java.io.FilePermission "${catalina.home}/webapps/cocoon/WEB-INF/db/-", "write";
   permission java.io.FilePermission "${catalina.home}/webapps/cocoon/WEB-INF/logs", "write";
   permission java.io.FilePermission "${catalina.home}/webapps/cocoon/WEB-INF/logs/-", "write";
   permission java.lang.RuntimePermission "createClassLoader";
   permission java.lang.RuntimePermission "getClassLoader";
   permission java.lang.RuntimePermission "shutdownHooks";
   permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
   permission java.net.SocketPermission "java.sun.com:80", "connect,resolve";
   permission java.util.PropertyPermission "*", "read,write";
};
  • Add the following lines to /etc/apache2/conf.d/tomcat:
JkMount /cocoon ajp13_worker
JkMount /cocoon/* ajp13_worker
  • Restart tomcat5 and apache2, and check logs in /var/log/tomcat5 for errors.
  • Assuming no stack traces in logs, you should be able to open the cocoon homepage at http://mysite/cocoon/

Adding Azureus

  • Turn on statistics logging in Azureus.
  • Download azureus.common.xml and azureus.xsl from http://azureus.sourceforge.net/faq.php
  • Place downloaded files in /usr/share/tomcat5/webapps/cocoon/azureus
  • Edit azureus.common.xml to set the azureus server location to the logging statistics file.
  • Add a line to /etc/tomcat5/policy.d/30cocoon.policy giving file read permission to the azureus stats file.
  • Create /usr/share/tomcat5/webapps/cocoon/azureus/sitemap.xmap with the contents:
<?xml version="1.0"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
  <map:components>
    <map:generators default="file">
      <map:generator name="file" src="org.apache.cocoon.generation.FileGenerator"/>
    </map:generators>

    <map:transformers>
      <map:transformer name="xslt" src="org.apache.cocoon.transformation.TraxTransformer">
        <!-- This is a parameter to the transformer component -->
        <use-request-parameters>false</use-request-parameters>
      </map:transformer>
    </map:transformers>

    <map:serializers default="html">
      <map:serializer name="html" mime-type="text/html" src="org.apache.cocoon.serialization.HTMLSerializer">
        <doctype-public>-//W3C//DTD HTML 4.0 Transitional//EN</doctype-public>
        <doctype-system>http://www.w3.org/TR/REC-html40/loose.dtd</doctype-system>
        <omit-xml-declaration>true</omit-xml-declaration>
        <encoding>UTF-8</encoding>
        <indent>1</indent>
      </map:serializer>
    </map:serializers>
  </map:components>

  <map:pipelines>
    <map:pipeline type="noncaching">
      <map:generate type="file" src="azureus.cocoon.xml" />
      <map:transform type="xslt" src="azureus.xsl" />
      <map:serialize type="html" />
    </map:pipeline>
  </map:pipelines>
</map:sitemap>
  • Restart tomcat5 and apache2, and check you can see azureus stats at http://mysite/cocoon/azureus/
  • Sit back with a beer, and revel in the fact that you didn't have to spend 6 hours working out this stuff from scratch!