使用jConsole连接远程tomcat JMX实例

Nig*_*ger 55 java tomcat jmx jconsole

我正在尝试使用jConsole连接到远程tomcat JMX实例.但无法成功连接.任何的想法?

我在远程tomcat中包含以下选项catalina.sh:

JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote \
    -Dcom.sun.management.jmxremote.port=9004 \
    -Dcom.sun.management.jmxremote.ssl=false \
    -Dcom.sun.management.jmxremote.authenticate=false"
Run Code Online (Sandbox Code Playgroud)

wax*_*ing 63

我有一个类似的,如果不是相同的问题.如果我在机器上本地启动jconsole,我可以连接到JMX服务器.

看来RMI服务器没有正在侦听正确的ip.因此,正如在这个相关问题中所建议的那样,我添加了以下内容:

-Djava.rmi.server.hostname=<host ip>
Run Code Online (Sandbox Code Playgroud)

JAVA_OPTS为好,然后它的工作.


Haj*_*len 36

我收集了通过网络传播的信息,并附有其他成员的提示.

由JMX引起的大多数痛苦是(imo)JMX打开第二个动态分配的网络端口的事实.防火墙(如iptables)将阻止此操作.

linux上tomcat的解决方案:

使用tomcat 6.0.24或更新的从apache tomcat extras下载catalina-jmx-remote.jar(在tomcat下载页面上使用browse)将它复制到$ CTALINA_HOME\lib中

这允许您设置JMX使用的两个端口

编辑server.xml中的Server部分

<Server port="8005" ..>
  ...
  <Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="9840" rmiServerPortPlatform="9841"/>
Run Code Online (Sandbox Code Playgroud)

设置一些环境变量(例如在setenv.sh中)

CATALINA_OPTS="
  -Djava.rmi.server.hostname=IP-TO-LISTEN
  -Dcom.sun.management.jmxremote.password.file=$CATALINA_BASE/conf/jmxremote.password 
  -Dcom.sun.management.jmxremote.access.file=$CATALINA_BASE/conf/jmxremote.access 
  -Dcom.sun.management.jmxremote.ssl=false"
Run Code Online (Sandbox Code Playgroud)

这会激活JMX的访问控制

jmxremote.access看起来像

monitorRole readonly
controlRole readwrite
Run Code Online (Sandbox Code Playgroud)

结束jmxremote.password将

monitorRole tomcat
controlRole tomcat
Run Code Online (Sandbox Code Playgroud)

(只是简单的空间)

重启tomcat.

现在在服务器上配置防火墙(例如iptables)

的/ etc/SYSCONFIG/iptables的

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 9840 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 9841 -j ACCEPT
Run Code Online (Sandbox Code Playgroud)

和/ etc/sysconfig/ip6tables

-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 9840 -j ACCEPT
-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 9841 -j ACCEPT
Run Code Online (Sandbox Code Playgroud)

重启iptables

完成!

现在在工作站上使用VisualVM或JConsole建立与我们样本中的rmiRegistryPortPlatform,9840的连接.

如果工作站和服务器之间没有防火墙,它应该可以工作.

  • +1谢谢!工作得很好!我只需要添加另一行:`-Djava.rmi.server.hostname = <server-name>`. (3认同)

fre*_*dev 11

试过Java 8

1.将其添加到java tomcat启动脚本中:

-Dcom.sun.management.jmxremote.port=1616
-Dcom.sun.management.jmxremote.rmi.port=1616
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=localhost
Run Code Online (Sandbox Code Playgroud)

例如,添加到bin/setenv.sh中:

export CATALINA_OPTS="$CATALINA_OPTS \
-Dcom.sun.management.jmxremote.port=1616 \
-Dcom.sun.management.jmxremote.rmi.port=1616 \
-Dcom.sun.management.jmxremote.local.only=true \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false "
Run Code Online (Sandbox Code Playgroud)

2.在您的计算机上执行此操作.

  • Windows用户:

    putty.exe -ssh user@remote-host -L 1616:remote-host:1616

  • Linux和Mac用户:

    ssh user@remote-host -L 1616:remote-host:1616

3. jconsole在计算机上启动

jconsole localhost:1616
Run Code Online (Sandbox Code Playgroud)

4.玩得开心!

  • PS:在步骤2中,使用ssh-L指定将本地(客户端)主机上的端口1616转发到远程端.
  • PS2.:您可以为JMX和RMI对话指定相同的端口


小智 8

您使用什么字符串作为JMX连接URL.我并不是要指出明显但JConsole有一个糟糕的界面,对我来说需要一个过于复杂的URL才能连接到远程jmx应用程序.我看起来像这样:

service:jmx:rmi:///jndi/rmi://(hostname):(jmxport)/jmxrmi
Run Code Online (Sandbox Code Playgroud)


joe*_*e p 2

当您说“但无法成功连接”时,您到底是什么意思?有错误信息吗?尝试在 jconsole 中打开日志记录,看看这是否有助于调试它。

要打开 jconsole 日志记录,请在将运行 jconsole 的目录中编辑名为logging.properties 的文件,添加:

handlers= java.util.logging.ConsoleHandler

.level=INFO

java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter

java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

javax.management.level=FINEST
javax.management.remote.level=FINEST
Run Code Online (Sandbox Code Playgroud)

然后,启动 jconsole:

jconsole -J-Djava.util.logging.config.file=logging.properties
Run Code Online (Sandbox Code Playgroud)