[英]How to activate JMX on my JROCKIT JVM for access with jconsole?
[英]How to activate JMX on my JVM for access with jconsole?
如何在 JVM 上激活 JMX 以使用 jconsole 進行訪問?
相關文檔可以在這里找到:
http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html
使用以下參數啟動您的程序:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.rmi.port=9010
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
例如像這樣:
java -Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=9010 \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-jar Notepad.jar
-Dcom.sun.management.jmxremote.local.only=false
不一定是必需的,但沒有它,它在 Ubuntu 上不起作用。 錯誤將是這樣的:
01 Oct 2008 2:16:22 PM sun.rmi.transport. customer .TCPTransport$AcceptLoop executeAcceptLoop
WARNING: RMI TCP Accept-0: accept loop for ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=37278] throws
java.io.IOException: The server sockets created using the LocalRMIServerSocketFactory only accept connections from clients running on the host where the RMI remote objects have been exported.
at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:89)
at sun.rmi.transport. customer .TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:387)
at sun.rmi.transport. customer .TCPTransport$AcceptLoop.run(TCPTransport.java:359)
at java.lang.Thread.run(Thread.java:636)
見http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6754672
還要小心-Dcom.sun.management.jmxremote.authenticate=false
這使得任何人都可以訪問,但如果你只用它來跟蹤本地機器上的 JVM,那沒關系。
更新:
在某些情況下,我無法訪問服務器。 如果我也設置了這個參數,這個問題就得到了修復: -Djava.rmi.server.hostname=127.0.0.1
在 Docker 容器中運行會為連接帶來一系列額外的問題,因此希望這對某人有所幫助。 我最終需要添加以下選項,我將在下面解釋:
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=${DOCKER_HOST_IP}
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.rmi.port=9998
DOCKER_HOST_IP
與在本地使用 jconsole 不同,您必須公布一個與您可能從容器內看到的 IP 不同的 IP。 您需要將${DOCKER_HOST_IP}
替換${DOCKER_HOST_IP}
Docker 主機的外部可解析 IP(DNS 名稱)。
JMX 遠程和 RMI 端口
看起來 JMX 還需要訪問遠程管理接口 ( jstat ), 該接口在仲裁連接時使用不同的端口來傳輸一些數據。 我在jconsole
沒有看到任何明顯的地方可以設置這個值。 在鏈接的文章中,過程是:
jconsole
連接jconsole
嘗試使用的端口iptables
/ firewall
規則以允許該端口連接雖然這有效,但它肯定不是一個可自動化的解決方案。 我選擇從 jconsole 升級到VisualVM,因為它讓您可以明確指定運行jstatd
的端口。 在 VisualVM 中,添加一個新的遠程主機並使用與上面指定的值相關的值更新它:
然后右鍵單擊新的遠程主機連接並Add JMX Connection...
不要忘記選中Do not require SSL connection
的復選框。 希望這應該允許您連接。
請注意,最新版本的 Java 6 允許 jconsole 將自身附加到正在運行的進程,即使它已在沒有 JMX 咒語的情況下啟動。
如果您可以使用它,還可以考慮 jvisualvm,因為它提供了有關正在運行的進程的大量信息,包括分析器。
我正在使用 WAS ND 7.0
我的 JVM 需要在 JConsole 中監視以下所有參數
-Djavax.management.builder.initial=
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8855
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
在 Linux 上,我使用了以下參數:
-Djavax.management.builder.initial=
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
並且我編輯了/etc/hosts
以便主機名解析為主機地址(192.168.0.x)而不是環回地址(127.0.0.1)
以下選項對我有用:
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.rmi.port=9010
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname={host name}
記得在服務器上打開9010端口
sudo ufw allow 9010/udp
sudo ufw allow 9010/tcp
sudo ufw reload
使用以下命令行參數運行您的 Java 應用程序:
-Dcom.sun.management.jmxremote.port=8855
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
如果您不想在 jmx 主機上設置數字證書,請務必使用-Dcom.sun.management.jmxremote.ssl=false參數。
如果您在 IP 地址為192.168.0.1的機器上啟動應用程序,請打開jconsole ,在Remote Process字段中輸入192.168.0.1:8855 ,然后單擊Connect 。
連同下面的命令行參數,
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
有時在 linux 服務器中,imx 連接不會成功。 那是因為,在雲 linux 主機中,在 /etc/hosts 中,以便主機名解析為主機地址。
修復它的最佳方法是,從網絡中的其他機器 ping 特定的 linux 服務器,並在
-Djava.rmi.server.hostname=IP address that obtained when you ping that linux server.
但是永遠不要依賴使用 ifconfig.me 從 linux 服務器獲得的 ipaddress。 您在那里獲得的 IP 是主機文件中存在的掩碼。
步驟 1:使用以下參數運行應用程序。
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
以上參數將應用程序綁定到端口 9999。
步驟 2:通過在命令提示符或終端中執行命令 jconsole 來啟動 jconsole。
選擇“遠程進程:”並輸入 URL 作為 {IP_Address}:9999 並單擊“連接”按鈕以連接到遠程應用程序。
您可以參考此鏈接以獲取完整的應用程序。
首先,您需要檢查您的 java 進程是否已經使用 JMX 參數運行。 做這個:
ps -ef | grep java
檢查您需要監控的 Java 進程。 如果你可以看到 jmx rmi 參數Djmx.rmi.registry.port=xxxx然后使用你的 java visualvm 中提到的端口在 jmx 連接下遠程連接它。
如果它不是通過 jmx rmi 端口運行,那么您需要使用以下提到的參數運行您的 java 進程:
-Djmx.rmi.registry.port=1234 -Djmx.rmi.port=1235 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
注意:端口號取決於您的選擇。
現在您可以使用此端口進行 jmx 連接。 這是端口1234
。
我遇到了這個確切的問題,並創建了一個 GitHub 項目來測試和找出正確的設置。
它包含一個帶有支持腳本的工作Dockerfile
,以及一個用於快速測試的簡單docker-compose.yml
。
使用遠程進程選項運行本地進程 JCONSOLE
要在本地運行,這對我有用-
我在我的vm args 中添加了這個 -
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=6001
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=localhost
-Dcom.sun.management.jmxremote.rmi.port=6001
I opened JConsole via Intellij Terminal
It was showing me all PID's in grey in local
So I selected remote process and logged in using host - localhost:6001
Keep empty username & password
Then click connect
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.