Unix / Linux: was macht mein Prozess?

There are some useful tools to check the load of your box / server – even when you have just only very less permissions (ant ‚top‘ is not available):

  • ptree – all processes with pid
  • prstat – similar to top
  • kill -3 <pid> – print (java) stack strace and dump to log
  • ps -aelf – you sh’d know it. Otherwise: forget your password.

velocity.log im „aktuellen“ Verzeichnis

Beim Einsatz von Velocity in Spring Projekten kannes vorkommen, dass Velocity im „aktuellen“ Verzeichnis loggen will. Jedoch kann Velocity auch ein existierendes Commons Logging / Log4j mit nutzen, indem man im classpath eine velocity.properties-Datei anlegt:

#runtime.log.logsystem.class=org.apache.velocity.runtime.log.SimpleLog4JLogSystem
runtime.log.logsystem.class=org.apache.velocity.tools.generic.log.CommonsLogLogSystem
runtime.log.logsystem.log4j.category=velocity

Wicket in Action

There are dozens of Java frameworks out there, but most of them require you to learn special coding techniques and new, often rigid, patterns of development. Wicket is different. As a component-based web application framework, Wicket lets you build maintainable enterprise-grade web applications using the power of plain old Java objects (POJOs), HTML, Ajax, Spring, Hibernate, and Maven. Wicket automatically manages state at the component level, which means no more awkward HTTPSession objects. Its elegant programming model enables you to write rich web applications quickly.

Wicket in Action is an authoritative, comprehensive guide for Java developers building Wicket-based web applications. This book starts with an introduction to Wicket’s structure and components, and moves quickly into examples of Wicket at work. Written by two of the project’s earliest and most authoritative experts, this book shows you both the “how-to” and the “why” of Wicket. As you move through the book, you’ll learn to use and customize Wicket components, how to interact with other technologies like Spring and Hibernate, and how to build rich, Ajax-driven features into your applications.

Weitere Infos auf manning.com

Apache Tomcat mit eigener Java VM starten

Apache Tomcat velangt nach einer Java VM – jedoch möchte man ggf eine andere verwenden, als auf dem System installiert ist?!

Apache Tomcat wird über ein Script gestartet, in dem sich auch wunderbar die entsprechenden Variablen überschreiben lassen. Wichtig ist dann nur, dies auch für das Shutdown-Script zu erledigen.

Durch Anpassung des startup.sh – Scriptes ist dies also einfach möglich!

# set my own java path
export JRE_HOME=/usr/java/jre1.6.0_01
# increase memory size
export JAVA_OPTS=-XX:MaxPermSize=512m

Es wird nun eine Java VM von einem bestimmten Pfad verwende, und auch die Optionen um den zu nutzenden Speicher zu vergrößern können gleichmit angegeben werden.

In der Datei shutdown.sh sollte jedoch mindesten die Zeile export JRE_HOME=/usr/java/jre1.6.0_01 nochmals angegeben werden, da ansonsten wieder die systemweit genutzte Environment-Variable verwendet werden würde.

Apache Tomcat und mod_jk / ajp13 auf SuSE Linux

Nach wie vor ist der Apache Httpd schneller als ein Apache Tomcat, wenn es um die Auslieferung von statischen Inhalten geht. Gerade in Verbindung mit Tomcat bietet der Apache Httpd noch weitere Vorteile: durch das Modul mod_jk kann eine ganze Farm an Tomcat-Servern per Load Balancer angeschlossen werden!

Für den Betrieb benötigt man:

  • einen funktionierenden Apache Httpd-Server
  • einen funktionierenden Apache Tomcat-Server
  • das Modul mod_jk, welches auf der Tomcat-Webseite zum download erhältlich ist

Das Modul habe ich zur Vereinfachung nach dem Download in „mod_jk.so“ umbenannt und im Lib-Verzeichnis des Apache Httpd abgelegt (auf SuSE Linux 10.2: /usr/lib/apache2).

Der Apache Httpd ist auf SuSE Linux so konfiguriert, dass alle Dateien, die auf *.conf enden und in /etc/apache2/conf.d liegen, automatisch zu httpd.conf (bzw default-server.conf) included werden. Das macht die weitere Konfiguration einfach, denn nun müssen in dem o.g. Verzeichnis nur zwei Konfigurationsdateien abgelegt werden.

Die Datei tomcat.conf bindet mod_jk ein:

# Load mod_jk module
# Update this path to match your modules location
LoadModule jk_module /usr/lib/apache2/mod_jk.so
# Declare the module for <IfModule directive> (remove this line on Apache 2.x)
#AddModule mod_jk.c

# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /etc/apache2/conf.d/workers.properties

# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile /var/log/apache2/mod_jk.shm

# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile /var/log/apache2/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel debug

# Select the timestamp log format
JkLogStampFormat „[%a %b %d %H:%M:%S %Y] “

# Send everything for context /examples to worker named worker1 (ajp13)
JkMount /application/* worker1

In der Datei müssen ggf. die Pfade zu mod_jk.so sowie zu den Log-Files angepasst werden.
Mit JkWorkersFile wird auf die Konfigurationsdatei des mod_jk referenziert. Alle Anfragen im Format http://www.domain.tld/application werden nun an mod_jk übergeben.

Die Datei workers.properties ist – sofern nur ein einziger Tomcat-Server angebunden werden muss, sehr kurz:

# Define 1 real worker using ajp13
# this coud be al list in the format
# worker.list=worker1, worker2, worker3, worker4
worker.list=worker1

# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009

Das Format zum Konfigurieren der einzelnen Worker ist also worker.<workername>.<property> . In der Beispielkonfiguration wird also nur ein Worker mit dem Namen „worker1“ genutzt, der auf dem gleichen Host läuft und mittels dem Protokoll ajp13 angesprochen wird.

Über die URL http://www.<domain>.<tld>/application erreicht man nun also direkt die Application auf dem Tomcat.

Quellen & weiterführende Links:

JAX 07: Apache und Tomcat 6

Workshop, Peter Roßbach @ JAX ’07, Wiesbaden + + +

Integration in Maven: Projekt Cargo

News in Tomcat 6

  • Support für Servlet 2.5 und JSP 2.1 API’s
  • Apache 2.0 Lizenz
  • Neue Connectoren (NIO)
  • Reduktion der Abhängigkeiten, Vereinfachung der Verzeichnisstrucktur
  • Neue JSP Engine (w/ JSF)
  • Coyote Connectoren optimiert: Verbesserung der Performance, Mod_JK 1.2.22, Native Connectoren im Tomcat >= 5.5.17
  • Erleichterung der Administration (JMX 1.2)
  • Einsatz des Eclipse 3.2 Compiler (JRE ready mit Java 5 JDT) – schneller, kleiner, besser handlebare Lizenz

Tomcat

  • jsvr – Wrapper für Tomcat, funktioniert wie Watchdog
  • Security Manager – steuert Zugriff auf Systemressourcen

App Reload (während der Entwicklungszeit)

in context.xml: Resources Monitoring:
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

  • Logging seit Tomcat 6.x
  • neues API
  • neues layout der Konfig Datei

Ports

  • 8080 – http
  • 8443 – https
  • 8009 – ssl
  • 8005 – shutdown
  • 9000 – JMX-Apdaptor http
  • 1099 – JMX-Apdaptor rmi
  • 0900 – JMX-Apdaptor iiop

Tomcat Pipeline

  • Server > Service > Engine > Host > Context > Wrapper
  • jeder Übergang wird mit einer Pipeline verbunden. An den Pipelines können Valves angeflanscht werden

Infos über den Tomcat & Server

  • Tool: Lambda Probe
  • Link: http://www.lambdaprobe.org
  • >> lambdaprobe.org: „Lambda Probe (formerly Tomcat Probe) is a self sufficient web application, which helps to visualize various parameters of Apache Tomcat instance in real time. Lambda Probe is designed to work specifically with Tomcat so it is able to access far more information that is normally available to JMX agents.“
  • Umfassende Infos über Tomcat, Apps, JVM…
  • noch keine vollständige Unterstützung von Tomcat 6.x (Stand: 2007-04-27)

Protokoll-Handler austauschen

  • in der server.xml wird das Protokoll gegen eine Klasse ausgtauscht, die das Protokoll implementiert

<Connector port=“8080″ protocol=“org.apache.coyote.http11.Http11NioProtocol“
connectionTimeout=“20000″
redirectPort=“8443″ />
<!–
<Connector port=“8080″ protocol=“HTTP/1.1″
connectionTimeout=“20000″
redirectPort=“8443″ />
–>

Arbeiten mit mod_jk

  • Eigenen conf-Datei in httpd.conf includen:

<IfModule !mod_jk.c>
LoadModule jk_module „modules/mod_jk.so“
</IfModule>
JkShmFile „logs/mod_jk.shm“
JkLogFile „logs/mod_jk.log“
JkLogLevel info
JKWorkersFile conf/workers.properties
JKWorkerProperty worker.list=loadbalancer,jkstatus
JKWorkerProperty worker.node01.port=8009
JKWorkerProperty worker.node01.host=localhost
JKWorkerProperty worker.node01.type=ajp13
JKWorkerProperty worker.node01.domain=d10
JKWorkerProperty worker.node01.lbfactor=4
JKWorkerProperty worker.loadbalancer.type=lb
JKWorkerProperty worker.loadbalancer.balance_workers=node01
JKWorkerProperty worker.jkstatus.type=status
JkMount /jkstatus jkstatus
JkMount /example* loadbalancer

Tipp: Template verwenden wenn viele Nodes im Einsatz sind:

JKWorkerProperty worker.template.type=ajp13
JKWorkerProperty worker.template.connection_pool_timeout=300

JKWorkerProperty worker.node01.lb.balance_workers_node=node101
JKWorkerProperty worker.node01.reference=worker.template

thanks to Peter Roßbach! Great work!

JAX 07: Session: Apache Tomcat

Konfig Apache:

  • httpd.conf: „Include conf/mod_jk.conf“
  • mod_jk.conf: Definition der Worker, Tomcat-Nodes etc

Konfig Tomcat:

  • server.xml: connector-Tag, Properties port=“8009″ + protocol=“AJP/1.3″
  • > Angabe der Engine-Name + jvmRoute zur Erkennung, Load Balancer kann so eine Session immer mit dem gleichen Node verbinden

… many hand written stuff…

Links:

thanks to Peter Roßbach! (www.objectpark.de)