====== Tomcat Administration ======
===== Tag 1 =====
==== 1.2 - tomcat.sh ====
#!/bin/sh
### Start Config ###
TOMCAT_VERSION=10.1.20
INSTANCE_NAME=workshop
### End Config ####
CATALINA_HOME=/opt/tomcat/products/${TOMCAT_VERSION}
CATALINA_BASE=/opt/tomcat/instances/${INSTANCE_NAME}
export CATALINA_HOME
export CATALINA_BASE
case "$1" in
start)
$CATALINA_HOME/bin/startup.sh
;;
stop)
$CATALINA_HOME/bin/shutdown.sh
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
==== 1.3 - Erweiterung setenv.sh ====
CATALINA_TMPDIR="${CATALINA_VAR}/temp"
CATALINA_PID="${CATALINA_VAR}/logs/tomcat.pid"
CATALINA_OUT="${CATALINA_VAR}/logs/catalina.out"
CATALINA_OPTS="-Dcatalina.var=${CATALINA_VAR}"
==== 1.4 - OOM ====
JAVA_OOM="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/tomcat/workshop -XX:OnOutOfMemoryError=${CATALINA_HOME}/bin/oom.sh"
CATALINA_OPTS="$CATALINA_OPTS $JAVA_OOM"
==== 1.4 - action.bash ====
#!/bin/bash
dumps=`ls -1rt /var/tomcat/java_pid*.hprof | tail -1`;
printf "Memory Dump:\n $dumps" >> /tmp/dumps.log
# printf "Memory Dump:\n $dumps" | mailx -s "Memory Dump" "admin@example.zz"
==== 1.8 - Valve und Filter ====
ExpiresFilter
org.apache.catalina.filters.ExpiresFilter
ExpiresByType text
access plus 2 days
ExpiresFilter
*.html
REQUEST
===== Tag 2 =====
==== 2.4 - SSL Connector ====
==== 2.5 - Anpassungen logging.properties ====
handlers = 1catalina.org.apache.juli.AsyncFileHandler,
2localhost.org.apache.juli.AsyncFileHandler,
3manager.org.apache.juli.AsyncFileHandler, 4hostmanager.
org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler,
5workshop1.org.apache.juli.AsyncFileHandler,
6workshop2.org.apache.juli.AsyncFileHandler
5workshop1.org.apache.juli.AsyncFileHandler.level = FINE
5workshop1.org.apache.juli.AsyncFileHandler.directory = ${catalina.var}/logs
5workshop1.org.apache.juli.AsyncFileHandler.prefix = workshop_log1.
5workshop1.org.apache.juli.AsyncFileHandler.maxDays = 90
5workshop1.org.apache.juli.AsyncFileHandler.encoding = UTF-8
6workshop2.org.apache.juli.AsyncFileHandler.level = FINE
6workshop2.org.apache.juli.AsyncFileHandler.directory = ${catalina.var}/logs
6workshop2.org.apache.juli.AsyncFileHandler.prefix = workshop_log2.
6workshop2.org.apache.juli.AsyncFileHandler.maxDays = 90
6workshop2.org.apache.juli.AsyncFileHandler.encoding = UTF-8
ws_log.handlers = 5workshop1.org.apache.juli.AsyncFileHandler
de.kippdata.workshop.handlers = 6workshop2.org.apache.juli.AsyncFileHandler
==== 2.6 - log4j.xml ====
%d %r %p [%t] %c (%F:%L) - %m%n
==== 2.7 - JMX Remote ====
JMX_OPTS_NOSSL_NOAUTH="\
-Dcom.sun.management.jmxremote=true \
-Dcom.sun.management.jmxremote.port=1090 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
"
JMX_OPTS_SSL_NOAUTH="\
-Dcom.sun.management.jmxremote=true \
-Dcom.sun.management.jmxremote.port=1090 \
-Dcom.sun.management.jmxremote.ssl=true \
-Dcom.sun.management.jmxremote.authenticate=false \
-Djavax.net.ssl.keyStorePassword=workshop \
-Djavax.net.ssl.keyStore=${CATALINA_BASE}/conf/keystore.jks \
"
JMX_OPTS_SSL_AUTH="\
-Dcom.sun.management.jmxremote=true \
-Dcom.sun.management.jmxremote.port=1090 \
-Dcom.sun.management.jmxremote.ssl=true \
-Dcom.sun.management.jmxremote.authenticate=true \
-Dcom.sun.management.jmxremote.access.file=${CATALINA_BASE}/conf/jmxremote.access \
-Dcom.sun.management.jmxremote.password.file=${CATALINA_BASE}/conf/jmxremote.password \
-Djavax.net.ssl.keyStorePassword=workshop \
-Djavax.net.ssl.keyStore=${CATALINA_BASE}/conf/keystore.jks \
"
CATALINA_OPTS="$CATALINA_OPTS $JMX_OPTS_NOSSL_NOAUTH"
===== Tag 3 =====
==== 3.7 - Ressources ====
==== 3.8 - LDAP Realm ====
===== Tag 4 =====
===== Tag 5 =====
==== 5.1 - docker ====
FROM alpine:3.15
#### OpenJDK 17
RUN apk update
RUN apk add openjdk17-jre-headless
ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk
#### tcnative
#ENV TCNATIVE 1.2.33
#RUN apk add openjdk17-jdk apr-dev openssl-dev gcc make musl-dev
#RUN wget -O /tmp/tomcat-native-${TCNATIVE}-src.tar.gz https://dlcdn.apache.org/tomcat/tomcat-connectors/native/${TCNATIVE}/source/tomcat-native-${TCNATIVE}-src.tar.gz; \
# cd /tmp; \
# tar -zxf tomcat-native-${TCNATIVE}-src.tar.gz; \
# cd tomcat-native-${TCNATIVE}-src/native; \
# ./configure --prefix=/opt/tcnative/${TCNATIVE}; \
# make; \
# make install; \
# cd /tmp; \
# rm -rf /tmp/tomcat-native*
#### tomcat
ENV TOMCATVERSION 10.0.20
ENV INSTANCENAME workshop
ENV TOMCATDIR /opt/tomcat
ENV WARFILE workshop.war
ENV APPVERSION 3.1.0
ENV CATALINA_HOME ${TOMCATDIR}/products/apache-tomcat-${TOMCATVERSION}
ENV CATALINA_BASE ${TOMCATDIR}/instances/${INSTANCENAME}
ENV CATALINA_VAR /var/tomcat/${INSTANCENAME}
ENV PATH $CATALINA_HOME/bin:$PATH
ENV TCUSER tcrun
ENV TCGROUP tcgroup
# create CATALINA_HOME
RUN mkdir -p "${TOMCATDIR}/products"; \
cd ${TOMCATDIR}/products; \
wget -O /tmp/tomcat-product.tar.gz "https://archive.apache.org/dist/tomcat/tomcat-10/v${TOMCATVERSION}/bin/apache-tomcat-${TOMCATVERSION}.tar.gz"; \
tar -zxf /tmp/tomcat-product.tar.gz; \
rm /tmp/tomcat-product.tar.gz
# create CATALINA_BASE
COPY ${INSTANCENAME}.tar /tmp/${INSTANCENAME}.tar
RUN mkdir -p ${TOMCATDIR}/instances; \
cd ${TOMCATDIR}/instances; \
tar -xf /tmp/${INSTANCENAME}.tar; \
rm /tmp/${INSTANCENAME}.tar
# create CATALINA_VAR
RUN mkdir -p /var/tomcat/${INSTANCENAME}; \
cd /var/tomcat/${INSTANCENAME}; \
mkdir logs temp webapps work
# create webappdir
RUN mkdir -p /opt/webapps/${INSTANCENAME}/${APPVERSION}-jee9
COPY $WARFILE /opt/webapps/${INSTANCENAME}/${APPVERSION}-jee9/
# create runtime user and change rights
RUN addgroup $TCGROUP; \
adduser -h /opt/tomcat -H -G $TCGROUP -s /bin/sh -D $TCUSER; \
chown -R $TCUSER:$TCGROUP /opt/tomcat; \
chown -R $TCUSER:$TCGROUP /var/tomcat; \
chown -R $TCUSER:$TCGROUP /opt/webapps
WORKDIR $CATALINA_BASE
EXPOSE 8080 8443
USER $TCUSER
CMD ["catalina.sh","run"]
==== 5.3 - einfacher Proxy ====
ProxyPass /workshop http://localhost:8180/workshop
ProxyPassReverse /workshop http://localhost:8080/workshop
ProxyPassReverse /workshop http://localhost:8180/workshop
ProxyPreserveHost On
==== 5.6 - Monitoring ====
ProxyPass /lbmanager !
SetHandler balancer-manager
AuthType basic
AuthName "Proxy Balancer"
AuthBasicProvider file
AuthUserFile htpasswd.intern
Require user proxyadmin
LogFormat "%h %l %u %t \"%r\" %>s %b %{BALANCER_ROUTE_CHANGED}e %{BALANCER_WORKER_ROUTE}e %{BALANCER_SESSION_ROUTE}e %D" proxyextended
CustomLog "logs/proxy_access_log" proxyextended