How do I use Jconsole to connect to EC2?
Asked Answered
H

2

6

I am running Jconsole on my macbook and trying to connect to a linux terminal on ec2 that does not have graphics(only command line access).

I run my code like this:

java -jar program.jar -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9005 
-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.remote.ssl=false

I read here that there was a problem with accessing via EC2(after I had problems connecting) and the solution seemed to be 'java.rmi.server.hostname to the public hostname of the instance'

I'm a bit confused at how to do this. I have tried two things, one to put it directly in my code(in the void static main section):

System.setProperty( "java.rmi.server.hostname" , "external_EC2_address" ); //in my real code I have the correct address here

The system accepted it(no errors when I created/uploaded runnable jar). I also opened the firewall on my instance to allow all TCP traffic. No Luck. I tried the above statement also as a flag to launch to the program but still no luck.

Any ideas how do this?

UPDATE: This will show how green I am at Java, I got a step further(still doesn't work) but I realized putting the java -jar filename.jar and then the options didn't give me the same results as putting my -jar at the end of the command. I tried that and the program tries to connect and then says connection failed(before it would just say it at the login screen right away).

Honebein answered 2/4, 2012 at 23:39 Comment(0)
I
2

Set the hostname property before the VM starts:

java -Dcom.sun.management.jmxremote \
     -Dcom.sun.management.jmxremote.port=9005 \
     -Dcom.sun.management.jmxremote.authenticate=false \
     -Dcom.sun.management.remote.ssl=false \
     -Djava.rmi.server.hostname=the.public.ip \
     -jar program.jar

Add the relevant rules to your security group.

Finally, ensure iptables is stopped, as this could be the reason that you're not getting a connection from the outside world. As root (or using sudo ...):

# service iptables stop
Indelicate answered 3/4, 2012 at 0:24 Comment(1)
Thank you for the answer. I followed what you wrote and still got the same error.Honebein
T
1

You need to open up the JMX remote port (9005 according to your example above) in the security group for your instance.

Topliffe answered 2/4, 2012 at 23:46 Comment(3)
I have already done this. just to be on the safe side I opened 0 - 65535 as well.Honebein
The only other thing I can't tell from above is whether you set java.rmi.server.hostname to the public hostname of your instance (this is usually in the format something like ec2-xxx-yyy-zzz-aaa.compute-1.amazonaws.com, where xxx-yyy-zzz-aaa is the public IP address). If you did that already I'm stumped, sorry.Topliffe
Your right I was using the public hostname to connect(which is what I use for ssh) ec2-xxx. I got an IP address and gave it a shot and still same problem.Honebein

© 2022 - 2024 — McMap. All rights reserved.