IT박스

원격 JMX JConsole을 사용하는 사람이 있습니까?

itboxs 2020. 7. 26. 12:42
반응형

원격 JMX JConsole을 사용하는 사람이 있습니까?


과거에는 이것이 작동하지 않은 것 같습니다. 현재는 작동하지 않습니다.

그러나 Java 프로세스를 시작합니다.

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

포트에 텔넷으로 연결할 수 있고 "뭔가가 있습니다"(즉, 프로세스를 시작하지 않으면 아무런 응답도 없지만, 그렇지 않은 경우) JConsole이 IP를 채우도록 할 수는 없습니다. 그리고 포트.

그렇게 간단하지만 오류, 소음, 아무것도 없어야합니다. 작동하지 않습니다.

누구든지 이것에 대한 팁을 알고 있습니까?


이에 대한 해결책이 있습니다.

귀하의 경우 자바 프로세스는 방화벽 뒤에 리눅스에서 실행 하면 시작하려는 JConsole의 / 자바 VisualVM과 / 자바 미션 컨트롤 에 연결하려면 로컬 컴퓨터에 Windows의를 자바 프로세스의 JMX 포트 .

SSH 로그인을 통해 Linux 시스템에 액세스해야합니다. 모든 통신은 SSH 연결을 통해 터널링됩니다.

힌트 : 이 솔루션은 방화벽이 있는지 여부에 관계없이 작동합니다.

단점 : Java 프로세스 다시 시작할마다 4-9의 모든 단계를 다시 수행해야합니다.


1. 여기에서 Windows 머신 용 퍼티 스위트가 필요합니다.

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

적어도 putty.exe


2. 리눅스 머신에서 하나의 빈 포트를 정의하십시오 :

<jmx-remote-port>

예:

jmx-remote-port = 15666      


3. 리눅스 머신에서 자바 프로세스에 인수 추가

이것은 정확히 이와 같이 수행되어야합니다. 아래처럼 수행하면 방화벽 뒤의 리눅스 머신에서 작동합니다 ( -Djava.rmi.server.hostname=localhost논쟁의 원인이됩니다 ).

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=<jmx-remote-port>
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=localhost

예:

java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=15666 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=localhost ch.sushicutta.jmxremote.Main


4. Java 프로세스의 Process-Id 얻기

ps -ef | grep <java-processname>

result ---> <process-id>

예:

ps -ef | grep ch.sushicutta.jmxremote.Main

result ---> 24321


5. RMIServer 스텁 다운로드를위한 임의의 포트 찾기

Java 프로세스는 Linux 시스템에서 새 TCP 포트를 열고 RMI 서버 스텁을 다운로드 할 수 있습니다. Java Virtual Machine에 연결하려면 SSH 터널을 통해이 포트를 사용할 수도 있어야합니다.

으로 netstat -lp이 포트는 찾을 수는 lsof -iJava 프로세스 형태로 개설되었습니다 어떤 포트 힌트를 제공합니다.

참고 :이 포트는 Java 프로세스가 시작될 때 항상 변경됩니다.

netstat -lp | grep <process-id>

tcp        0      0 *:<jmx-remote-port>     *:*     LISTEN      24321/java
tcp        0      0 *:<rmi-server-port>     *:*     LISTEN      24321/java


result ---> <rmi-server-port>

예:

netstat -lp | grep 24321

tcp        0      0 *:15666     *:*     LISTEN      24321/java
tcp        0      0 *:37123     *:*     LISTEN      24321/java


result ---> 37123


6. 퍼티를 사용하여 Windows 시스템에서 두 개의 SSH-Tunnels를 활성화하십시오.

Source port: <jmx-remote-port>
Destination: localhost:<jmx-remote-port>
[x] Local       
[x] Auto       

Source port: <rmi-server-port>
Destination: localhost:<rmi-server-port>
[x] Local       
[x] Auto

예:

Source port: 15666
Destination: localhost:15666
[x] Local       
[x] Auto       

Source port: 37123
Destination: localhost:37123
[x] Local       
[x] Auto


퍼티를 통해 SSL 터널을 열기위한 설정


7.이 SSH-Tunnel이 활성화 된 퍼티로 Linux 시스템에 로그인하십시오.

퍼티 세션을 열어 두십시오.

로그인하면 Putty는 SSH 포트 22를 통해 모든 TCP 연결을 Linux 시스템으로 터널링합니다.

JMX 포트 :

Windows machine: localhost:15666   >>> SSH >>>   linux machine: localhost:15666

RMIServer- 스텁-포트 :

Windows Machine: localhost:37123   >>> SSH >>>   linux machine: localhost:37123


8. 다음 URL을 사용하여 JConsole / Java VisualVM / Java Mission Control을 시작하여 Java 프로세스에 연결하십시오.

이 작동하면 JConsole / Java VisualVM / Java Mission Control이 로컬 Windows 시스템의 포트에 연결한다고 생각합니다. 그러나 퍼티는 모든 페이로드를 15666 포트로 리눅스 머신으로 보냅니다.

리눅스 머신에서 먼저 자바 프로세스는 응답을 제공하고 RMIServer 포트를 다시 보냅니다. 이 예에서는 37123입니다.

그런 다음 JConsole / Java VisualVM / Java Mission Control은 localhost : 37123에 연결한다고 생각하고 퍼티는 전체 페이로드를 Linux 시스템으로 보냅니다.

Java 프로세스가 응답하고 연결이 열려 있습니다.

[x] Remote Process:
service:jmx:rmi:///jndi/rmi://localhost:<jndi-remote-port>/jmxrmi

예:

[x] Remote Process:
service:jmx:rmi:///jndi/rmi://localhost:15666/jmxrmi


jmx 서비스 URL을 통해 연결


9. 엔조이 # 8-]


추가하면 -Djava.rmi.server.hostname='<host ip>'이 문제가 해결되었습니다.


Java 8로 시도

이 솔루션은 방화벽과도 잘 작동합니다

1. 이것을 원격 호스트의 Java 시작 스크립트에 추가하십시오.

-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

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

4. 재미있게 보내세요!

추신 : 2 단계 동안, 사용 ssh-L로컬 (클라이언트) 호스트의 포트 1616는 원격 측에 전달되어야 함을 지정합니다. 이것은 ssh 터널이며 방화벽이나 다양한 네트워크 문제를 피하는 데 도움이됩니다.


방화벽에 문제가있을 수 있습니다. '문제'는 지정한 포트가 사용 된 유일한 포트가 아니며 RMI에 1 개 또는 2 개 이상의 포트를 사용하며 방화벽에 의해 차단 된 것입니다.

기본 RMI 구성을 사용하는 경우 추가 포트 중 하나를 미리 알 수 없으므로 서버 관리자를 즐겁게하지 않을 수있는 광범위한 포트를 열어야합니다.

많은 포트를 열 필요가없는 솔루션이 있지만, 소스 스 니펫과 팁을 결합하여 작동하도록했습니다.

http://forums.sun.com/thread.jspa?threadID=5267091- 더 이상 링크가 작동하지 않습니다

http://blogs.oracle.com/jmxetc/entry/connecting_through_firewall_using_jmx

http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html

ssh 터널을 설정하고 여전히 작동하도록 할 수도 있습니다 :-)


지난 며칠 동안 Google-fu를 테스트 한 후 마침내 스택 오버플로 와이 페이지 http://help.boomi.com/atomsphere/GUID-F787998C- 에서 답변을 컴파일 한 후이 기능을 사용할 수있었습니다 . 53C8-4662-AA06-8B1D32F9D55B.html .

Dell Boomi 페이지에서 다시 게시 :

To Enable Remote JMX on an Atom

If you want to monitor the status of an Atom, you need to turn on Remote JMX (Java Management Extensions) for the Atom.

Use a text editor to open the <atom_installation_directory>\bin\atom.vmoptions file.

Add the following lines to the file:

-Dcom.sun.management.jmxremote.port=5002
-Dcom.sun.management.jmxremote.rmi.port=5002
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

The one line that I haven't seen any Stack Overflow answer cover is

-Dcom.sun.management.jmxremote.rmi.port=5002

In my case, I was attempting to retrieve Kakfa metrics, so I simply changed the above option to match the -Dcom.sun.management.jmxremote.port value. So, without authentication of any kind, the bare minimum config should look like this:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.port=(jmx remote port)

-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.rmi.port=(jmx remote port)
-Djava.rmi.server.hostname=(CNAME|IP Address)

Are you running on Linux? Perhaps the management agent is binding to localhost:

http://java.sun.com/j2se/1.5.0/docs/guide/management/faq.html#linux1


Sushicutta's steps 4-7 can be skipped by adding the following line to step 3:

-Dcom.sun.management.jmxremote.rmi.port=<same port as jmx-remote-port>

e.g. Add to start up parameters:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.rmi.port=12345
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=localhost

For the port forwarding, connect using:

ssh -L 12345:localhost:12345 <username>@<host>

if your host is a stepping stone, simply chain the port forward by running the following on the step stone after the above:

ssh -L 12345:localhost:12345 <username>@<host2>

Mind that the hostname=localhost is needed to make sure the jmxremote is telling the rmi connection to use the tunnel. Otherwise it might try to connect directy and hit the firewall.


PROTIP:

The RMI port are opened at arbitrary portnr's. If you have a firewall and don't want to open ports 1024-65535 (or use vpn) then you need to do the following.

You need to fix (as in having a known number) the RMI Registry and JMX/RMI Server ports. You do this by putting a jar-file (catalina-jmx-remote.jar it's in the extra's) in the lib-dir and configuring a special listener under server:

<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener"
      rmiRegistryPortPlatform="10001" rmiServerPortPlatform="10002" />

(And ofcourse the usual flags for activating JMX

    -Dcom.sun.management.jmxremote  \
    -Dcom.sun.management.jmxremote.ssl=false \
    -Dcom.sun.management.jmxremote.authenticate=false \
    -Djava.rmi.server.hostname=<HOSTNAME> \

See: JMX Remote Lifecycle Listener at http://tomcat.apache.org/tomcat-6.0-doc/config/listeners.html

Then you can connect using this horrific URL:

service:jmx:rmi://<hostname>:10002/jndi/rmi://<hostname>:10001/jmxrmi

Check if your server is behind the firewall. JMX is base on RMI, which open two port when it start. One is the register port, default is 1099, and can be specified by the com.sun.management.jmxremote.port option. The other is for data communication, and is random, which is what cause problem. A good news is that, from JDK6, this random port can be specified by the com.sun.management.jmxremote.rmi.port option.

export CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8991 -Dcom.sun.management.jmxremote.rmi.port=8991 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

Getting JMX through the Firewall is really hard. The Problem is that standard RMI uses a second random assigned port (beside the RMI registry).

We have three solution that work, but every case needs a different one:

  1. JMX over SSH Tunnel with Socks proxy, uses standard RMI with SSH magic http://simplygenius.com/2010/08/jconsole-via-socks-ssh-tunnel.html

  2. JMX MP (alternative to standard RMI), uses only one fixed port, but needs a special jar on server and client http://meteatamel.wordpress.com/2012/02/13/jmx-rmi-vs-jmxmp/

  3. Start JMX Server form code, there it is possible to use standard RMI and use a fixed second port: https://issues.apache.org/bugzilla/show_bug.cgi?id=39055


When testing/debugging/diagnosing remote JMX problems, first always try to connect on the same host that contains the MBeanServer (i.e. localhost), to rule out network and other non-JMX specific problems.


There are already some great answers here, but, there is a slightly simpler approach that I think it is worth sharing.

sushicutta's approach is good, but is very manual as you have to get the RMI Port every time. Thankfully, we can work around that by using a SOCKS proxy rather than explicitly opening the port tunnels. The downside of this approach is JMX app you run on your machine needs to be able to be configured to use a Proxy. Most processes you can do this from adding java properties, but, some apps don't support this.

Steps:

  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
    

The following worked for me (though I think port 2101 did not really contribute to this):

-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>

I am connecting from a remote machine to a server which has Docker running and the process is inside the container. Also, I stopped firewallD but I don't think that was the issue as I could telnet to 2100 even with the firewall open. Hope it helps.


I am running JConsole/JVisualVm on windows hooking to tomcat running Linux Redhat ES3.

Disabling packet filtering using the following command did the trick for me:

/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.


I'm using boot2docker to run docker containers with Tomcat inside and I've got the same problem, the solution was to:

  • Add -Djava.rmi.server.hostname=192.168.59.103
  • Use the same JMX port in host and docker container, for instance: docker run ... -p 9999:9999 .... Using different ports does not work.

You need to also make sure that your machine name resolves to the IP that JMX is binding to; NOT localhost nor 127.0.0.1. For me, it has helped to put an entry into hosts that explicitly defines this.


Getting JMX through the firewall isn't that hard at all. There is one small catch. You have to forward both your JMX configured port ie. 9010 and one of dynamic ports its listens to on my machine it was > 30000


These are the steps that worked for me (debian behind firewall on the server side, reached over VPN from my local Mac):

check server ip

hostname -i

use JVM params:

-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]

run application

find pid of the running java process

check all ports used by JMX/RMI

netstat -lp | grep [pid from step 4]

open all ports from step 5 on the firewall

Voila.


In order to make a contribution, this is what I did on CentOS 6.4 for Tomcat 6.

  1. Shutdown iptables service

    service iptables stop
    
  2. Add the following line to 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]"
    

This way I was able to connect from another PC using JConsole.


I'm trying to JMC to run the Flight Recorder (JFR) to profile NiFi on a remote server that doesn't offer a graphical environment on which to run JMC.

Based on the other answers given here, and upon much trial and error, here is what I'm supplying to the JVM (conf/bootstrap.conf)when I launch NiFi:

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)

I did put this in /etc/hosts, though I doubt it's needed:

10.10.10.92   localhost

Then, upon launching JMC, I create a remote connection with these properties:

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

Incidentally, if I click the Custom JMX service URL, I see:

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

This finally did it for me.

참고 URL : https://stackoverflow.com/questions/151238/has-anyone-ever-got-a-remote-jmx-jconsole-to-work

반응형