[[http://tmade.de|Home tmade.de]] [[http://wiki.tmade.de|Home Wiki]] ===== Tomcat ===== ==== Tomcat Log ==== /srv/www/tomcat6/logs/catalina.out #Tomcat logfile To check, if server has started (finally all applications loaded), have a look on string (within catalina.out): "Server startup in" ==== Version ==== To check version of tomcat: /usr/share/tomcat5.5/bin/version.sh #Check Tomcat version ==== Tomcat Manager ==== The tomcat manager can be used to start, stop and deploy applications. The manager can be accessed on: http(s)://HOST-IP/manger/html To add/ modify a tomcat user (admin) edit "tomcat-root/conf/tomcat-users.xml". Example: **Note:** The relevant part might be configured with XML-comments () and has to be uncommented (remove "") to get it work! To avoid setting a plaintext password execute: export JAVA_HOME="/usr/lib/jvm/default-java/" #JAVA_HOME has to be setup to get it work. tomcat-root/bin/digest.sh –a MD5 "test" #The password "test" will be created Example: ./digest.sh -a MD5 "test" test:098f6bcd4621d373cade4e832627b4f6 Afterwards replace with Additionally edit the "tomcat-root/conf/server.xml" as follows. Previously: Afterwards: Finaly the tomcat has to be restarted. ==== Limit Manager Access ==== To limit network access to "127.0.0.1, 192.168.1.*, 192.168.0.*" for the tomcat-manager edit: tomcat-root/conf/Catalina/localhost/manager.xml Previously: Afterwards: ==== Tomcat Initscript ==== The following script (/etc/init.d/tomcat6) will start Tomcat6 and may be added on autostart (chkconfig tomcat6 on). #! /bin/sh # # Author: Thomas Roehm # # /etc/init.d/tomcat6 # # and symbolic its link # # /sbin/rctomcat6 # ### BEGIN INIT INFO # Provides: tomcat6 # Required-Start: $network $remote_fs # Required-Stop: $network $remote_fs # Default-Start: 3 5 # Default-Stop: 0 1 2 6 # Description: Start Tomcat6 # Startup script for Tomcat # description: Tomcat jakarta JSP server ### END INIT INFO #Necessary environment variables export CATALINA_HOME="/srv/www/tomcat6" if [ ! -f $CATALINA_HOME/bin/catalina.sh ] then echo "Tomcat not available..." exit fi start() { echo -n -e '\E[0;0m'"\033[1;32mStarting Tomcat: \033[0m \n" su -l tomcat -c $CATALINA_HOME/bin/startup.sh sleep 3 } stop() { PID=`(cat /var/log/tomcat6/tomcat.pid)` echo -n -e '\E[0;0m'"\033[1;31mShutting down Tomcat: \033[m \n" su -l tomcat -c $CATALINA_HOME/bin/shutdown.sh sleep 10 kill $PID rm /var/log/tomcat6/tomcat.pid } status() { ps ax | grep "org.apache.catalina.startup.Bootstrap start" | grep tomcat | awk '{printf $1 " "}' > /tmp/tomcat_process.txt process=`(cat /tmp/tomcat_process.txt)` if [ -s /tmp/tomcat_process.txt ] then echo "Tomcat is running with PID $process" else echo "Tomcat has been stopped" fi } case "$1" in start) start ;; stop) stop ;; restart) stop sleep 15 start ;; status) status ;; *) echo "Usage: tomcat6 {start|stop|restart|status}" exit 1 esac Additionally to start/stop with "rctomcat6 option": ln –s /ect/init.d/tomcat6 /sbin/rctomcat6 ==== Tomcat systemd unit-file ==== Path: /etc/systemd/system/tomcat.service Content: # Systemd unit file for default tomcat # # To create clones of this service: # DO NOTHING, use tomcat@.service instead. [Unit] Description=Apache Tomcat Web Application Container After=syslog.target network.target [Service] Type=forking #EnvironmentFile=/etc/tomcat/tomcat.conf ExecStart=/data/tomcat8.5/bin/startup.sh ExecStop=/data/tomcat8.5/bin/shutdown.sh User=tomcat Group=tomcat [Install] WantedBy=multi-user.target ==== OCF-Script ==== The following script can be used (in combination with the tomcat-initscript) for heartbeat (Linux-HA). The file has to be saved on "/usr/lib/ocf/resources.d/heartbeat/tomcat6". #!/bin/sh export OCF_ROOT=/usr/lib/ocf CATALINA_HOME="${OCF_RESKEY_catalina_home}" export CATALINA_HOME . ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs INIT_SCRIPT=/etc/init.d/tomcat6 case "$1" in start) cd "$CATALINA_HOME/bin" ${INIT_SCRIPT} start > /dev/null 2>&1 && exit || exit 1 ;; stop) cd "$CATALINA_HOME/bin" ${INIT_SCRIPT} stop > /dev/null 2>&1 && exit || exit 1 ;; status) cd "$CATALINA_HOME/bin" ${INIT_SCRIPT} status > /dev/null 2>&1 && exit || exit 1 ;; monitor) cd "$CATALINA_HOME/bin" # Check if Ressource is stopped ${INIT_SCRIPT} status > /dev/null 2>&1 || exit 7 # Otherwise check services (XXX: Maybe loosen retry / timeout) wget --no-proxy -O /dev/null http://localhost:8080/i52server/ 2>&1 | grep 'connected' && exit || exit 1 ;; meta-data) cat < 1.0 OCF Ressource Agent for Tomcat6. OCF Ressource Agent for Tomcat 6 Home directory of Tomcat Home directory of Tomcat END ;; esac ==== Catalina(.sh) Variables / Parameters ==== CATALINA_PID=/var/log/tomcat6/tomcat.pid --DisplayName ServiceName #Service display name in processlist Examples of paramters set in {$Tomcat}/bin/catalina.sh CATALINA_OPTS=" -Djava.awt.headless=true \ -Dcatalina.home=$CATALINA_BASE \ -Dcatalina.base=$CATALINA_BASE \ -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \ -Djava.util.logging.config.file=conf\logging.properties \ -Djavax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema=org.apache.xerces.jaxp.validation.XMLSchemaFactory \ -Xmx5021M \ -XX:MaxPermSize=256m \ -XX:+HeapDumpOnOutOfMemoryError \ -XX:HeapDumpPath=/srv/www/tomcat6/logs \ -Djava.compiler=NONE \ -Xdebug \ -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 \ -Xnoagent \ -Dcom.sun.management.jmxremote=true \ -Dorg.eclipse.jdt.core.compiler.source=1.5 \ -Dorg.eclipse.jdt.core.compiler.compliance=1.5 \ -Djavax.xml.datatype.DatatypeFactory=com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl \ -DconfigurationsFilePath=/etc/configuration \ -DoptionalConfigurationsFilePath=/etc/configuration \ -Dcompression=false \ -Duser.language=de \ -Duser.country=DE \ -Dcontentgrabber.default.charset=iso-8859-1 \ -Dmail.mime.charset=UTF-8 \ -Djavax.xml.bind.JAXBContext=com.sun.xml.bind.v2.ContextFactory \ -Djavax.net.ssl.keyStore=/srv/www/tomcat6/keystore/keystorefile.keystore \ -Djavax.net.ssl.keyStorePassword=password \ -Dhttp.proxyHost=10.10.15.15 \ -Dhttp.proxyPort=8080 \ -Djava.io.tmpdir=/var/log/tomcat6/temp \ -Dorg.eclipse.jdt.core.compiler.codegen.TargetPlatform=1.5 \ -DlogsFilePath=/var/log/tomcat6 \ -Dhttp.nonProxyHosts=localhost|127.0.0.1 \ -Dhttps.nonProxyHosts=localhost|127.0.0.1 " # -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk15Logger \ ==== JAVA OPTS ==== "JAVA OPTS" can be set on: *init-script */etc/default/tomcat *catalina.sh Example (/etc/default/tomcat): JAVA_OPTS="-XX:MaxPermSize=256m -Xms512m -Xmx1024m" ==== Forwarding to webapplication ==== Edit /srv/www/tomcat/webapps/ROOT/index.html to: ==== Certificat Request ==== Tomcat: 1. Create a local Certificate: keytool -genkey -alias tomcat -keysize 2048 -keyalg RSA -keystore #keystore_filename: E.g. tomcatSSL 2. The CSR is then created with: keytool -certreq -keyalg RSA -alias tomcat -file certreq.csr -keystore 3. Import the rootCA certificate into your keystore (you have to export it previously from the signed certificate): keytool -import -alias root -keystore -trustcacerts -file 4. Import the intermediate certificate into you keystore (you have to export it previously from the signed certificate): keytool -import -alias intermediate -keystore -trustcacerts -file 5. And finally import your new Certificate: keytool -import -alias tomcat -keystore -trustcacerts -file **Note:** The "alias" has to differ for the rootCA, intermediate and certificate! Official: Tomcat (keytool) This document provides instructions for installing TC Trust SSL certificate. If you are unable to use these instructions for your server, we recommend that you contact either the vendor of your server software or an organisation that supports Tomcat. 1 Install the Root CA certificate You must first obtain the Root CA certificate (TC TrustCenter Class 2 CA II) and save the Root CA certificate as root.cer. In the following example please replace the example keystore name 'keystore.key' with your keystore name. Use the following command to import this certificate in the keystore: keytool -import -alias root -keystore keystore.key -trustcacerts -file root.cer 2 Install the Intermediate CA certificate Create a file in Notepad and save the Intermediate CA certificate (TC TrustCenter Class 2 L1 CA XI) as intermediate.cer. Use the following command to import this certificate in the keystore: keytool -import -alias intermediate -keystore keystore.key -trustcacerts -file intermediate.cer 3 Install the TC Trust SSL certificate Your TC Trust SSL certificate will be sent via email. Look for the TC Trust SSL certificate text in the body of the email and copy and paste it into a .crt file (such as tc_server.crt) using Vi or Notepad. Please be sure to include the header and footer as well as the surrounding dashes including the -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- lines. NOTE: Do not use Microsoft Word or other word processing programs that may add characters. Confirm that there are no extra lines or spaces in the file otherwise additional characters may render the certificate unusable. Enter the following command to import your TC Trust SSL certificate (certreq.csr is the alias specified during CSR creation): keytool -import -alias server.crt -file server.crt -keystore keystore.key ====Check==== keytool -list -keystore keytool -list -v -keystore #verbose keytool -list -v -keystore /path/to/keystore.jks -storetype PKCS12 -storepass the_password #all at once Show alias of your keystore file (just if the alias "foo" is known): keytool -list -keystore -alias ==== Certificat Conversion ==== Convert key, crt certificate to pfx: openssl pkcs12 -export -out mypfxfile.pxf -inkey domain.name.key -in domain.name.crt Convert pfx certificate to jks: keytool -importkeystore -srckeystore mypfxfile.pxf -srcstoretype pkcs12 -destkeystore clientcert.jks -deststoretype JKS #type JKS keytool -importkeystore -srckeystore mypfxfile.pxf -srcstoretype pkcs12 -destkeystore clientcert.jks -deststoretype pkcs12 #type pkcs12 ==== Change Password ==== keytool -storepasswd -keystore KEYSTORE.jks #Keystore only has one password keytool -keypasswd -alias alias-name -keystore KEYSTORE.jks #To change password of private key