如何使用JConsole的连接到EC2? [英] How do I use Jconsole to connect to EC2?
问题描述
我在我的MacBook上运行JConsole的,并尝试连接到Linux终端上的EC2不具有图形(仅适用于命令行访问)。
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).
我跑我的code是这样的:
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
我看了这里,有通过EC2访问问题(后我有连接问题)和解决方案似乎是 java.rmi.server.hostname到该实例的公共主机名
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
'
我有点困惑,在如何做到这一点。我已经试过两件事情,一是把它直接在我的code(在虚空静态主要部分):
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
系统接受了它(没有错误,当我创建/上载运行的JAR)。我也打开了我的情况下防火墙以允许所有TCP流量。没有运气。我尝试了上面的语句也可以作为一个标志,启动该程序,但仍然没有运气。
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?
更新:这将显示我在java如何绿色,我得到了一步(仍然无法正常工作),但我意识到,把Java的罐子filename.jar,然后选择并没有给我相同的结果为把我的罐子在命令的末尾。我试过了,程序会尝试连接,然后说:连接失败(之前它只是说,它在登录屏幕右侧的距离)。
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).
推荐答案
设置虚拟机前的主机名属性启动:
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.
最后,确保iptables的停止,因为这可能是因为你没有得到来自外部世界的连接的原因。作为根(或使用sudo ...):
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
这篇关于如何使用JConsole的连接到EC2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!