4

Trying to connect jconsole to a remote server.

I added this to my catalina.sh:

export JAVA_OPTS="-Dcom.sun.management.jmxremote \
    -Dcom.sun.management.jmxremote.port=9005 \
    -Dcom.sun.management.jmxremote.ssl=false \
    -Dcom.sun.management.jmxremote.authenticate=false \
    -Djava.rmi.server.hostname=xx.xx.xx.xx"

catalina.out shows:

Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: myhostname: myhostname

Not sure why it repeats my hostname in the error message?

BTW, since I set authentication to false, in the jconsole app, do I leave username/password blank or is that for logging into the server?

Blankman
  • 259,732
  • 324
  • 769
  • 1,199
  • Are you using the property rmi.server.hostname for some other pupose (other than enabling JMX) ? – Santosh Dec 22 '11 at 06:12
  • I'm using it b/c I think you need it to connect to a remote server. – Blankman Dec 22 '11 at 12:15
  • Hi @Blankman, If you think my answer has solved your problem, can you please accept my answer? otherwise I'm happy to help you if you need any further assistance. – Aamir Yaseen Nov 28 '13 at 17:28

5 Answers5

14

You have to add the same host name in /etc/hosts file as you have defined in /etc/sysconfig/network file. This is how I solved my problem.

Aamir Yaseen
  • 487
  • 6
  • 20
3

I have found the solution for this issue. Add the following in your catalina.sh file:

JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=7010 -Djava.rmi.server.hostname=${IP}"

Also add the following line in your /etc/init.d/hosts file:

127.0.0.1 localhost <your_hostname>

This resolved the issue. I am able to run jconsole as well as jvisualvm on this port now.
I hope this helps !

Autumn
  • 339
  • 5
  • 19
2

If you want to get the IP address dynamically you can try:

IP=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.ssl=false  -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=${IP}"
James
  • 15,085
  • 25
  • 83
  • 120
1
  1. If you use '\' in your 'export' statement, remove those.

  2. To connect to remote java process, Use IP address of the server where your java process (tomcat instance) is running. The UnknownHostException is thrown when IP address could not be determined, so another option is to add the name - IP address definition to your hosts file.

Seego
  • 106
  • 6
0

You can try adding the parameters that you have added in JAVA_OPTS to CATALINA_OPTS. It should work that way.
Also make sure u are making the settings with the same profile login from where you are running tomcat.

Autumn
  • 339
  • 5
  • 19