开发者

Still cannot connect Tomcat 6 remotely via VisualVM

开发者 https://www.devze.com 2022-12-20 12:19 出处:网络
If checked the other questions regarding this issue but so far no soultion. Here is my setup: TC6 runs on a debian vm on my macbook. in /etc/default/tomcat6.0 I have following options set:

If checked the other questions regarding this issue but so far no soultion. Here is my setup: TC6 runs on a debian vm on my macbook. in /etc/default/tomcat6.0 I have following options set:

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

netstat -ntlp gives me:

tcp6       0      0 :::8080                 :::*                    LISTEN      6550/java
tcp6       0      0 :::8086                 :::*                    LISTEN      6550/java

Where 6550:

root      6550  3.3  6.8 224888 52984 pts/0    Sl   10:31   0:43 /usr/lib/jvm/java-6-sun/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/var/lib/tomcat6.0/conf/logging.properties -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8086 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.endorsed.dirs=/usr/share/tomcat6.0/common/endorsed -classpath :/usr/lib/jvm/java-6-sun/jre//lib/jcert.jar:/usr/lib/jvm/java-6-sun/jre//lib/jnet.jar:/usr/lib/jvm/java-6-sun/jre//lib/jsse.jar:/usr/share/tomcat6.0/bin/bootstrap.jar:/usr/share/tomcat6.0/bin/commons-logging-api.jar -Dcatalina.base=/var/lib/tomcat6.0 -Dcatalina.home=/usr/share/tomcat6.0 -Djava.io.tmpdir=/var/lib/tomcat6.0/temp org.apache.catalina.startup.Bootstrap start

Firewall:

Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all      anywhere             anywhere            

Chain FORWARD (policy DROP)
target     prot opt source               destination         

Chain OUTPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all      anywhere             anywhere 

When I try to connect from OSX using jvisualm: - adding a new host with the hostname of my vm (added it to /etc/hosts) - adding a new JMX-Connection

VisualVM fails wit开发者_StackOverflow中文版h:

Cannot connect using service:jmx:rmi///jndi/rmi://<vmhostname>:8086/jmxrmi

When I connect to my VM using ssh -X and start jvisualvm on the same machine that tomcat is running on, I do not initially see TC, but I can add the jmx connection as above.

Could this be an issue with foreign hosts being misteriously prevented to access the rmiregistry? Why would anyone do such a dumb thing?

What am I doing wrong?

(sorry 4 the lengthy post)


Here is a tutorial on how to connect Visual VM to Tomcat 7. It is a bit on the verbose side, but should help steer you around a number of the problems most people run into.


Check out the jmx listener on this page. http://tomcat.apache.org/tomcat-6.0-doc/config/listeners.html

It lets you set both the JMX port and the RMI registry port, both of which have to open on your firewall.


Try adding to catalina_opts: -Djava.rmi.server.hostname=vmhostname and ensure that your mac is able to resolve this hostname, e.g. nc -v vmhostname 8086 should succeed in opening the connection.


You may try to add actual ip and hostname to /etc/hosts where jstatd is running.


Follow this steps,

  • Download jvisualvm setup from Download Jvisualvm

  • Unzip this setup and go to bin directory from command line

  • Use this command to start the visualvm:

    \bin>visualvm.exe -J-Dnetbeans.system_socks_proxy=localhost:9998 -J-Djava.net.useSystemProxies=true

  • get the putty setup ,go to installation directory of putty use following command to ssh tunnel to remote system

putty -D 9998 -load Name_of_the_saved_putty_session

  • saved_putty_session should have tunnel to localhost:JMX_port and some_source_port

  • now in visualvm UI in Left nav ,right click the remote and "Add remote host" , with public ip of remote host

  • Now on this added remote host right click and say "ADD JMX CONNECTION"

  • In a connection box say localhost:source_port_provided_in_putty_tunnel

  • Click on the ok button and you are done.


So the above worked for me:

service:jmx:rmi:///jndi/rmi://machinedomainname:1099/jmxrmi

After spending 1/2 day on this. Following all the usual instructions and getting frustrated the above cracked it.

I have a play application deployed in amazon ec2 with the following flags:

 -Dcom.sun.management.jmxremote
   -Dcom.sun.management.jmxremote.port=<myport>
   -Dcom.sun.management.jmxremote.authenticate=false
   -Dcom.sun.management.jmxremote.ssl=false
   -Dcom.sun.management.jmxremote.local.only=false
   -Djava.rmi.server.hostname=<mymachinedomainname>

I have jvisualvm running locally on my mac.

I added a jvisualvm remote host with host name:

 <mymachinedomainname>

Then added added a jmx connection to this host. I tried the recommended

service:jmx:rmi://<mymachinedomainname>:<myport>

but it would just not connect.

But as soon as i did

service:jmx:rmi:///jndi/rmi://<mymachinedomainname>:<myport>/jmxrmi 

instead. it connected and works.

No idea why! but it works.


Make sure that you can

a) ping <vmhostname>
b) telnet <vmhostname> 8086

Note also that you can use IP address instead of <vmhostname>


Make sure the jstatd process is running on the remote machine which you want to monitor, with required permissions.


I would suggest using this option:

-Dcom.sun.management.jmxremote.port=1099

Then, connect with

service:jmx:rmi:///jndi/rmi://machinedomainname:1099/jmxrmi

As long as RMI is listening on all interfaces ( ie. 0.0.0.0) then there should be no problem connecting from a remote server as long as the firewall is off (or carefully configured).


I have actually just tackled this problem myself and figured it out.

I would wager that the problem is the RMI connections - you can't predict which ports it will use and so you can't get it to work with a firewall.

The workaround is to use an SSH proxy:

  1. SSH to the box where your application is running but use the -D option like this:

    ssh user@remoteHost -D 9999

    This will start a socks proxy on your local machine on port 9999.

  2. Open JVisualVM and in the preferences, under 'network' configure it to use a socks proxy at localhost, on port 9999.

If you do the above, you should then be able to connect to the remote machine as normal and since all the RMI traffic is now going over the SSH proxy, it is punched through the firewall and works nicely.

Good luck :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消