有人成功使用远程JMX JConsole吗?

128

过去似乎我从未让此工作。目前我知道它不起作用。

但我们启动了Java进程:

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

我可以telnet到端口,然后"有些东西在那里"(也就是说,如果我不启动该进程,则没有任何答案,但如果我启动它,则会有答案),但我无法让JConsole在填写IP和端口后工作。

看起来应该很简单,但没有错误,没有噪音,什么都没有。只是不起作用。

有人知道这个的窍门吗?


3
如果您正在使用 Tomcat,则可能需要尝试以下解决方案:https://dev59.com/3nM_5IYBdhLWcg3wslfs#6782309 - Hajo Thelen
5
你在这里忘记接受了什么吗@Will? - Gray
20个回答

2
这里已经有一些很好的答案了,但是我认为有一个稍微简单一些的方法值得分享。
sushicutta的方法不错,但是非常繁琐,因为你需要每次获取RMI端口。幸运的是,我们可以通过使用SOCKS代理来避免明确打开端口隧道。这种方法的缺点是您在本地运行的JMX应用程序需要能够配置使用代理。大多数进程都可以通过添加Java属性来完成此操作,但是某些应用程序不支持此功能。
步骤:
  1. Add the JMX options to the startup script for your remote Java service:

    -Dcom.sun.management.jmxremote=true
    -Dcom.sun.management.jmxremote.port=8090
    -Dcom.sun.management.jmxremote.ssl=false
    -Dcom.sun.management.jmxremote.authenticate=false
    
  2. Set up a SOCKS proxy connection to your remote machine:

    ssh -D 9696 user@remotemachine.com
    
  3. Configure your local Java monitoring app to use the SOCKS proxy (localhost:9696). Note: You can sometimes do this from the command line, i.e.:

    jconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=9696
    

2
以下方法适用于我(尽管我认为2101端口并没有真正起到贡献):
-Dcom.sun.management.jmxremote.port=2100
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.rmi.port=2101
-Djava.rmi.server.hostname=<IP_ADDRESS>OR<HOSTNAME>

我正在从远程机器连接到运行有Docker的服务器上,进程在容器内。我已经停止了firewallD,但我认为这不是问题,因为即使防火墙开启,我仍然可以通过telnet连接到2100端口。 希望这能帮到你。


2

当测试/调试/诊断远程JMX问题时,首先始终尝试在包含MBeanServer的同一主机上连接(即本地主机),以排除网络和其他非JMX特定问题。


1
我正在使用boot2docker运行内置Tomcat的Docker容器,遇到了同样的问题,解决方法是:
  • 添加-Djava.rmi.server.hostname=192.168.59.103
  • 在主机和Docker容器中使用相同的JMX端口,例如:docker run ... -p 9999:9999 ...。使用不同的端口无法正常工作。

1

我正在Windows上运行JConsole/JVisualVm,连接到运行Linux Redhat ES3的Tomcat。

使用以下命令禁用数据包过滤对我很有帮助:

/usr/sbin/iptables -I INPUT -s jconsole-host -p tcp --destination-port jmxremote-port -j ACCEPT

where jconsole-host is either the hostname or the host address on which JConsole runs on and jmxremote-port is the port number set for com.sun.management.jmxremote.port for remote management.


2
在 SUSE Amazon EC2 实例上它对我没有起作用。我认为问题在别的地方。 - djangofan

0

以下是我成功实践的步骤(服务器端在防火墙后面的 Debian 系统,通过 VPN 从本地 Mac 访问):

检查服务器 IP。

hostname -i

使用JVM参数:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=[jmx port]
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=[server ip from step 1]

运行应用程序

查找正在运行的Java进程的PID

检查JMX/RMI使用的所有端口

netstat -lp | grep [pid from step 4]

在防火墙上打开从步骤5开始的所有端口。

完成。


0
为了做出贡献,我在CentOS 6.4上为Tomcat 6做了以下工作。
  1. 关闭iptables服务

    service iptables stop
    
  2. 在tomcat6.conf中添加以下行

    CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8085 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=[host_ip]"
    

通过这种方式,我能够使用JConsole从另一台电脑连接。


0

你还需要确保你的机器名解析到 JMX 绑定的 IP,而不是 localhost 或 127.0.0.1。对我来说,将一个条目放入 hosts 文件中以明确定义这一点有所帮助。


0

穿过防火墙获取JMX并不难。只有一个小问题需要注意。您必须转发JMX配置端口(即9010)和其中一个动态端口,我的机器上是> 30000。


0

我正在尝试在没有图形环境的远程服务器上运行JMC以运行Flight Recorder(JFR)来对NiFi进行分析。

根据其他答案和大量试错,这是我在启动NiFi时提供给JVM(conf/bootstrap.conf)的内容:

java.arg.90=-Dcom.sun.management.jmxremote=true
java.arg.91=-Dcom.sun.management.jmxremote.port=9098
java.arg.92=-Dcom.sun.management.jmxremote.rmi.port=9098
java.arg.93=-Dcom.sun.management.jmxremote.authenticate=false
java.arg.94=-Dcom.sun.management.jmxremote.ssl=false
java.arg.95=-Dcom.sun.management.jmxremote.local.only=false
java.arg.96=-Djava.rmi.server.hostname=10.10.10.92  (the IP address of my server running NiFi)

我把它放在了/etc/hosts中,尽管我怀疑这并不需要:

10.10.10.92   localhost

然后,在启动JMC时,我使用以下属性创建远程连接:

Host: 10.10.10.92
Port: 9098
User: (nothing)
Password: (ibid)

顺便提一下,如果我点击自定义JMX服务URL,我会看到:

service:jmx:rmi:///jndi/rmi://10.10.10.92:9098/jmxrmi

这最终解决了我的问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接