Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't stop tomcat normally when I configure jmxremote

Tags:

java

tomcat

jmx

I added a jmxremote configuraiton in the catalina.bat:

set JAVA_OPTS=-Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false

so that I could start jconsole to monitor the tomcat's performance.

But I got a problem that I couldn't stop tomcat normally through $CATALINA_HOME\catalina.bat stop, neither did $CATALINA_HOME\shutdown.bat

Any suggestions?

like image 249
爱国者 Avatar asked Nov 20 '11 05:11

爱国者


1 Answers

In order to monitor the java process, you need to add the following system properties to the command line:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

In the visualvm you just use the connection string host:9999.

However, sometimes the RMI listener listens to the wrong IP address, one which is inaccessible to the visualvm. Thanks to Pavel’s tip, I found a way to overcome this is by adding the following parameters:

-Djava.rmi.server.hostname=$(hostname)
-Djava.rmi.server.useLocalHostname=true

Now it works like a charm!

For completeness, I’d mention you can secure the connection to the JVM, either by requiring user/password or by using SSL. If you are interested, please see this guide.

Make sure that you put the definitions in a place only the start command sees, but not the shutdown. The reason or this is that the jmx remote create a listening socket, making the shutdown to listen to the same port if not configured properly.

like image 169
David Rabinowitz Avatar answered Oct 18 '22 10:10

David Rabinowitz