0

According to https://tomcat.apache.org/tomcat-8.0-doc/monitoring.html#Introduction I should be able to active JMX by setting some env variables on CATALINA_OPTS. I've done this:

export CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

Some places seem to suggest I need catalina-jmx-remote.jar in $CATALINA_OPTS/lib which I have:

$ ls -l /opt/tomcat/apache-tomcat-8.0.37/lib/catalina-jmx-remote.jar
-rw-r--r-- 1 root root 13608 Jan 18 23:05 /opt/tomcat/apache-tomcat-8.0.37/lib/catalina-jmx-remote.jar

I've also made sure the environment variable is properly set:

$ sudo cat /proc/20893/environ
LANG=en_USLANGUAGE=en_US:PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binHOME=/srv/tomcatLOGNAME=tomcatUSER=tomcatSHELL=TOMCAT_JAVA_HOME=/opt/java/oracle/jdk1.8.0_112CATALINA_HOME=/opt/tomcat/apache-tomcat-8.0.37CATALINA_BASE=/srv/tomcat/catalina/tomcatCATALINA_OPTS=-Djava.rmi.server.hostname=172.16.29.134 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false

Despite this, JMX is not listening on 1099 and I cannot connect to it:

$ netstat --listen | grep 1099

If I run a regular java program with:

$ java -Djava.rmi.server.hostname=172.16.29.134 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false HelloWorld

This also seems to work if I pass it as args when starting tomcat:

/opt/java/oracle/jdk1.8.0_112/bin/java \
  -Djava.util.logging.config.file=/srv/tomcat/catalina/%i/conf/logging.properties \
  -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
  -Djava.security.egd=file:/dev/./urandom \
  -Djava.endorsed.dirs=/opt/tomcat/apache-tomcat-8.0.37/endorsed \
  -Dcatalina.home=/opt/tomcat/apache-tomcat-8.0.37 \
  -Dcatalina.base=/srv/tomcat/catalina/%i \
  -Djava.io.tmpdir=/srv/tomcat/catalina/%i/temp \
  -Djava.net.preferIPv4Stack=true \
  -Djava.rmi.server.hostname=172.16.29.134 \
  -Dcom.sun.management.jmxremote.authenticate=false \
  -Dcom.sun.management.jmxremote.port=1099 \
  -Dcom.sun.management.jmxremote.ssl=false \
  -classpath "/opt/tomcat/apache-tomcat-8.0.37/bin/bootstrap.jar:/opt/tomcat/apache-tomcat-8.0.37/bin/tomcat-juli.jar" \
  org.apache.catalina.startup.Bootstrap start

So why doesn't CATALINA_OPTS get picked up like the documentation suggests? What is it I'm missing?

Kit Sunde
  • 946
  • 3
  • 12
  • 31
  • where exactly do you set the catalina.opts? On the shell? it might be possible that your startup script for starting tomcat overwrites them. – Dennis Nolte Mar 05 '17 at 21:51
  • It's set in a systemd env file. I'm not sure when it would manage to overwrite it since systemd is invoking bin/java like above, and the process was at least initialized with that env according to /proc. – Kit Sunde Mar 05 '17 at 21:54
  • if it might be systemd related you might want to add the serverOS as tag, and the systemd version in case someone else knows details about that specific situation – Dennis Nolte Mar 05 '17 at 22:02
  • You mention systemd; here's an article for [Centos 7](https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-centos-7), and one for [Ubuntu 16.04](https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-16-04). In particular, see their example `/etc/systemd/tomcat.service` files -- and the fact that they use start/stop scripts (which should Do The Right Thing(tm)) rather than invoking `java` directly from the systemd file. – Castaglia Mar 06 '17 at 05:49
  • did you refresh systemd configuration via `systemctl daemon-reload` ? – GioMac Mar 10 '17 at 13:43
  • @GioMac Yes. But also as you can see from /proc the env is being passed. – Kit Sunde Mar 10 '17 at 13:45
  • You should set them up in setenv.sh CATALINA_OPTS=-Dcom.sun.whatever1 -Dcom.sun.whatever2 – Danila Ladner Mar 10 '17 at 15:21
  • Try once putting all Java parameter in "setenv.sh" under $CATALINA_HOME/bin – quark2is Mar 12 '17 at 04:32

0 Answers0