1

我想使用 JMX 通过远程连接来监控 tomcat 和 ActiveMQ。

对于activeMQ,我在startup.bat的JAVA_OPTS中添加了这个:

JAVA_OPTS=
-Dwebconsole.type=properties \
-Dwebconsole.jms.url=tcp://localhost:61616 \
-Dwebconsole.jmx.url=service:jmx:rmi:///jndi/rmi://localhost:1099/ jmxrmi

当我启动 tomcat 服务器和 ActiveMQ 时,在 Jconsole 中我可以连接到 url:

service:jmx:rmi:///jndi/rmi://x.x.x.x:1099/jmxrmi

对于tomcat监控,我添加了:

-Dcom.sun.management.jmxremote ^
-Dcom.sun.management.jmxremote.port=9004 ^
-Dcom.sun.management.jmxremote.ssl=false ^
-Dcom.sun.management.jmxremote.authenticate=false ^
-Djava.rmi.server.hostname=x.x.x.x

然后,当我尝试连接到service:jmx:rmi:///jndi/rmi://x.x.x.x:9004/jmxrmiJconsole 中的 url 时,连接失败。我尝试使用 Netbeans(他似乎使用 catalina.bat 而不是 startup.bat)并将 java_opts 从 startup.bat 移动到 catalina.bat,并在我启动服务器时将日志移至此处:

'-Dcom.sun.management.jmxremote' n'est pas reconnu en tant que commande interne
Using CATALINA_BASE:   "C:\Program Files\apache-tomcat-7.0.33"
Using CATALINA_HOME:   "C:\Program Files\apache-tomcat-7.0.33"
Using CATALINA_TMPDIR: "C:\Program Files\apache-tomcat-7.0.33\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk1.7.0_07"
Using CLASSPATH:       "C:\Program Files\apache-tomcat-7.0.33\bin\bootstrap.jar;C:\Program Files\apache-tomcat-7.0.33\bin\tomcat-juli.jar"
ou externe, un programme ex‚cutable ou un fichier de commandes.
'-Dcom.sun.management.jmxremote' n'est pas reconnu en tant que commande interne
ou externe, un programme ex‚cutable ou un fichier de commandes.

对不起法语的东西,重要的部分说 -Dcom.sun.management.jmxremote 不能识别为内部或外部命令。

Jconsole 调试输出:

java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 192.168.117.31; nested exception is: 
    java.net.ConnectException: Connection refused: connect]
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:357)
    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:267)
    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:226)
    at sun.tools.jconsole.ProxyClient.tryConnect(ProxyClient.java:354)
    at sun.tools.jconsole.ProxyClient.connect(ProxyClient.java:314)
    at sun.tools.jconsole.VMPanel$2.run(VMPanel.java:295)
Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 192.168.117.31; nested exception is: 
    java.net.ConnectException: Connection refused: connect]
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:118)
    at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:203)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1924)
    at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1891)
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:274)
    ... 5 more
Caused by: java.rmi.ConnectException: Connection refused to host: 192.168.117.31; nested exception is: 
    java.net.ConnectException: Connection refused: connect
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
    at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:340)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:114)
    ... 10 more
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at java.net.Socket.<init>(Socket.java:425)
    at java.net.Socket.<init>(Socket.java:208)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:146)
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
    ... 15 more

我将 activeMQ 部分留在了 startup.bat 中,我仍然可以连接到它。我真的不知道问题出在哪里......如果有人可以帮助我

4

1 回答 1

3

我终于解决了问题,现在可以将 jConsole 连接到端口 9004。这是我配置 catalina.bat 的方式:

set CATALINA_OPTS=-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=x.x.x.x

没有“输入”,没有引号,我指定true了第一个参数,并且全部都在一个 CATALINA_OPTS 声明中。

希望它可以有用

于 2013-03-05T09:21:31.603 回答